Class GridView
A view containing recycled rows with items inside.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
public class GridView : BaseGridView, IEventHandler, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IResolvedStyle, IBindable, ISerializationCallbackReceiver
Constructors
GridView()
Creates a GridView with all default properties. The itemsSource, itemHeight, makeItem and bindItem properties must all be set for the GridView to function properly.
Declaration
public GridView()
GridView(IList, Func<VisualElement>, Action<VisualElement, int>)
Constructs a GridView, with all required properties provided.
Declaration
public GridView(IList itemsSource, Func<VisualElement> makeItem, Action<VisualElement, int> bindItem)
Parameters
Type | Name | Description |
---|---|---|
IList | itemsSource | The list of items to use as a data source. |
Func<VisualElement> | makeItem | The factory method to call to create a display item. The method should return a VisualElement that can be bound to a data item. |
Action<VisualElement, int> | bindItem | The method to call to bind a data item to a display item. The method receives as parameters the display item to bind, and the index of the data item to bind it to. |
Properties
itemHeight
The height of a single item in the list, in pixels.
Declaration
public int itemHeight { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
GridView requires that all visual elements have the same height so that it can calculate the scroller size.
This property must be set for the list view to function.
resolvedItemHeight
The computed pixel-aligned height for the list elements.
Declaration
public float resolvedItemHeight { get; }
Property Value
Type | Description |
---|---|
float |
Remarks
This value changes depending on the current panel's DPI scaling.
See Also
Methods
ApplySelectedState()
Set the selected visual state on items.
Declaration
protected override void ApplySelectedState()
Overrides
GetIndexByWorldPosition(Vector2)
Returns the index of the item at the given position.
Declaration
public override int GetIndexByWorldPosition(Vector2 worldPosition)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | worldPosition | The position of the item in the world-space. |
Returns
Type | Description |
---|---|
int | The index of the item at the given position. |
Overrides
Remarks
The position is relative to the top left corner of the grid. No check is made to see if the index is valid.
GetVisualElementInternal(int)
Implement this method to return the VisualElement at the specified index.
Declaration
protected override VisualElement GetVisualElementInternal(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the VisualElement to return. |
Returns
Type | Description |
---|---|
VisualElement | The VisualElement at the specified index. |
Overrides
OnContainerHeightChanged(float)
Callback called when the ScrollView container height changes.
Declaration
protected override void OnContainerHeightChanged(float height)
Parameters
Type | Name | Description |
---|---|---|
float | height | The new height of the container. |
Overrides
OnCustomStyleResolved(CustomStyleResolvedEvent)
Method to implement to handle the custom style resolved event.
Declaration
protected override void OnCustomStyleResolved(CustomStyleResolvedEvent e)
Parameters
Type | Name | Description |
---|---|---|
CustomStyleResolvedEvent | e | The custom style resolved event. |
Overrides
OnScroll(float)
Callback called when the scroll value changes.
Declaration
protected override void OnScroll(float offset)
Parameters
Type | Name | Description |
---|---|---|
float | offset | The new scroll offset. |
Overrides
Remarks
You can also call this method one frame your Refresh() implementation to ensure the visual state of the grid is updated correctly.
Refresh()
Clears the GridView, recreates all visible visual elements, and rebinds all items.
Declaration
public override void Refresh()
Overrides
Remarks
Call this method whenever the data source changes.
ScrollToItem(int)
Scrolls to a specific item index and makes it visible.
Declaration
public override void ScrollToItem(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | Item index to scroll to. Specify -1 to make the last item visible. |