Lysa UI  0.0
Lysa UI —UI components for the Lysa Engine
Table Class Reference

Detailed Description

A Grid with a row of column headers.

+ Inheritance diagram for Table:

Classes

struct  Column
 

Public Types

enum class  SortOrder { NONE, ASCENDING, DESCENDING }
 
- Public Types inherited from Widget
enum  Type {
  WIDGET, PANEL, BOX, LINE,
  FRAME, BUTTON, TOGGLEBUTTON, RADIOBUTTON,
  CHECKBOX, CHECKMARK, CROSSMARK, ARROW,
  TEXT, TEXTEDIT, RICHTEXTAREA, SCROLLBAR,
  SLIDER, COLORSLIDER, COLORWHEEL, KNOB,
  TREEVIEW, IMAGE, POPUP, LIST,
  LISTBOX, SELECTION, PROGRESSBAR, SCROLLCONTAINER,
  MENU, MENUPANEL, MENUBOX, TABBAR,
  TABCONTAINER, DIALOG, FOLDABLECONTAINER, COLORPICKER,
  COLORPICKERBUTTON, SPINBOX, SPINBUTTONS, ICONIMAGE,
  ICONSVG, DROPDOWNLIST, TOOLTIP, GRIDCELL,
  GRID, TABLE
}
 

Public Member Functions

 Table ()
 
void setResources (const std::string &resHeader, const std::string &resGrid, const std::string &resArrow)
 
int32 addColumn (const std::string &title, float width=Grid::AUTO_SIZE, bool sortable=true, bool resizable=true)
 
int32 addColumn (const std::shared_ptr< Widget > &title, float width=Grid::AUTO_SIZE, bool sortable=true, bool resizable=true)
 
void removeColumn (int32 index)
 
void removeAllColumns ()
 
int32 getColumnCount () const
 
const auto & getColumns () const
 
std::shared_ptr< ButtongetColumnHeader (int32 index) const
 
template<typename T = Widget>
std::shared_ptr< T > getColumnTitle (int32 index) const
 
int32 getColumnAt (float x) const
 
void setColumnWidth (int32 index, float width)
 
float getColumnWidth (int32 index) const
 
void setColumnSortable (int32 index, bool sortable=true)
 
bool isColumnSortable (int32 index) const
 
void setColumnResizable (int32 index, bool resizable=true)
 
bool isColumnResizable (int32 index) const
 
int32 addRow (float height=0.0f) const
 
void insertRow (int32 index, float height=0.0f) const
 
void removeRow (int32 index) const
 
void removeAllRows () const
 
int32 getRowCount () const
 
void setRowHeight (int32 index, float height) const
 
float getRowHeight (int32 index) const
 
void setDefaultRowHeight (const float height)
 
auto getDefaultRowHeight () const
 
std::shared_ptr< GridCellgetCell (int32 row, int32 column) const
 
void sort (int32 column, SortOrder order)
 
void sortRows (int32 column, const std::function< bool (const GridCell &, const GridCell &)> &comparator) const
 
auto getSortedColumn () const
 
auto getSortOrder () const
 
void setHeaderHeight (float height)
 
auto getHeaderHeight () const
 
void setGripWidth (float width)
 
auto getGripWidth () const
 
const auto & getGrid () const
 
const auto & getHeader () const
 
void onResize () override
 
void onHide () override
 
void onDetach () override
 
- Public Member Functions inherited from Widget
 Widget (Type type=WIDGET)
 
 ~Widget () override
 
Type getType () const
 
bool isVisible () const
 
void setVisible (bool show=true)
 
bool isEnabled () const
 
void setEnabled (bool isEnabled=true)
 
virtual void setPos (float x, float y)
 
float getWidth () const
 
float getHeight () const
 
float getRequestedWidth () const
 
float getRequestedHeight () const
 
virtual void setSize (float width, float height)
 
void setWidth (const float width)
 
void setHeight (const float height)
 
