Table
Table view.
| Header | #include "nativeui/table.h" |
| Namespace | namespace nu |
| Type | class (RefCounted) |
| Inherits | View |
The Table does not store any data itself, to display data in Table, users
have to provide a TableModel.
How data are renderered depends on the type of column. It is also possible to create a custom renderer for arbitrary data.
Constructors
Table()
Create a new Table.
Class properties
const char* kClassName
The class name of this view.
Methods
void SetModel(scoped_refptr<TableModel> model)
Set model as table's data source.
Parameters
TableModel* GetModel()
Return table's model.
Return
TableModel*void AddColumn(const std::string& title)
Add a new column with title, which shows readonly text.
Parameters
const std::string&title
void AddColumnWithOptions(const std::string& title, const Table::ColumnOptions& options)
Add a new column with title and options.
Parameters
const std::string&titleconst Table::ColumnOptions&options
int GetColumnCount() const
Return the number of columns.
Return
intvoid SetColumnsVisible(bool visible)
Set whether the columns header is visible.
On macOS adding column after hiding the header will result in missing columns in the header even after making the header visible again.
It is recommended to never show the header again after hiding the header, for consistent behaviors between platforms.
Parameters
boolvisible
bool IsColumnsVisible() const
Return whether the columns header is visible.
Return
boolvoid SetRowHeight(float height)
Set the height of each row.
It is not recommended to change row height unless you are drawing all cells yourself, as the default text cells may not show decently under large or small height.
On Linux, due to platform implementations, this method has to be called before adding columns. It does not have any effect when columns have already been added.
Parameters
floatheight
float GetRowHeight() const
Return the height of each row.
Return
floatvoid SetHasBorder(bool has)
Set whether the view has border.
Parameters
boolhas
bool HasBorder() const
Return whether the view has border.
Return
boolvoid EnableMultipleSelection(bool enable)
Set whether it is allowed to select more than one row at a time.
Parameters
boolenable
bool IsMultipleSelectionEnabled() const
Return whether it is allowed to select more than one row at a time.
Return
boolvoid SelectRow(int row)
Select a row.
Parameters
introw
int GetSelectedRow() const
Return the index of selected row.
For table that allows multiple selections, this will return the index of
first selected row. When no row is selected, -1 will be returned.
Return
intvoid SelectRows(std::set<int> rows)
Select multiple rows.
Parameters
std::set<int>rows
std::set<int> GetSelectedRows() const
Return selected rows' indexes.
Return
std::set<int>Events
void on_selection_change(Table* self)
Emitted when the table's selection has changed.
Parameters
Table*self
Preventable
No.void on_row_activate(Table* self, int row)
Emitted when the user double-clicks a row.
Parameters
Table*selfintrow
Preventable
No.void on_toggle_checkbox(Table* self, int column, int row)
Emitted when the user clicks a cell to toggle checkbox.
Parameters
Table*selfintcolumnintrow