GridPicker
Description
The GridPicker component creates an interactive grid of buttons, where each cell can have multiple states. It is used for building grid-based state selectors and pickers, such as scheduling interfaces or game boards. The component is part of the Tesserae UI Components group and leverages a fluent interface to configure button appearance and behavior based on the state.
Usage
Create a GridPicker instance by providing arrays of column and row names, the number of states each cell can have, an initial state for every cell, and a function to format each button based on its state. Optionally, you can provide custom column sizes and row heights.
Below is a simple usage example:
API reference
public sealed class GridPicker : IComponentA GridPicker component that allows users to select states across a grid of buttons, supporting drag-to-select functionality.
Constructors
public GridPicker(string[] columnNames, string[] rowNames, int states, int[][] initialStates, Action<Button, int, int> formatState, UnitSize[] columns = null, UnitSize rowHeight = null)Initializes a new instance of the GridPicker class.
Parameters
- columnNames
- Names of the columns.
- rowNames
- Names of the rows.
- states
- Number of available states for each grid cell.
- initialStates
- Initial state values for each cell.
- formatState
- An action to format the button based on its state.
- columns
- Optional column widths.
- rowHeight
- Optional row height.
Properties
Methods
public int[][] GetState()Gets the current state of the grid picker.
Returns
A 2D array representing the states.
public GridPicker SetState(int[][] state)Sets the current state of the grid picker.
Parameters
- state
- A 2D array representing the new states.
Returns
The current instance of the type.
public GridPicker OnChange(ComponentEventHandler<GridPicker, Event> onChange)Adds a change event handler to the grid picker.
Parameters
- onChange
- The event handler.
Returns
The current instance of the type.
Samples
Basic GridPicker Example
The following sample demonstrates how to instantiate a simple GridPicker with two states. Each cell displays different text based on its current state.
Advanced GridPicker for Hourly Schedule
This sample shows how to create an hourly schedule picker by dynamically generating column headers for each hour of the day.