const Rect & getRect () const
 
void setRect (float x, float y, float width, float height)
 
void setRect (const Rect &rect)
 
float getAspectRatio () const
 
Alignment getAlignment () const
 
void setAlignment (Alignment alignment)
 
std::shared_ptr< Font > getFont () const
 
void setFont (const std::shared_ptr< Font > &font)
 
float getFontScale () const
 
virtual void setFontScale (float fontScale)
 
bool isFocused () const
 
Widget * getParent () const
 
void setOverlap (const bool overlap)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const std::string &resource, const Alignment alignment, Args &&...args)
 
template<typename T , typename... Args>
std::shared_ptr< T > create (const Alignment alignment, Args &&...args)
 
template<typename T >
std::shared_ptr< T > add (std::shared_ptr< T > child, const Alignment alignment=Alignment::NONE, const std::string &resource="", const bool overlap=false)
 
template<typename T >
std::shared_ptr< T > addPopup (std::shared_ptr< T > child, const std::string &resource="")
 
template<typename T >
std::shared_ptr< T > addAfter (std::shared_ptr< T > child, const std::shared_ptr< Widget > &after, const Alignment alignment, const std::string &resource="", const bool overlap=false)
 
virtual void remove (const std::shared_ptr< Widget > &child)
 
virtual void removeAll ()
 
void setPadding (float padding)
 
float getPadding () const
 
float getVBorder () const
 
float getHBorder () const
 
void setVBorder (float size)
 
void setHBorder (float size)
 
bool isDrawBackground () const
 
void setDrawBackground (bool drawBackground)
 
bool isPushed () const
 
bool isPointed () const
 
bool isFreezed () const
 
bool isRedrawOnMouseEvent () const
 
bool isOverlapping () const
 
Rect getChildrenRect () const
 
void setFreezed (const bool f)
 
void setPushed (const bool p)
 
void refresh ()
 
void setResource (std::shared_ptr< UIResource > res)
 
uint32 getGroupIndex () const
 
void setGroupIndex (int32 index)
 
template<typename T >
getUserData () const
 
template<typename T >
std::shared_ptr< T > getPointerUserData () const
 
const std::any & getUserData () const
 
void setUserData (const std::any &data)
 
float getTransparency () const
 
void setTransparency (float alpha)
 
void resizeChildren ()
 
float getChildrenOffsetX () const
 
float getChildrenOffsetY () const
 
void setChildrenOffset (float x, float y)
 
std::shared_ptr< Widget > setFocus (bool focus=true)
 
virtual void onAttach ()
 
virtual void onShow ()
 
virtual void onMove ()
 
virtual bool onKeyDown (Key key)
 
virtual bool onTextInput (const std::string &text)
 
virtual bool onKeyUp (Key key)
 
virtual bool onMouseDown (MouseButton button, float x, float y)
 
virtual bool onMouseUp (MouseButton button, float x, float y)
 
virtual bool onMouseMove (uint32 buttonsState, float x, float y)
 
virtual void onMouseLeave ()
 
virtual void onDisable ()
 
virtual void onEnable ()
 
virtual void onGotFocus ()
 
virtual void onLostFocus ()
 
bool getConsumeMouseEvent () const
 
void setConsumeMouseEvent (const bool consumeMouseEvent)
 
const std::list< std::shared_ptr< Widget > > & getChildren () const
 
bool hasChildren () const
 
void subscribe (const event_type &type, unique_id id, EventHandlerCallback callback)
 
void subscribe (const event_type &type, EventHandlerCallback callback)
 
void unsubscribe (unique_id id)
 
bool isAttached () const
 
WindowgetWindow () const
 
StylegetStyle () const
 
Vector2DRenderer & getRenderer () const
 
RenderingWindow & getRenderingWindow () const
 
WindowManagergetWindowManager () const
 

Static Public Attributes

static constexpr int32 NO_COLUMN {-1}
 No column is sortedn. More...
 
static constexpr float DEFAULT_HEADER_HEIGHT {20.0f}
 Default height of the row of headers. More...
 
static constexpr float DEFAULT_ROW_HEIGHT {20.0f}
 Default height of a row of the grid. More...
 
static constexpr float DEFAULT_GRIP_WIDTH {6.0f}
 Default width of the area used to drag the border between two columns. More...
 
static constexpr float MIN_COLUMN_WIDTH {8.0f}
 Smallest width a column can be resized to. More...
 

Additional Inherited Members

- Protected Attributes inherited from Widget
const Type type
 
Rect rect
 
float requestedWidth {0}
 
float requestedHeight {0}
 
float hborder {0}
 
float vborder {0}
 
float padding {0}
 
bool consumeMouseEvent {false}
 
bool overlap {false}
 
bool focused {false}
 
bool allowFocus {false}
 
bool allowChildren {true}
 
bool drawBackground {true}
 
bool moveChildrenOnPush {false}
 
bool scrollChildren {false}
 
bool skipInvisibleChildren {false}
 
bool redrawOnMouseEvent {false}
 
bool redrawOnMouseMove {false}
 
float transparency {1.0f}
 
Widget * parent {nullptr}
 
Alignment alignment {Alignment::NONE}
 
std::shared_ptr< UIResourceresource
 
std::list< std::shared_ptr< Widget > > children
 
bool mouseMoveOnFocus {false}
 
float childrenOffsetX {0}
 
float childrenOffsetY {0}
 

Member Enumeration Documentation

enum class SortOrder
strong

Direction of the sort of a column.

Enum ValuesDocumentation
NONE 

The column is not sorted.

ASCENDING 

The column is sorted from the smallest to the greatest value.

DESCENDING 

The column is sorted from the greatest to the smallest value.

Constructor & Destructor Documentation

Table ( )

Creates an empty table.

Member Function Documentation

int32 addColumn ( const std::shared_ptr< Widget > &  title,
float  width = Grid::AUTO_SIZE,
bool  sortable = true,
bool  resizable = true 
)

Appends a column at the right of the last column.

Parameters
titleWidget displayed by the header.
widthWidth of the column, or Grid::AUTO_SIZE.
sortableTrue if clicking the header sorts the table.
resizableTrue if the width can be changed with the mouse.
Returns
The index (0-based) of the added column.
int32 addColumn ( const std::string &  title,
float  width = Grid::AUTO_SIZE,
bool  sortable = true,
bool  resizable = true 
)

Appends a column at the right of the last column.

Parameters
titleText of the header.
widthWidth of the column, or Grid::AUTO_SIZE.
sortableTrue if clicking the header sorts the table.
resizableTrue if the width can be changed with the mouse.
Returns
The index (0-based) of the added column.
int32 addRow ( float  height = 0.0f) const

Appends a row at the bottom of the table.

Parameters
heightHeight of the row, or 0 to use the default row height.
Returns
The index (0-based) of the added row.
std::shared_ptr<GridCell> getCell ( int32  row,
int32  column 
) const

Returns the cell at a given position of the table or nullptr.

int32 getColumnAt ( float  x) const

Returns the index of the column displayed at a given position or NO_COLUMN.

int32 getColumnCount ( ) const
inline

Returns the number of columns.

std::shared_ptr<Button> getColumnHeader ( int32  index) const

Returns the header of a column or nullptr for an invalid index.

const auto& getColumns ( ) const
inline

Returns the columns in display order.

std::shared_ptr< T > getColumnTitle ( int32  index) const

Returns the widget displayed by the header of a column or nullptr for an invalid index.

float getColumnWidth ( int32  index) const

Returns the width currently used by a column.

auto getDefaultRowHeight ( ) const
inline

Returns the height given to the rows added without an explicit height.

const auto& getGrid ( ) const
inline

Returns the grid displaying the content of the table.

auto getGripWidth ( ) const
inline

Returns the width of the area used to drag the border between two columns.

