Loading...
Searching...
No Matches
ml::Table Class Reference

A fixed-size, multi-column data table with a header row. More...

#include <Malena/Graphics/Controls/Table.h>

Inheritance diagram for ml::Table:
[legend]

Public Types

using Flag = TableManifest::Flag
using State = TableManifest::State

Public Member Functions

 Table (const sf::Font &font=FontManager<>::getDefault())
 Table (const Table &)=delete
void addColumn (const std::string &header, float width=0.f)
 Define a column. Call before adding rows.
void addRow (const std::vector< std::string > &cells)
 Append a data row.
void clear ()
 Remove all data rows (columns are kept).
void clearRowColor (std::size_t rowIndex)
 Remove the colour override for a specific row.
std::size_t columnCount () const
sf::FloatRect getGlobalBounds () const override
sf::Vector2f getPosition () const override
sf::Vector2f getSize () const
bool isSettingsLocked () const
 Return true if applySettings() is currently blocked.
bool isThemeLocked () const
 Return true if this component ignores theme changes.
void lockSettings ()
 Prevent applySettings() from taking effect.
void lockTheme ()
 Prevent automatic re-styling when the global theme changes.
Tableoperator= (const Table &)=delete
bool removeRow (std::size_t index)
 Remove a row by index (0 = oldest).
void reset ()
 Remove all data rows AND all column definitions.
std::size_t rowCount () const
void setAltRowBgColor (const sf::Color &c)
void setBorderColor (const sf::Color &c)
void setDividerColor (const sf::Color &c)
void setFontSize (unsigned int s)
void setHeaderBgColor (const sf::Color &c)
void setHeaderHeight (float h)
void setHeaderTextColor (const sf::Color &c)
void setMaxRows (std::size_t max)
 Cap the number of stored rows; oldest are dropped on overflow. Pass 0 to disable the limit.
void setPadding (float p)
void setPosition (const sf::Vector2f &pos) override
void setRowBgColor (const sf::Color &c)
void setRowColor (std::size_t rowIndex, sf::Color color)
 Override the background colour of a specific row.
void setRowHeight (float h)
void setSize (const sf::Vector2f &size)
void setTextColor (const sf::Color &c)
void unlockSettings ()
 Allow applySettings() to take effect again.
void unlockTheme ()
 Resume reacting to global theme changes.

Protected Member Functions

void draw (sf::RenderTarget &target, sf::RenderStates states) const override
void onThemeApplied (const Theme &theme) override
 Called by ThemeManager when the active theme changes.

Detailed Description

A fixed-size, multi-column data table with a header row.

Columns are defined once via addColumn(); rows are appended with addRow() and removed with clear() or removeRow(). When more rows exist than can fit in the visible area the table shows the newest rows (tail view) — no scrollbar, just a live window.

Usage

ml::Table table;
table.setSize({600.f, 400.f});
table.setPosition({20.f, 100.f});
table.addColumn("App", 300.f);
table.addColumn("Event", 300.f);
table.setMaxRows(200);
table.addRow({"Chrome", ""});
table.addRow({"", "copy"});
addComponent(table);
A fixed-size, multi-column data table with a header row.
Definition Table.h:63
void setMaxRows(std::size_t max)
Cap the number of stored rows; oldest are dropped on overflow. Pass 0 to disable the limit.
void setSize(const sf::Vector2f &size)
Definition Table.h:187
void addColumn(const std::string &header, float width=0.f)
Define a column. Call before adding rows.
void addRow(const std::vector< std::string > &cells)
Append a data row.
void setPosition(const sf::Vector2f &pos) override

Column widths of 0 share whatever space remains after fixed columns.

See also
TableManifest

Definition at line 62 of file Table.h.

Member Typedef Documentation

◆ Flag

Definition at line 65 of file Table.h.

◆ State

Definition at line 66 of file Table.h.

Constructor & Destructor Documentation

◆ Table() [1/2]

ml::Table::Table ( const sf::Font & font = FontManager<>::getDefault())
explicit

◆ Table() [2/2]

ml::Table::Table ( const Table & )
delete

Member Function Documentation

◆ addColumn()

void ml::Table::addColumn ( const std::string & header,
float width = 0.f )

Define a column. Call before adding rows.

Parameters
headerColumn header label.
widthWidth in pixels; 0 = distribute remaining space evenly.

◆ addRow()

void ml::Table::addRow ( const std::vector< std::string > & cells)

Append a data row.

Extra cells are ignored; missing cells are left blank. If setMaxRows() was called and the row count would exceed the limit, the oldest row is discarded first.

◆ clear()

void ml::Table::clear ( )

Remove all data rows (columns are kept).

◆ clearRowColor()

void ml::Table::clearRowColor ( std::size_t rowIndex)

Remove the colour override for a specific row.

◆ columnCount()

std::size_t ml::Table::columnCount ( ) const
inlinenodiscard

Definition at line 168 of file Table.h.

◆ draw()

void ml::Table::draw ( sf::RenderTarget & target,
sf::RenderStates states ) const
overrideprotected

◆ getGlobalBounds()

