25#ifndef TGUI_LIST_VIEW_HPP
26#define TGUI_LIST_VIEW_HPP
28#include <TGUI/Widgets/Scrollbar.hpp>
29#include <TGUI/Renderers/ListViewRenderer.hpp>
30#include <TGUI/Text.hpp>
32#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
39TGUI_MODULE_EXPORT
namespace tgui
50 using Ptr = std::shared_ptr<ListView>;
51 using ConstPtr = std::shared_ptr<const ListView>;
53 static constexpr const char StaticWidgetType[] =
"ListView";
62 std::vector<Text> texts;
70 float designWidth = 0;
71 float widestItemWidth = 0;
72 std::size_t widestItemIndex = std::numeric_limits<std::size_t>::max();
75 bool autoResize =
false;
76 bool expanded =
false;
86 ListView(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
123 using Widget::setSize;
332 std::size_t
addItem(
const std::vector<String>& item);
355 void insertItem(std::size_t index,
const std::vector<String>& item);
373 bool changeItem(std::size_t index,
const std::vector<String>& item);
474 template <
typename DataType>
477 if (index < m_items.size())
478 return AnyCast<DataType>(m_items[index].data);
480 throw std::bad_cast();
525 TGUI_NODISCARD std::vector<String>
getItemRow(std::size_t index)
const;
542 TGUI_NODISCARD std::vector<String>
getItems()
const;
549 TGUI_NODISCARD std::vector<std::vector<String>>
getItemRows()
const;
562 void sort(std::size_t index,
const std::function<
bool(
const String&,
const String&)>& cmp);
691 TGUI_DEPRECATED(
"Use setColumnAutoExpanded and setColumnAutoResize instead") void setExpandLastColumn(
bool expand);
700 TGUI_DEPRECATED("Use ColumnAutoExpanded and ColumnAutoResize setters and getters instead") TGUI_NODISCARD
bool getExpandLastColumn() const;
706 TGUI_DEPRECATED("Use getVerticalScrollbar()->setPolicy(policy) instead")
void setVerticalScrollbarPolicy(
Scrollbar::Policy policy);
712 TGUI_DEPRECATED("Use getVerticalScrollbar()->getPolicy() instead") TGUI_NODISCARD
Scrollbar::Policy getVerticalScrollbarPolicy() const;
718 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setPolicy(policy) instead")
void setHorizontalScrollbarPolicy(
Scrollbar::Policy policy);
724 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getPolicy() instead") TGUI_NODISCARD
Scrollbar::Policy getHorizontalScrollbarPolicy() const;
731 TGUI_DEPRECATED("Use getVerticalScrollbar()->setValue(value) instead")
void setVerticalScrollbarValue(
unsigned int value);
738 TGUI_DEPRECATED("Use getVerticalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarValue() const;
747 TGUI_DEPRECATED("Use getVerticalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getVerticalScrollbarMaxValue() const;
754 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setValue(value) instead")
void setHorizontalScrollbarValue(
unsigned int value);
761 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarValue() const;
770 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getHorizontalScrollbarMaxValue() const;
798 void setResizableColumns(
bool resizable);
807 TGUI_NODISCARD
bool getResizableColumns() const;
813 TGUI_NODISCARD
bool isMouseOnWidget(
Vector2f pos) const override;
823 void leftMouseReleased(
Vector2f pos) override;
828 void rightMousePressed(
Vector2f pos) override;
833 void mouseMoved(
Vector2f pos) override;
838 bool scrolled(
float delta,
Vector2f pos,
bool touch) override;
843 void mouseNoLongerOnWidget() override;
848 void leftMouseButtonNoLongerDown() override;
853 void keyPressed(const
Event::KeyEvent& event) override;
864 bool canHandleKeyPress(const
Event::KeyEvent& event) override;
893 void rendererChanged(const
String& property) override;
898 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
903 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
908 void mouseEnteredWidget() override;
913 void mouseLeftWidget() override;
918 void updateTextSize() override;
931 TGUI_NODISCARD
Vector2f getInnerSize() const;
936 TGUI_NODISCARD
Text createText(const
String& caption);
941 TGUI_NODISCARD
Text createHeaderText(const
String& caption);
946 virtual
void setItemColor(std::
size_t index, const
Color& color);
951 TGUI_NODISCARD
float calculateAutoColumnWidth(const
Text& text);
956 void updateSelectedAndhoveredItemColors();
961 void updateItemColors();
966 void updateHeaderTextsColor();
971 void updateHoveredItem(
int item);
976 void updateSelectedItem(
int item);
981 void selectRangeFromEvent(std::
size_t item);
986 bool updateWidestItemInColumn(std::
size_t columnIndex);
991 bool updateWidestItemInColumn(std::
size_t columnIndex, std::
size_t itemIndex);
996 bool updateWidestItem();
1001 bool updateWidestItem(std::
size_t itemIndex);
1007 void incrementWidestItemIndices(std::
size_t itemIndex);
1013 void updateColumnWidths();
1018 bool hasExpandedColumn() const;
1023 void addSelectedItem(
int item);
1028 void removeSelectedItem(std::
size_t item);
1033 void updateHoveredItemByMousePos(
Vector2f mousePos);
1038 TGUI_NODISCARD
unsigned int getTotalSeparatorWidth() const;
1043 TGUI_NODISCARD
float getItemTotalWidth(const
Item& item, std::
size_t columnIndex) const;
1049 TGUI_NODISCARD
int getColumnIndexBelowMouse(
float mouseLeft);
1056 TGUI_NODISCARD
bool findBorderBelowMouse(
Vector2f pos, std::
size_t& columnIndex) const;
1061 void updateScrollbars();
1066 void updateVerticalScrollbarMaximum();
1076 void drawColumn(
BackendRenderTarget& target,
RenderStates states, std::
size_t firstItem, std::
size_t lastItem, std::
size_t column,
float columnWidth) const;
1081 bool updateTime(
Duration elapsedTime) override;
1105 std::vector<Column> m_columns;
1106 std::vector<Item> m_items;
1107 std::set<std::size_t> m_selectedItems;
1109 int m_hoveredItem = -1;
1110 int m_firstSelectedItemIndex = -1;
1111 int m_focusedItemIndex = -1;
1113 float m_requestedHeaderHeight = 0;
1114 unsigned int m_itemHeight = 0;
1115 unsigned int m_headerTextSize = 0;
1116 unsigned int m_headerSeparatorHeight = 0;
1117 unsigned int m_separatorWidth = 1;
1118 unsigned int m_gridLinesWidth = 1;
1119 unsigned int m_iconCount = 0;
1120 float m_maxIconWidth = 0;
1121 float m_widestItemWidth = 0;
1122 std::size_t m_widestItemIndex = std::numeric_limits<std::size_t>::max();
1123 bool m_headerVisible =
true;
1124 bool m_showHorizontalGridLines =
false;
1125 bool m_showVerticalGridLines =
true;
1126 bool m_expandLastColumn =
false;
1127 bool m_multiSelect =
false;
1128 bool m_resizableColumns =
false;
1130 Cursor::Type m_currentListViewMouseCursor = Cursor::Type::Arrow;
1131 std::size_t m_resizingColumn = 0;
1132 float m_resizingColumnLastMouseX = 0;
1134 int m_mouseOnHeaderIndex = -1;
1135 int m_possibleDoubleClick =
false;
1136 bool m_autoScroll =
true;
1138 Sprite m_spriteHeaderBackground;
1139 Sprite m_spriteBackground;
1144 Color m_borderColorCached;
1145 Color m_separatorColorCached;
1146 Color m_gridLinesColorCached;
1147 Color m_headerTextColorCached;
1148 Color m_headerBackgroundColorCached;
1149 Color m_backgroundColorCached;
1150 Color m_backgroundColorHoverCached;
1151 Color m_selectedBackgroundColorCached;
1152 Color m_selectedBackgroundColorHoverCached;
1153 Color m_textColorCached;
1154 Color m_textColorHoverCached;
1155 Color m_selectedTextColorCached;
1156 Color m_selectedTextColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Type
List of available cursors.
Definition Cursor.hpp:50
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition ListViewRenderer.hpp:35
List view widget.
Definition ListView.hpp:47
void setShowVerticalGridLines(bool showGridLines)
Changes whether lines are drawn between columns.
void setSelectedItems(const std::set< std::size_t > &indices)
Selects items in the list view.
bool getShowHorizontalGridLines() const
Returns whether lines are drawn between items.
String getColumnText(std::size_t index) const
Returns the text of a column.
void setHeaderTextSize(unsigned int textSize)
Changes the text size of the header caption.
bool changeItem(std::size_t index, const std::vector< String > &item)
Changes an item with values for multiple columns to the list.
void removeAllItems()
Removes all items from the list.
bool getColumnAutoResize(std::size_t index) const
Returns whether the column width depends on the widest item added to that column.
void setColumnWidth(std::size_t index, float width)
Changes the width of a column.
String getItem(std::size_t index) const
Retrieves an item in the list.
unsigned int getSeparatorWidth() const
Returns the width of the column separator.
void setSize(const Layout2d &size) override
Changes the size of the list view.
void setHeaderVisible(bool showHeader)
Changes whether the header is shown.
void insertItem(std::size_t index, const String &text)
Inserts an item into the list.
std::vector< String > getItemRow(std::size_t index) const
Retrieves the values of all columns for an item in the list.
void setColumnText(std::size_t index, const String &text)
Changes the text of a column.
std::shared_ptr< ListView > Ptr
Shared widget pointer.
Definition ListView.hpp:50
static ListView::Ptr copy(const ListView::ConstPtr &listView)
Makes a copy of another list view.
String getItemCell(std::size_t rowIndex, std::size_t columnIndex) const
Retrieves the value for a cell in the list.
float getHeaderHeight() const
Returns the height of the header row.
std::size_t getColumnCount() const
Returns the amount of columns in the list view.
unsigned int getGridLinesWidth() const
Returns the width of the grid lines.
void sort(std::size_t index, const std::function< bool(const String &, const String &)> &cmp)
Sort items.
std::size_t addColumn(const String &text, float width=0, HorizontalAlignment alignment=HorizontalAlignment::Left)
Adds a column.
void insertMultipleItems(std::size_t index, const std::vector< std::vector< String > > &items)
Inserts multiple items into the list.
bool getHeaderVisible() const
Returns whether the header is shown.
bool getColumnExpanded(std::size_t index) const
Returns whether the column is expanded to fill the list view (if all columns fit inside the list view...
bool changeSubItem(std::size_t index, std::size_t column, const String &item)
Changes the caption of a single value in the item.
int getSelectedItemIndex() const
Gets the index of the selected item.
std::size_t addItem(const String &text)
Adds an item to the list.
unsigned int getItemHeight() const
Returns the height of the items in the list view.
void insertItem(std::size_t index, const std::vector< String > &item)
Inserts an item into the list.
void setItemIcon(std::size_t index, const Texture &texture)
Sets a small icon in front of the item.
float getColumnWidth(std::size_t index) const
Returns the width of a column.
ListViewRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
float getColumnDesignWidth(std::size_t index) const
Returns the original width of a column (the value passed to addColumn or the last setColumnWidth call...
void setColumnAlignment(std::size_t columnIndex, HorizontalAlignment alignment)
Changes the text alignment within a column.
HorizontalAlignment getColumnAlignment(std::size_t columnIndex) const
Returns the current text alignment within a column.
DataType getItemData(std::size_t index) const
Returns user data stored in the item.
Definition ListView.hpp:475
static ListView::Ptr create()
Creates a new list view widget.
std::size_t getItemCount() const
Returns the amount of items in the list view.
int getHoveredItemIndex() const
Gets the index of the item below the mouse cursor.
ListViewRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool getAutoScroll() const
Returns whether the list view scrolls to the bottom when a new item is added.
void setHeaderHeight(float height)
Changes the height of the header row.
void setShowHorizontalGridLines(bool showGridLines)
Changes whether lines are drawn between items.
std::shared_ptr< const ListView > ConstPtr
Shared constant widget pointer.
Definition ListView.hpp:51
void deselectItems()
Deselects the selected items.
void addMultipleItems(const std::vector< std::vector< String > > &items)
Adds multiple items to the list.
void setAutoScroll(bool autoScroll)
Changes whether the list view scrolls to the bottom when a new item is added.
std::size_t addItem(const std::vector< String > &item)
Adds an item with values for multiple columns to the list.
std::vector< std::vector< String > > getItemRows() const
Returns a list of all column values for all items in the list view.
std::set< std::size_t > getSelectedItemIndices() const
Gets the indices of the selected items.
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the list view.
void setSelectedItem(std::size_t index)
Selects an item in the list view.
void setSeparatorWidth(unsigned int width)
Changes the width of the column separator.
bool getMultiSelect() const
Returns multi selection of the items is allowed.
void setHeaderSeparatorHeight(unsigned int height)
Changes the height of the separator between the header and the items.
void setItemData(std::size_t index, Any data)
Store some user data with the item.
std::vector< String > getItems() const
Returns a list of the texts in the first column for all items in the list view.
unsigned int getHeaderTextSize() const
Returns the text size of the header caption.
Texture getItemIcon(std::size_t index) const
Gets the icon displayed in front of the item.
void setMultiSelect(bool multiSelect)
Allow multi selection of the items.
void removeAllColumns()
Removes all columns.
bool removeItem(std::size_t index)
Removes the item from the list view.
float getCurrentHeaderHeight() const
Returns the height of the header or 0 if no header row is shown.
void setColumnAutoResize(std::size_t index, bool autoResize)
Changes whether the column width depends on the widest item added to that column.
bool getShowVerticalGridLines() const
Returns whether lines are drawn between items.
unsigned int getHeaderSeparatorHeight() const
Returns the height of the separator between the header and the items.
void setColumnExpanded(std::size_t index, bool expand)
Changes whether a column is expanded to fill the list view (if all columns fit inside the list view)
void setGridLinesWidth(unsigned int width)
Changes the width of the grid lines.
Definition Outline.hpp:38
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:57
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:62
Orientation
Orientation of the object.
Definition Layout.hpp:52
Definition ListView.hpp:68
Definition ListView.hpp:61
States used for drawing.
Definition RenderStates.hpp:38