const auto& getHeader ( ) const
inline

Returns the widget holding the headers of the columns.

auto getHeaderHeight ( ) const
inline

Returns the height of the row of headers.

int32 getRowCount ( ) const

Returns the number of rows.

float getRowHeight ( int32  index) const

Returns the height requested for a row.

auto getSortedColumn ( ) const
inline

Returns the index of the sorted column or NO_COLUMN.

auto getSortOrder ( ) const
inline

Returns the direction of the sort of the sorted column.

void insertRow ( int32  index,
float  height = 0.0f 
) const

Inserts a row, the rows below being shifted down.

Parameters
indexIndex of the inserted row, clamped to the number of rows.
heightHeight of the row, or 0 to use the default row height.
bool isColumnResizable ( int32  index) const

Returns true if the width of a column can be changed with the mouse.

bool isColumnSortable ( int32  index) const

Returns true if clicking the header of a column sorts the table.

void onDetach ( )
overridevirtual

Event called before Widget is detached from its parent.

Reimplemented from lysa::ui::Widget::onDetach()

void onHide ( )
overridevirtual

Event called when (after) the Window manager need to hide the Window.

Reimplemented from lysa::ui::Widget::onHide()

void onResize ( )
overridevirtual

Event called after a size change.

Reimplemented from lysa::ui::Widget::onResize()

void removeAllColumns ( )

Removes all the columns.

void removeAllRows ( ) const

Removes all the rows.

void removeColumn ( int32  index)

Removes a column.

void removeRow ( int32  index) const

Removes a row.

void setColumnResizable ( int32  index,
bool  resizable = true 
)

Sets whether the width of a column can be changed with the mouse.

void setColumnSortable ( int32  index,
bool  sortable = true 
)

Sets whether clicking the header of a column sorts the table.

void setColumnWidth ( int32  index,
float  width 
)

Sets the width of a column or Grid::AUTO_SIZE to share the remaining space.

void setDefaultRowHeight ( const float  height)
inline

Sets the height given to the rows added without an explicit height.

void setGripWidth ( float  width)

Sets the width of the area used to drag the border between two columns.

void setHeaderHeight ( float  height)

Sets the height of the row of headers or 0 to compute it from the height of the titles.

void setResources ( const std::string &  resHeader,
const std::string &  resGrid,
const std::string &  resArrow 
)

Sets the UI resources of the widgets created by the table.

Parameters
resHeaderResource string of the header buttons.
resGridResource string of the Grid.
resArrowResource string of the sort direction indicators.
void setRowHeight ( int32  index,
float  height 
) const

Sets the height of a row or Grid::AUTO_SIZE to share the remaining space.

void sort ( int32  column,
SortOrder  order 
)

Changes the sorted column and the sort direction.

The rows are not reordered, use sortRows() or one of the reordering methods of the Grid for that.

Parameters
columnColumn to sort, or NO_COLUMN to remove the sort.
orderDirection of the sort.
void sortRows ( int32  column,
const std::function< bool (const GridCell &, const GridCell &)> &  comparator 
) const

Reorders the rows by comparing the cells of a column.

The comparator is called with the two cells to compare must return true if the first one must be displayed above the second one when the table is sorted in the SortOrder::ASCENDING direction.

Does nothing if a cell of the grid spans several rows.

Member Data Documentation

constexpr float DEFAULT_GRIP_WIDTH {6.0f}
staticconstexpr

Default width of the area used to drag the border between two columns.

constexpr float DEFAULT_HEADER_HEIGHT {20.0f}
staticconstexpr

Default height of the row of headers.

constexpr float DEFAULT_ROW_HEIGHT {20.0f}
staticconstexpr

Default height of a row of the grid.

constexpr float MIN_COLUMN_WIDTH {8.0f}
staticconstexpr

Smallest width a column can be resized to.

constexpr int32 NO_COLUMN {-1}
staticconstexpr

No column is sortedn.