sf::FloatRect ml::Table::getGlobalBounds ( ) const
override

◆ getPosition()

sf::Vector2f ml::Table::getPosition ( ) const
override

◆ getSize()

sf::Vector2f ml::Table::getSize ( ) const
inline

Definition at line 188 of file Table.h.

◆ isSettingsLocked()

bool ml::Themeable::isSettingsLocked ( ) const
inlinenodiscardinherited

Return true if applySettings() is currently blocked.

Definition at line 115 of file Themeable.h.

◆ isThemeLocked()

bool ml::Themeable::isThemeLocked ( ) const
inlinenodiscardinherited

Return true if this component ignores theme changes.

Definition at line 97 of file Themeable.h.

◆ lockSettings()

void ml::Themeable::lockSettings ( )
inlineinherited

Prevent applySettings() from taking effect.

Explicit individual setter calls still work normally. Only blocks the batch applySettings() path.

Definition at line 107 of file Themeable.h.

◆ lockTheme()

void ml::Themeable::lockTheme ( )
inlineinherited

Prevent automatic re-styling when the global theme changes.

The component keeps its current visual state. Explicit individual setter calls still work normally.

Definition at line 85 of file Themeable.h.

◆ onThemeApplied()

void ml::Table::onThemeApplied ( const Theme & theme)
overrideprotectedvirtual

Called by ThemeManager when the active theme changes.

Override in your component to re-style from the new theme. Always check isThemeLocked() first:

void onThemeApplied(const Theme& theme) override
{
if (isThemeLocked()) return;
MySettings::applyTheme(theme);
syncFromSettings();
}
void onThemeApplied(const Theme &theme) override
Called by ThemeManager when the active theme changes.
bool isThemeLocked() const
Return true if this component ignores theme changes.
Definition Themeable.h:97
Universal design token set applied across all Themeable components.
Definition Theme.h:70
Parameters
themeThe newly active theme.

Implements ml::Themeable.

◆ operator=()

Table & ml::Table::operator= ( const Table & )
delete

◆ removeRow()

bool ml::Table::removeRow ( std::size_t index)

Remove a row by index (0 = oldest).

◆ reset()

void ml::Table::reset ( )

Remove all data rows AND all column definitions.

◆ rowCount()

std::size_t ml::Table::rowCount ( ) const
inlinenodiscard

Definition at line 167 of file Table.h.

◆ setAltRowBgColor()

void ml::Table::setAltRowBgColor ( const sf::Color & c)
inline

Definition at line 180 of file Table.h.

◆ setBorderColor()

void ml::Table::setBorderColor ( const sf::Color & c)
inline

Definition at line 183 of file Table.h.

◆ setDividerColor()

void ml::Table::setDividerColor ( const sf::Color & c)
inline

Definition at line 182 of file Table.h.

◆ setFontSize()

void ml::Table::setFontSize ( unsigned int s)
inline

Definition at line 174 of file Table.h.

◆ setHeaderBgColor()

void ml::Table::setHeaderBgColor ( const sf::Color & c)
inline

Definition at line 177 of file Table.h.

◆ setHeaderHeight()

void ml::Table::setHeaderHeight ( float h)
inline

Definition at line 173 of file Table.h.

◆ setHeaderTextColor()

void ml::Table::setHeaderTextColor ( const sf::Color & c)
inline

Definition at line 178 of file Table.h.

◆ setMaxRows()

void ml::Table::setMaxRows ( std::size_t max)

Cap the number of stored rows; oldest are dropped on overflow. Pass 0 to disable the limit.

◆ setPadding()

void ml::Table::setPadding ( float p)
inline

Definition at line 175 of file Table.h.

◆ setPosition()

void ml::Table::setPosition ( const sf::Vector2f & pos)
override

◆ setRowBgColor()

void ml::Table::setRowBgColor ( const sf::Color & c)
inline

Definition at line 179 of file Table.h.

◆ setRowColor()

void ml::Table::setRowColor ( std::size_t rowIndex,
sf::Color color )

Override the background colour of a specific row.

The override persists until clearRowColor() or clear() is called. Indices shift automatically when rows are inserted or removed.

Parameters
rowIndex0-based index of the row to highlight.
colorBackground colour to use instead of the default.

◆ setRowHeight()

void ml::Table::setRowHeight ( float h)
inline

Definition at line 172 of file Table.h.

◆ setSize()

void ml::Table::setSize ( const sf::Vector2f & size)
inline

Definition at line 187 of file Table.h.

◆ setTextColor()

void ml::Table::setTextColor ( const sf::Color & c)
inline

Definition at line 181 of file Table.h.

◆ unlockSettings()

void ml::Themeable::unlockSettings ( )
inlineinherited

Allow applySettings() to take effect again.

Definition at line 112 of file Themeable.h.

◆ unlockTheme()

void ml::Themeable::unlockTheme ( )
inlineinherited

Resume reacting to global theme changes.

Does NOT immediately re-apply the current theme — call ThemeManager::get() and pass it to onThemeApplied() manually if you want to re-sync immediately after unlocking.

Definition at line 94 of file Themeable.h.


The documentation for this class was generated from the following file: