Class SelectionTable#

Inheritance Relationships#

Base Type#

Class Documentation#

class SelectionTable : public Karana::WebUI::Widget#

A table whose rows form selection options similar to radio buttons.

Selection is a zero-based index, initially zero for a newly created state. Rows and headers must have the same width; missing cells will trigger an exception. Changing the number of rows resets the index to zero. An empty table or an index outside the rows shows no selection.

Public Functions

SelectionTable(Router &router, std::string_view text, const std::vector<std::vector<std::string>> &choices, const std::vector<std::string> &headers, std::function<void(size_t)> on_change = {}, const Karana::Core::ks_ptr<State> &select_state = nullptr, size_t max_rows = 0, size_t row_height = 34)#

Create a selectable table.

Parameters:
  • router – Connection router.

  • text – Label above the table.

  • choices – Rows containing text cells.

  • headers – Column labels.

  • on_change – Called with the selected row index.

  • select_state – Shared index state, or nullptr to create one initialized to zero.

  • max_rows – Nominal visible row limit; zero leaves the height unlimited.

  • row_height – Nominal row and header height in CSS pixels (default 34). Cells may wrap and grow taller. The scroll cap includes a nominal header plus max_rows rows, with an extra 25% of row_height rounded up to a whole pixel.

Throws:

std::invalid_argument – If a row width differs from the header width.

~SelectionTable() override#

Remove widget callbacks and the subscription to the shared selection state.

void setIndex(size_t index, bool trigger_own_callback = false)#

Select a row by its zero-based index.

Parameters:
  • index – Row index; an out-of-range index displays no selection.

  • trigger_own_callback – Whether to invoke this widget’s callback.

void setMaxRows(size_t max_rows)#

Change the nominal visible row limit without changing selection.

Parameters:

max_rows – Nominal visible row limit; zero removes the scroll-height cap.

void setRowHeight(size_t row_height)#

Change the nominal row and header height without changing selection.

Parameters:

row_height – Height in CSS pixels; cells can grow to fit wrapped text.

void setChoices(const std::vector<std::vector<std::string>> &choices)#

Replace all rows; changing their count resets the index to zero.

Parameters:

choices – New rows with one cell per current header.

Throws:

std::invalid_argument – For mismatched widths; deferred calls report through the server error handler. The previous rows remain unchanged.

void setHeaders(const std::vector<std::string> &headers)#

Replace the column labels.

Parameters:

headers – New column labels matching the current row width.

Throws:

std::invalid_argument – For mismatched widths; deferred calls report through the server error handler. The previous headers remain unchanged.

void setContent(const std::vector<std::vector<std::string>> &choices, const std::vector<std::string> &headers)#

Replace rows and headers together, allowing the column count to change.

Parameters:
  • choices – New rows with one cell per new header.

  • headers – New column labels.

Throws:

std::invalid_argument – If a row width differs from the new headers. Invalid content leaves both rows and headers unchanged. A row-count change resets the index to zero; a same-count replacement preserves it.

Protected Functions

virtual void _onConnect(int client_id) override#

Send current rows and headers to a connecting client.

Parameters:

client_id – Client receiving the current table content.