82 using CellTextProvider = std::function<std::string(
int row,
int col)>;
83 using CellFactory = std::function<std::shared_ptr<Layout>(
int row,
int col)>;
85 explicit Table(
float rowHeight = 32.0f,
float headerHeight = 34.0f);
90 int addColumn(std::string title,
92 bool sortable =
false,
93 bool resizable =
true,
95 float minWidth = 48.0f,
97 void setColumns(std::vector<TableColumnSpec> cols);
100 int columnCount()
const noexcept {
return static_cast<int>(columns_.size()); }
101 const std::vector<TableColumnSpec> &columns()
const noexcept {
return columns_; }
103 void setColumnWidth(
int col,
float width,
bool notify =
false);
104 float getColumnWidth(
int col)
const;
105 float totalColumnsWidth()
const noexcept;
111 int getRowCount() const noexcept {
return rowCount_; }
114 void setRows(std::vector<std::vector<std::string>> rows);
115 void addRow(std::vector<std::string> row);
118 void setCellTextProvider(CellTextProvider provider);
119 void setCellFactory(CellFactory factory);
124 void setRowHeight(
float px);
125 float getRowHeight() const noexcept {
return rowHeight_; }
127 void setHeaderHeight(
float px);
128 float getHeaderHeight() const noexcept {
return headerHeight_; }
132 void setSort(
int col,
SortDirection dir,
bool notify =
false);
133 void clearSort(
bool notify =
false) { setSort(-1, SortDirection::None, notify); }
134 int getSortColumn() const noexcept {
return sortColumn_; }
135 SortDirection getSortDirection() const noexcept {
return sortDirection_; }
139 void selectRow(
int row,
bool notify =
false);
140 void clearSelection(
bool notify =
false) { selectRow(-1, notify); }
141 int getSelectedRow() const noexcept {
return selectedRow_; }
143 void scrollToRow(
int row);
147 std::shared_ptr<Layout> headerBar()
const {
return headerViewport_; }
148 std::shared_ptr<Layout> headerRow()
const {
return headerRow_; }
149 std::shared_ptr<Button> headerButton(
int col);
150 std::shared_ptr<Layout> resizeHandle(
int col);
151 std::shared_ptr<VirtualView> body()
const {
return body_; }
155 std::function<void(
int row)> onSelectionChanged;
156 std::function<void(
int row)> onRowActivated;
157 std::function<void(
int col,
SortDirection dir)> onSortChanged;
158 std::function<void(
int col,
float width)> onColumnResized;
171 struct HeaderColNodes
173 std::shared_ptr<Layout> cell;
174 std::shared_ptr<Button> button;
175 std::shared_ptr<Layout> handle;
178 void ingestDeclarativeColumns();
179 void rebuildHeader();
180 void updateHeaderLabels();
181 void updateHeaderGeometry();
182 void syncHeaderScroll();
183 void flushBodyIfDirty();
184 void applySelectionVisuals();
185 void handleHeaderClick(
int col);
186 void handleRowClick(
int row);
187 void setDraggingCursor(
bool active);
188 std::shared_ptr<Layout> buildRow(
int row);
189 std::string resolveCellText(
int row,
int col)
const;
191 std::shared_ptr<Layout> headerViewport_;
192 std::shared_ptr<Layout> headerRow_;
193 std::shared_ptr<VirtualView> body_;
194 std::shared_ptr<Layout> columnsStaging_;
196 std::vector<TableColumnSpec> columns_;
197 std::vector<HeaderColNodes> headerNodes_;
198 std::vector<std::vector<std::string>> inlineRows_;
199 std::vector<std::pair<int, std::weak_ptr<Layout>>> materializedRows_;
201 CellTextProvider textProvider_;
202 CellFactory cellFactory_;
204 float rowHeight_{32.0f};
205 float headerHeight_{34.0f};
207 int selectedRow_{-1};
211 bool headerDirty_{
true};
212 bool bodyDirty_{
false};
213 float lastHeaderScrollX_{0.0f};
215 int resizingCol_{-1};
216 float resizeStartX_{0.0f};
217 float resizeStartWidth_{0.0f};
219 int lastClickedRow_{-1};
220 double lastClickTime_{-10.0};
The node class: tree structure, layout pass, style resolution, input dispatch, render orchestration,...
A read-only text node backed by UIContext::textEngine.