/// <summary> /// Set <paramref name="chunkBufferSize"/> to a smaller value (like 10) if big jumps in the scrolling position are very frequent /// and your data source allows retrieving a few values, but frequently. Default is <see cref="BufferredDataSource{T}.BUFFER_MAX_SIZE_DEFAULT"/>. /// <para>Though the best way is to find it by manually testing different values</para> /// </summary> public BufferredTableData(ITableColumns columnsProvider, int tuplesCount, TuplesChunkReader tuplesChunkReader, int chunkBufferSize, bool columnSortingSupported) { _ChunkReader = tuplesChunkReader; _DataSource = new BufferredDataSource <ITuple>(tuplesCount, ReadTuplesChunk, chunkBufferSize, false /*items will be created directly*/); Init(columnsProvider, columnSortingSupported); }
/// <summary>Initialization method provided for inheritors, if needed</summary> protected void Init(ITableColumns columns, bool columnSortingSupported) { Columns = columns; int maxCountForSorting = TableViewConst.MAX_TABLE_ENTRIES_FOR_ACCEPTABLE_COLUMN_ITERATION_TIME; if (Count > maxCountForSorting) { if (columnSortingSupported) { Debug.Log(typeof(TableData).Name + ": columnSortingSupported is true, but the count exceeds MAX_TABLE_ENTRIES_FOR_ACCEPTABLE_COLUMN_SORTING_TIME " + "(" + Count + " > " + maxCountForSorting + "). Setting columnSortingSupported=false"); columnSortingSupported = false; } } _ColumnSortingSupported = columnSortingSupported; if (_ColumnSortingSupported) { _MapValueTypeToComparer = new Dictionary <TableValueType, IComparer>(9); var rawComparerForNull = new ObjectComparerForNull(); _MapValueTypeToComparer[TableValueType.RAW] = rawComparerForNull; _MapValueTypeToComparer[TableValueType.STRING] = StringComparer.OrdinalIgnoreCase; _MapValueTypeToComparer[TableValueType.INT] = Comparer <int> .Default; _MapValueTypeToComparer[TableValueType.LONG_INT] = Comparer <long> .Default; _MapValueTypeToComparer[TableValueType.FLOAT] = Comparer <float> .Default; _MapValueTypeToComparer[TableValueType.DOUBLE] = Comparer <double> .Default; _MapValueTypeToComparer[TableValueType.ENUMERATION] = new EnumComparerSupportingNull(); _MapValueTypeToComparer[TableValueType.BOOL] = Comparer <bool> .Default; _MapValueTypeToComparer[TableValueType.TEXTURE] = rawComparerForNull; } }
public void ResetWithTuple(ITuple tuple, ITableColumns columnsProvider) { if (!IsInitialized) { Init(); } _CurrentTuple = tuple; _ColumnsProvider = columnsProvider; int columnsCount = _ColumnsProvider.ColumnsCount; if (GetItemsCount() == columnsCount) { // Save massive amounts of performance by just updating the existing views holders rather than resetting the view. // Same count means existing items don't need to be enabled/disabled/destroyed, because their position won't change var thisAsITupleAdapter = this as ITupleAdapter; for (int i = 0; i < _VisibleItemsCount; i++) { var vh = GetItemViewsHolder(i); thisAsITupleAdapter.ForceUpdateValueViewsHolder(vh); } // Force a ComputeVisibility pass, if needed //SetNormalizedPosition(GetNormalizedPosition()); } else { ResetItems(columnsCount); } }
public virtual void UpdateViews(ITuple tuple, ITableColumns columns) { if (_IndexText) { _IndexText.text = ItemIndex.ToString(); } Adapter.ResetWithTuple(tuple, columns); }
void GetRandomTuples(ITuple[] into, int numTuples, ITableColumns columns) { // If this mehtod is called from different threads, each thead needs its own random generator instance var random = new System.Random((int)DateTime.Now.Ticks); for (int i = 0; i < numTuples; i++) { var tuple = TableViewUtil.CreateTupleWithEmptyValues <BasicTuple>(columns.ColumnsCount); GetRandomValuesIntoTuple(columns, tuple, random); into[i] = tuple; } }
public override void UpdateViews(object value, ITableColumns columnsProvider) { bool isNull = value == null; var column = columnsProvider.GetColumnState(ItemIndex); if (isNull) { UpdateAsNullText(column); return; } UpdateViews(value, column); }
/// <summary>Populate the TableAdapter with new data</summary> public void ResetTable(ITableColumns columns, ITupleProvider tuples) { Columns = columns; Tuples = tuples; // Init is called in Start() by OSA by design. But we make sure it's called here as well, // in case SetData is called before Start() if (!IsInitialized) { Init(); } ResetTableWithCurrentData(); }
public override void UpdateViews(object value, ITableColumns columnsProvider) { string asStr = (string)value; if (columnsProvider.GetColumnState(ItemIndex).CurrentlyReadOnly) { asStr += "\n<color=#00000030><size=10>Read-only</size></color>"; } TextComponent.text = asStr; var sortType = columnsProvider.GetColumnState(ItemIndex).CurrentSortingType; UpdateArrowFromSortType(sortType); }
public abstract void UpdateViews(object value, ITableColumns columnsProvider);
/// <summary> /// <paramref name="rowTuples"/> is the list of all the rows in the table, as tuples implementing <see cref="ITuple"/> /// </summary> public TableData(ITableColumns columnsProvider, bool columnSortingSupported) { Init(columnsProvider, _ColumnSortingSupported); }
void GetRandomValuesIntoTuple(ITableColumns columnsModel, ITuple tuple, System.Random random) { for (int i = 0; i < columnsModel.ColumnsCount; i++) { var randInt = random.Next(); var randIntPos = randInt < 0 ? -randInt : randInt; object obj = null; if (randInt % 10 != 0) // objects can also be null { var columnState = columnsModel.GetColumnState(i); var type = columnState.Info.ValueType; var buf8 = new byte[sizeof(double)]; switch (type) { case TableValueType.RAW: if (randInt % 2 == 0) { obj = new object(); } else { obj = new Vector3((randInt % 4), (randInt % (1 + i)), (randInt % (2 + i))); } break; case TableValueType.STRING: obj = _RandomStrings[randIntPos % _RandomStrings.Length]; break; case TableValueType.INT: obj = randInt; break; case TableValueType.LONG_INT: obj = (((long)(randInt) << 32) + (~randInt)); break; case TableValueType.FLOAT: obj = randInt / 134325.4134E+23f; break; case TableValueType.DOUBLE: // _Random.NextDouble() is useless because it doesn't produce the entire range of doubles // This also can yield NaN and Infinity, but we want that, for demo purposes random.NextBytes(buf8); obj = BitConverter.ToDouble(buf8, 0); break; case TableValueType.ENUMERATION: var enumType = columnState.Info.EnumValueType; var enumValues = Enum.GetValues(enumType); obj = enumValues.GetValue(randIntPos % enumValues.Length); break; case TableValueType.BOOL: obj = randInt % 2 == 0; break; case TableValueType.TEXTURE: obj = _SampleTextures[randIntPos % _SampleTextures.Length]; break; } } tuple.SetValue(i, obj); } }
/// <summary> /// See <see cref="AsyncBufferredDataSource{T}"/> /// </summary> public AsyncBufferredTableData(ITableColumns columns, int tuplesCount, int chunkBufferSize, AsyncBufferredDataSource <TTuple> .Loader loader) { _DataSource = new AsyncBufferredDataSource <TTuple>(tuplesCount, chunkBufferSize, loader); Columns = columns; }
/// <summary> /// <paramref name="rowTuples"/> is the list of all the rows in the table, as tuples implementing <see cref="ITuple"/> /// </summary> public BasicTableData(ITableColumns columnsProvider, IList rowTuples, bool columnSortingSupported) { _RowTuples = rowTuples; Init(columnsProvider, columnSortingSupported); }