![]() |
Lysa UI
0.0
Lysa UI —UI components for the Lysa Engine
|
Grid lays out its children in rows and columns of independent sizes each position being a GridCell container. Table builds on it by adding a row of column headers that sort and resize the columns.
Neither widget owns the data it displays: a cell is only a container and the value are stored in the user data of the widgets.
A Grid is a Widget drawn with a border:
The rows and the columns of the constructor are created when the grid is added to a Window, so the grid must be attached before addRow() or addColumn() is called.
Row 0 is the top row and column 0 the leftmost one, even though the coordinate space is Y-up:
Rows and columns are inserted and removed at any position :
Every row has a height and every column a width, expressed in UI units. A size of Grid::AUTO_SIZE (zero) means that the row or the column shares what is left :
getRowHeight() and getColumnWidth() return the requested size, AUTO_SIZE included :
The cells are laid out inside the client rectangle of the grid (minus its borders and its padding). Sizes are clamped to that rectangle.
A GridCell is a Widget : add the widgets to display into it with the usual create() / add() and alignments :
A cell can be given a background of its own:
The grid never owns a value, you have to use the user data:
getCell() returns the cell displaying a position :
merge() turns a rectangle of positions into a single cell with the one at its top-left corner :
merge() returns false when the rectangle is not entirely inside the grid.
split() removes the span of the cell displaying a position :
A cell knows the rectangle it covers:
Rows are moved with the widgets they display and nothing is re-created. This is what makes a sort possible without the grid knowing anything about the data.
The lines between the cells are drawn above them so a cell with a background never hides them :
The style provides the default :
Table is a Grid with a row of column headers displayed above it and kept aligned with the columns. A header is a Button holding the title of the column and an Arrow showing the sort direction:
Rows are added to the table itself :
Set setDefaultRowHeight(Grid::AUTO_SIZE) to get back the behaviour of the grid, the rows sharing the height of the table.
Clicking the header of a sortable column changes the sorted column and the sort direction and emits UIEvent::OnSortColumn.
The table does not reorder the rows by itself**: it does not know what a cell displays. React to the signal and reorder the rows yourself or let sortRows() do it :
The comparator returns true when the first cell must be displayed above the second one for the SortOrder::ASCENDING direction. sortRows() reverses the result when the table is currently sorted in SortOrder::DESCENDING.
getUserData<T>() throws when the cell has no user data of that type: give every cell of a sorted column its value or compare through the widgets of the cells instead.
The sort is also driven from the code, which emits the signal exactly like a click on a header:
Dragging the right border of the header of a resizable column changes the width of that column :
The two widgets built by the table are reachable :
Each column keeps its header, its title and its sort indicator:
The height of the row of headers is computed from the height of the titles unless it is set explicitly:
The resources of the headers of the grid and of the sort indicators are assigned by the style :