Table and List Sources
ModernUI data controls use sources.
Simple helpers such as Mui::ListBox and Mui::SimpleTable create basic string sources for you. Larger or domain-specific controls use custom source classes.
Choose the right source path
| Need | Use |
|---|---|
| Small string list | Mui::ListBox |
| Small string table | Mui::SimpleTable |
| Large/dynamic list | MuiListView with MuiItemSource |
| Large/dynamic table | MuiTableView with MuiTableSource |
| Hierarchical data | MuiTreeView with tree source |
ListBox
string items[];
ArrayResize(items,3);
items[0]="One";
items[1]="Two";
items[2]="Three";
MuiListBox lb=Mui::ListBox(parent,items,0,0.0,0.0);
lb.SetItem(1,"Two updated");
MuiListBox exposes:
| Member | Purpose |
|---|---|
list |
MuiListView* |
source |
backing string source |
Count() |
number of rows |
SetItem(index,value) |
update row |
Item(index) |
read row |
Refresh() |
notify after direct source changes |
SimpleTable
string headers[];
ArrayResize(headers,3);
headers[0]="Time";
headers[1]="Event";
headers[2]="Status";
MuiSimpleTable table=Mui::SimpleTable(parent,headers,4,0.0,180.0,true,true);
table.SetCell(0,0,"10:30");
table.SetCell(0,1,"Started");
table.SetCell(0,2,"OK");
MuiSimpleTable exposes:
| Member/method | Purpose |
|---|---|
table |
MuiTableView* |
source |
backing table source |
Rows() |
data row count |
Cols() / Columns() |
column count |
SetCell(row,col,value) |
set one cell |
Cell(row,col) |
read one cell |
SetRow(row,values[]) |
set a row |
Clear() |
clear data rows |
Refresh() |
notify after direct source changes |
Custom item source
Use MuiItemSource for larger lists.
class MyItemSource : public MuiItemSource
{
public:
virtual int Count(void)
{
return 1000;
}
virtual void BindRow(MuiRowTemplate *row,const int index)
{
row.primary.Text("Row "+IntegerToString(index));
row.primary.SetVisible(true);
row.secondary.SetVisible(false);
row.meta.SetVisible(false);
row.badge.SetVisible(false);
}
};
static MyItemSource source;
MuiListView *list=Mui::ListView(parent,&source,260.0,220.0);
Custom table source
Use MuiTableSource for large or custom table data.
class MyTableSource : public MuiTableSource
{
public:
virtual int RowCount(void) { return 5000; }
virtual int ColCount(void) { return 5; }
virtual string ColName(const int col)
{
return "C"+IntegerToString(col);
}
virtual string CellText(const int row,const int col)
{
return IntegerToString(row)+":"+IntegerToString(col);
}
};
static MyTableSource source;
MuiTableView *table=Mui::TableView(parent,&source,520.0,260.0);
Row recycling rule
Virtualized rows may be reused.
In BindRow, reset every bindable field:
- text
- secondary text
- meta text
- badge text
- visibility
- colours
- checked/selected visual state where relevant
Do not rely on the previous row state.
Source lifetime
Data views typically do not own custom sources.
Practical rules:
- source object must outlive the view
- static/global sources are safe for examples
- heap sources need a clear owner
- do not delete a source while a control still references it
ListBoxandSimpleTableexpose their backing source pointers
Refreshing data
Call the wrapper/source refresh method after direct changes.
table.Refresh();
lb.Refresh();
For custom sources, call the relevant source/control notification method used by the control.
Common mistakes
Expensive CellText
CellText can be called often. Cache expensive formatting where possible.
Stale pooled rows
If reused rows show old badges/text, your BindRow is not resetting everything.
Using SimpleTable for numeric sorting
SimpleTable is string-based. Use a custom source for numeric/domain sorting.