GridAdapterTParams, TCellVH Class |
An optimized adapter for a GridView
Implements OSATParams, TItemViewsHolder to simulate a grid by using
a runtime-generated "row" prefab (or "colum" prefab, if horizontal ScrollView), having a Horizontal (or Vertical, respectively) LayoutGroup component, inside which its corresponding cells will lie.
This prefab is represented by a CellGroupViewsHolderTCellVH, which nicely abstractizes the mechanism to using cell prefabs. This views holder is managed internally and is no concern for most users.
The cell prefab is used the same way as the "item prefab", for those already familiarized with the ListView examples. It is represented
by a CellViewsHolder, which are the actual views holders you need to create/update and nothing else.
Namespace: Com.ForbiddenByte.OSA.CustomAdapters.GridView
public abstract class GridAdapter<TParams, TCellVH> : OSA<TParams, CellGroupViewsHolder<TCellVH>> where TParams : GridParams where TCellVH : new(), CellViewsHolder
The GridAdapterTParams, TCellVH type exposes the following members.
Name | Description | |
---|---|---|
GridAdapterTParams, TCellVH |
Name | Description | |
---|---|---|
CellsCount | The "items count". Same value is returned in GetItemsCount | |
InsertAtIndexSupported | (Overrides OSATParams, TItemViewsHolderInsertAtIndexSupported.) | |
RemoveFromIndexSupported | (Overrides OSATParams, TItemViewsHolderRemoveFromIndexSupported.) |
Name | Description | |
---|---|---|
ChangeItemsCount | Overridden in order to convert the cellsCount to groupsCount before passing it to the base's implementation (Overrides OSATParams, TItemViewsHolderChangeItemsCount(ItemCountChangeMode, Int32, Int32, Boolean, Boolean).) | |
CreateViewsHolder | Creates the Group viewsholder which instantiates the group prefab using the provided params in Init. Only override it if you have a custom cell group prefab (Overrides OSATParams, TItemViewsHolderCreateViewsHolder(Int32).) | |
GetCellGroupsCount | ||
GetCellViewsHolder | Retrieve the views holder of a cell with speciffic index in view. For example, one can iterate from 0 to GetNumVisibleCells in order to do something with each visible cell. Not to be mistaken for GetCellViewsHolderIfVisible(Int32), which retrieves a cell by the index of its corresponding model in your data list (ItemIndex) | |
GetCellViewsHolderIfVisible(Int32) | Retrieve the views holder of a cell whose associated model's index in your data list is withCellItemIndex. Not to be mistaken for GetCellViewsHolder(Int32) which retrieves a cell by its index in the "all visible cells" list | |
GetCellViewsHolderIfVisible(CellGroupViewsHolderTCellVH, Int32) | ||
GetItemsCount | Overriding base's implementation to return the cells count, instead of the groups count (Overrides OSATParams, TItemViewsHolderGetItemsCount.) | |
GetNewCellGroupViewsHolder | Provide your own implementation of the group prefab, if you have a custom one. Most often than not, you won't use this | |
GetNumVisibleCells | The number of visible cells | |
GetViewsHolderClosestToViewportLongitudinalNormalizedAbstractPoint |
Tha base implementation finds the group. Here, we're narrowing the search in the group iself in order to return the CellViewsHolder
(Overrides OSATParams, TItemViewsHolderGetViewsHolderClosestToViewportLongitudinalNormalizedAbstractPoint(Canvas, RectTransform, Single, Single, Single).) | |
InsertItems | Not currently implemented for GridAdapters (Overrides OSATParams, TItemViewsHolderInsertItems(Int32, Int32, Boolean, Boolean).) | |
OnBeforeRecycleOrDisableCellViewsHolder | The only important callback for inheritors. It provides cell's views holder which has just become visible and whose views should be updated from its corresponding data model. viewsHolder.ItemIndex(ItemIndex) can be used to know what data model is associated with. | |
OnBeforeRecycleOrDisableViewsHolder |
Overridden in order to call OnBeforeRecycleOrDisableCellViewsHolder(TCellVH, Int32) for each active cell in the group
(Overrides OSATParams, TItemViewsHolderOnBeforeRecycleOrDisableViewsHolder(TItemViewsHolder, Int32).) | |
OnCellGroupsRefreshed | ||
OnCellViewsHolderCreated | Called for each cell in a cell group at the moment the group is first created | |
OnInitialized | (Overrides OSATParams, TItemViewsHolderOnInitialized.) | |
OnItemIndexChangedDueInsertOrRemove | This is not needed yet in case of grid adapters (Overrides OSATParams, TItemViewsHolderOnItemIndexChangedDueInsertOrRemove(TItemViewsHolder, Int32, Boolean, Int32).) | |
OnItemsRefreshed | (Overrides OSATParams, TItemViewsHolderOnItemsRefreshed(Int32, Int32).) | |
RebuildLayoutDueToScrollViewSizeChange | (Overrides OSATParams, TItemViewsHolderRebuildLayoutDueToScrollViewSizeChange.) | |
Refresh |
Overriding base's implementation so that we pass the cells count to our own implementation which converts them to group count before further passing it to the base impl.
(Overrides OSATParams, TItemViewsHolderRefresh(Boolean, Boolean).) | |
RemoveItems | Not currently implemented fir GridAdapters (Overrides OSATParams, TItemViewsHolderRemoveItems(Int32, Int32, Boolean, Boolean).) | |
ScrollTo | Scrolls to the specified cell. Use ScrollToGroup(Int32, Single, Single) if that was intended instead (Overrides OSATParams, TItemViewsHolderScrollTo(Int32, Single, Single).) | |
ScrollTo_ConvertItemPivotToUseIfPossible | ||
ScrollToGroup | Scroll to the specified GROUP. Use ScrollTo(Int32, Single, Single) if scrolling to a CELL was intended instead | |
SmoothBringToView | (Overrides OSATParams, TItemViewsHolderSmoothBringToView(Int32, Single, NullableSingle, FuncSingle, Boolean, Action, Boolean).) | |
SmoothScrollTo | Scrolls to the specified cell. Use SmoothScrollToGroup(Int32, Single, Single, Single, FuncSingle, Boolean, Action, Boolean) if that was intended instead (Overrides OSATParams, TItemViewsHolderSmoothScrollTo(Int32, Single, Single, Single, FuncSingle, Boolean, Action, Boolean).) | |
SmoothScrollToGroup | ||
UpdateCellViewsHolder | The only important callback for inheritors. It provides cell's views holder which has just become visible and whose views should be updated from its corresponding data model. viewsHolder.ItemIndex(ItemIndex) can be used to know what data model is associated with. | |
UpdateViewsHolder |
Here the grid adapter checks if new groups need to be created or if old ones need to be disabled or destroyed, after which it calls UpdateCellViewsHolder(TCellVH) for each remaining cells.
(Overrides OSATParams, TItemViewsHolderUpdateViewsHolder(TItemViewsHolder).)Override it (and call the base implementation!) only if you know what you're doing. If you just want to update your cells' views, do it in UpdateCellViewsHolder(TCellVH) |
Name | Description | |
---|---|---|
ItemsRefreshed |
This override the base's implementation to return the cells count, instead of the groups(rows) count.
Params are: 1=prevCellCount, 2=newCellCount
(Overrides OSATParams, TItemViewsHolderItemsRefreshed.) |
Name | Description | |
---|---|---|
_CellsCount |