TGUI 1.12
Loading...
Searching...
No Matches
ListView.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2026 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_LIST_VIEW_HPP
26#define TGUI_LIST_VIEW_HPP
27
28#include <TGUI/Widgets/Scrollbar.hpp>
29#include <TGUI/Renderers/ListViewRenderer.hpp>
30#include <TGUI/Text.hpp>
31
32#include <set>
33#include <limits>
34
36
37namespace tgui
38{
44 class TGUI_API ListView : public Widget, public DualScrollbarChildInterface
45 {
46 public:
47
48 using Ptr = std::shared_ptr<ListView>;
49 using ConstPtr = std::shared_ptr<const ListView>;
50
51 static constexpr const char StaticWidgetType[] = "ListView";
52
56 using ColumnAlignment TGUI_DEPRECATED("Use tgui::HorizontalAlignment instead") = HorizontalAlignment;
57
58 struct Item
59 {
60 std::vector<Text> texts;
61 Any data;
62 Sprite icon;
63 };
64
65 struct Column
66 {
67 float width = 0;
68 float designWidth = 0;
69 float widestItemWidth = 0;
70 std::size_t widestItemIndex = std::numeric_limits<std::size_t>::max();
71 Text text;
73 bool autoResize = false;
74 bool expanded = false;
75 };
76
84 explicit ListView(const char* typeName = StaticWidgetType, bool initRenderer = true);
85
90 TGUI_NODISCARD static ListView::Ptr create();
91
99 TGUI_NODISCARD static ListView::Ptr copy(const ListView::ConstPtr& listView);
100
105 TGUI_NODISCARD ListViewRenderer* getSharedRenderer() override;
106 TGUI_NODISCARD const ListViewRenderer* getSharedRenderer() const override;
107
113 TGUI_NODISCARD ListViewRenderer* getRenderer() override;
114
120 void setSize(const Layout2d& size) override;
121 using Widget::setSize;
122
132 std::size_t addColumn(const String& text, float width = 0, HorizontalAlignment alignment = HorizontalAlignment::Left);
133
140 void setColumnText(std::size_t index, const String& text);
141
149 TGUI_NODISCARD String getColumnText(std::size_t index) const;
150
157 void setColumnWidth(std::size_t index, float width);
158
171 TGUI_NODISCARD float getColumnWidth(std::size_t index) const;
172
184 TGUI_NODISCARD float getColumnDesignWidth(std::size_t index) const;
185
192 void setColumnAlignment(std::size_t columnIndex, HorizontalAlignment alignment);
193
201 TGUI_NODISCARD HorizontalAlignment getColumnAlignment(std::size_t columnIndex) const;
202
217 void setColumnAutoResize(std::size_t index, bool autoResize);
218
228 TGUI_NODISCARD bool getColumnAutoResize(std::size_t index) const;
229
246 void setColumnExpanded(std::size_t index, bool expand);
247
257 TGUI_NODISCARD bool getColumnExpanded(std::size_t index) const;
258
263
269 TGUI_NODISCARD std::size_t getColumnCount() const;
270
276 void setHeaderHeight(float height);
277
283 TGUI_NODISCARD float getHeaderHeight() const;
284
290 TGUI_NODISCARD float getCurrentHeaderHeight() const;
291
297 void setHeaderVisible(bool showHeader);
298
304 TGUI_NODISCARD bool getHeaderVisible() const;
305
316 std::size_t addItem(const String& text);
317
330 std::size_t addItem(const std::vector<String>& item);
331
337 void addMultipleItems(const std::vector<std::vector<String>>& items);
338
345 void insertItem(std::size_t index, const String& text);
346
353 void insertItem(std::size_t index, const std::vector<String>& item);
354
361 void insertMultipleItems(std::size_t index, const std::vector<std::vector<String>>& items);
362
371 bool changeItem(std::size_t index, const std::vector<String>& item);
372
382 bool changeSubItem(std::size_t index, std::size_t column, const String& item);
383
391 bool removeItem(std::size_t index);
392
397
403 void setSelectedItem(std::size_t index);
404
410 void setSelectedItems(const std::set<std::size_t>& indices);
411
416
422 TGUI_NODISCARD int getSelectedItemIndex() const;
423
429 TGUI_NODISCARD int getHoveredItemIndex() const;
430
436 TGUI_NODISCARD std::set<std::size_t> getSelectedItemIndices() const;
437
443 void setMultiSelect(bool multiSelect);
444
450 TGUI_NODISCARD bool getMultiSelect() const;
451
464 void setItemData(std::size_t index, Any data);
465
472 template <typename DataType>
473 TGUI_NODISCARD DataType getItemData(std::size_t index) const
474 {
475 if (index < m_items.size())
476 return AnyCast<DataType>(m_items[index].data);
477 throw std::bad_cast();
478 }
479
486 void setItemIcon(std::size_t index, const Texture& texture);
487
495 TGUI_NODISCARD Texture getItemIcon(std::size_t index) const;
496
502 TGUI_NODISCARD std::size_t getItemCount() const;
503
511 TGUI_NODISCARD String getItem(std::size_t index) const;
512
522 TGUI_NODISCARD std::vector<String> getItemRow(std::size_t index) const;
523
532 TGUI_NODISCARD String getItemCell(std::size_t rowIndex, std::size_t columnIndex) const;
533
539 TGUI_NODISCARD std::vector<String> getItems() const;
540
546 TGUI_NODISCARD std::vector<std::vector<String>> getItemRows() const;
547
559 void sort(std::size_t index, const std::function<bool(const String&, const String&)>& cmp);
560
566 void setItemHeight(unsigned int itemHeight);
567
573 TGUI_NODISCARD unsigned int getItemHeight() const;
574
582 void setHeaderTextSize(unsigned int textSize);
583
589 TGUI_NODISCARD unsigned int getHeaderTextSize() const;
590
596 void setSeparatorWidth(unsigned int width);
597
603 TGUI_NODISCARD unsigned int getSeparatorWidth() const;
604
610 void setHeaderSeparatorHeight(unsigned int height);
611
617 TGUI_NODISCARD unsigned int getHeaderSeparatorHeight() const;
618
624 void setGridLinesWidth(unsigned int width);
625
631 TGUI_NODISCARD unsigned int getGridLinesWidth() const;
632
640 void setAutoScroll(bool autoScroll);
641
647 TGUI_NODISCARD bool getAutoScroll() const;
648
656 void setShowVerticalGridLines(bool showGridLines);
657
663 TGUI_NODISCARD bool getShowVerticalGridLines() const;
664
672 void setShowHorizontalGridLines(bool showGridLines);
673
679 TGUI_NODISCARD bool getShowHorizontalGridLines() const;
680
688 TGUI_DEPRECATED("Use setColumnAutoExpanded and setColumnAutoResize instead") void setExpandLastColumn(bool expand);
689
697 TGUI_DEPRECATED("Use ColumnAutoExpanded and ColumnAutoResize setters and getters instead") TGUI_NODISCARD bool getExpandLastColumn() const;
698
703 TGUI_DEPRECATED("Use getVerticalScrollbar()->setPolicy(policy) instead") void setVerticalScrollbarPolicy(Scrollbar::Policy policy);
704
709 TGUI_DEPRECATED("Use getVerticalScrollbar()->getPolicy() instead") TGUI_NODISCARD Scrollbar::Policy getVerticalScrollbarPolicy() const;
710
715 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setPolicy(policy) instead") void setHorizontalScrollbarPolicy(Scrollbar::Policy policy);
716
721 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getPolicy() instead") TGUI_NODISCARD Scrollbar::Policy getHorizontalScrollbarPolicy() const;
722
728 TGUI_DEPRECATED("Use getVerticalScrollbar()->setValue(value) instead") void setVerticalScrollbarValue(unsigned int value);
729
735 TGUI_DEPRECATED("Use getVerticalScrollbar()->getValue() instead") TGUI_NODISCARD unsigned int getVerticalScrollbarValue() const;
736
744 TGUI_DEPRECATED("Use getVerticalScrollbar()->getMaxValue() instead") TGUI_NODISCARD unsigned int getVerticalScrollbarMaxValue() const;
745
751 TGUI_DEPRECATED("Use getHorizontalScrollbar()->setValue(value) instead") void setHorizontalScrollbarValue(unsigned int value);
752
758 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getValue() instead") TGUI_NODISCARD unsigned int getHorizontalScrollbarValue() const;
759
767 TGUI_DEPRECATED("Use getHorizontalScrollbar()->getMaxValue() instead") TGUI_NODISCARD unsigned int getHorizontalScrollbarMaxValue() const;
768
777 void setFixedIconSize(Vector2f iconSize);
778
786 TGUI_NODISCARD Vector2f getFixedIconSize() const;
787
795 void setResizableColumns(bool resizable);
796
804 TGUI_NODISCARD bool getResizableColumns() const;
805
810 TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override;
811
815 bool leftMousePressed(Vector2f pos) override;
816
820 void leftMouseReleased(Vector2f pos) override;
821
825 void rightMousePressed(Vector2f pos) override;
826
830 void mouseMoved(Vector2f pos) override;
831
835 bool scrolled(float delta, Vector2f pos, bool touch) override;
836
840 void mouseNoLongerOnWidget() override;
841
845 void leftMouseButtonNoLongerDown() override;
846
850 void keyPressed(const Event::KeyEvent& event) override;
851
861 bool canHandleKeyPress(const Event::KeyEvent& event) override;
862
869 void draw(BackendRenderTarget& target, RenderStates states) const override;
870
872 protected:
873
883 TGUI_NODISCARD Signal& getSignal(String signalName) override;
884
890 void rendererChanged(const String& property) override;
891
895 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
896
900 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
901
905 void mouseEnteredWidget() override;
906
910 void mouseLeftWidget() override;
911
915 void updateTextSize() override;
916
923 void scrollbarPolicyChanged(Orientation orientation) override;
924
926 // Returns the size without the borders
928 TGUI_NODISCARD Vector2f getInnerSize() const;
929
931 // Create a Text object for an item from the given caption, using the preset color, font, text size and opacity
933 TGUI_NODISCARD Text createText(const String& caption);
934
936 // Create a Text object for a header text from the given caption, using the preset color, font, text size and opacity
938 TGUI_NODISCARD Text createHeaderText(const String& caption);
939
941 // Changes the color of all Text objects in an item
943 virtual void setItemColor(std::size_t index, const Color& color);
944
946 // Calculate the width of the column based on its caption when no column width was provided
948 TGUI_NODISCARD static float calculateAutoColumnWidth(const Text& text);
949
951 // Update the colors of the selected and hovered items
953 void updateSelectedAndhoveredItemColors();
954
956 // Update the color of all the items
958 void updateItemColors();
959
961 // Changes the color of all header texts
963 void updateHeaderTextsColor();
964
966 // Update on which item the mouse is standing
968 void updateHoveredItem(int item);
969
971 // Update which item is selected
973 void updateSelectedItem(int item);
974
976 // Selects multiple items when multi-select is on and the user selects an item while the shift key is held down
978 void selectRangeFromEvent(std::size_t item);
979
981 // Updates which item is the widest in the given column, by calculating the width of each item
983 bool updateWidestItemInColumn(std::size_t columnIndex);
984
986 // Updates which item is the widest in the given column, when only one item has changed in width
988 bool updateWidestItemInColumn(std::size_t columnIndex, std::size_t itemIndex);
989
991 // Updates which item is the widest in all columns, by calculating the width of each item
993 bool updateWidestItem();
994
996 // Updates which item is the widest in all columns, when only one item has changed in width
998 bool updateWidestItem(std::size_t itemIndex);
999
1001 // This function needs to be called when items are inserted into the list. If the widest item for each column is located
1002 // below the inserted item then it's index needs to be updated.
1004 void incrementWidestItemIndices(std::size_t itemIndex);
1005
1007 // Recalculates the width of each column if they don't have a fixed width. For auto-resized columns, the widest item
1008 // should have already been updated in each column before this function is called.
1010 void updateColumnWidths();
1011
1013 // Returns whether at least one column potentially has its width expanded to fill the list view
1015 bool hasExpandedColumn() const;
1016
1018 // Add item to selected set
1020 void addSelectedItem(int item);
1021
1023 // Remove item from selected set
1025 void removeSelectedItem(std::size_t item);
1026
1028 // Update on which item the mouse is standing, given the current mouse position
1030 void updateHoveredItemByMousePos(Vector2f mousePos);
1031
1033 // Returns either the configured separator width or the width of vertical grid lines, whichever is larger.
1035 TGUI_NODISCARD unsigned int getTotalSeparatorWidth() const;
1036
1038 // Returns the total width an Item takes up at some column, assuming it will not be cut off by the column.
1040 TGUI_NODISCARD float getItemTotalWidth(const Item& item, std::size_t columnIndex) const;
1041
1043 // Found out which column is located below the mouse. The mouseLeft is relative to the widget position.
1044 // This function should only be called after checking that the mouse is positioned on top of the header.
1046 TGUI_NODISCARD int getColumnIndexBelowMouse(float mouseLeft);
1047
1049 // Returns whether the mouse is standing between two columns.
1050 // If true then columnIndex is set to the index of border below the mouse (1 is the border between first two columns).
1051 // If false then columnIndex remains unchanged.
1053 TGUI_NODISCARD bool findBorderBelowMouse(Vector2f pos, std::size_t& columnIndex) const;
1054
1056 // Recalculate the size and viewport size of the scrollbars
1058 void updateScrollbars();
1059
1061 // Recalculate the maximum value for the vertical scrollbar
1063 void updateVerticalScrollbarMaximum();
1064
1066 // Draw the header text for a single column
1068 void drawHeaderText(BackendRenderTarget& target, RenderStates states, float columnWidth, float headerHeight, std::size_t column) const;
1069
1071 // Draw the texts in a single column
1073 void drawColumn(BackendRenderTarget& target, RenderStates states, std::size_t firstItem, std::size_t lastItem, std::size_t column, float columnWidth) const;
1074
1076 // This function is called every frame with the time passed since the last frame.
1078 bool updateTime(Duration elapsedTime) override;
1079
1081 // Makes a copy of the widget
1083 TGUI_NODISCARD Widget::Ptr clone() const override;
1084
1086 public:
1087
1093 SignalInt onItemSelect = {"ItemSelected"};
1094
1095 SignalInt onDoubleClick = {"DoubleClicked"};
1096 SignalInt onRightClick = {"RightClicked"};
1097 SignalInt onHeaderClick = {"HeaderClicked"};
1098
1100 protected:
1101
1102 std::vector<Column> m_columns;
1103 std::vector<Item> m_items;
1104 std::set<std::size_t> m_selectedItems;
1105
1106 int m_hoveredItem = -1;
1107 int m_firstSelectedItemIndex = -1;
1108 int m_focusedItemIndex = -1;
1109
1110 float m_requestedHeaderHeight = 0;
1111 unsigned int m_itemHeight = 0;
1112 unsigned int m_headerTextSize = 0;
1113 unsigned int m_headerSeparatorHeight = 0;
1114 unsigned int m_separatorWidth = 1;
1115 unsigned int m_gridLinesWidth = 1;
1116 unsigned int m_iconCount = 0;
1117 float m_maxIconWidth = 0;
1118 float m_widestItemWidth = 0; // If there are no columns, this is the maximum width from all items
1119 std::size_t m_widestItemIndex = std::numeric_limits<std::size_t>::max(); // If there are no columns, this is the index of the item with the maximum width
1120 bool m_headerVisible = true;
1121 bool m_showHorizontalGridLines = false;
1122 bool m_showVerticalGridLines = true;
1123 bool m_expandLastColumn = false; // TGUI_NEXT: Remove this property
1124 bool m_multiSelect = false;
1125 bool m_resizableColumns = false;
1126 Vector2f m_fixedIconSize;
1127 Cursor::Type m_currentListViewMouseCursor = Cursor::Type::Arrow;
1128 std::size_t m_resizingColumn = 0;
1129 float m_resizingColumnLastMouseX = 0;
1130
1131 int m_mouseOnHeaderIndex = -1; // If the left mouse is down, this contains the index of the column if the mouse went down on the header
1132 int m_possibleDoubleClick = false; // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
1133 bool m_autoScroll = true; // Should the list view scroll to the bottom when a new item is added?
1134
1135 Sprite m_spriteHeaderBackground;
1136 Sprite m_spriteBackground;
1137
1138 // Cached renderer properties
1139 Borders m_bordersCached;
1140 Borders m_paddingCached;
1141 Color m_borderColorCached;
1142 Color m_separatorColorCached;
1143 Color m_gridLinesColorCached;
1144 Color m_headerTextColorCached;
1145 Color m_headerBackgroundColorCached;
1146 Color m_backgroundColorCached;
1147 Color m_backgroundColorHoverCached;
1148 Color m_selectedBackgroundColorCached;
1149 Color m_selectedBackgroundColorHoverCached;
1150 Color m_textColorCached;
1151 Color m_textColorHoverCached;
1152 Color m_selectedTextColorCached;
1153 Color m_selectedTextColorHoverCached;
1154
1156 };
1157
1159}
1160
1162
1163#endif // TGUI_LIST_VIEW_HPP
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:71
Type
List of available cursors.
Definition Cursor.hpp:48
@ Arrow
Arrow cursor (default).
Definition Cursor.hpp:49
DualScrollbarChildInterface()
Default constructor.
Wrapper for durations.
Definition Duration.hpp:53
Class to store the position or size of a widget.
Definition Layout.hpp:321
Definition ListViewRenderer.hpp:35
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
bool scrolled(float delta, Vector2f pos, bool touch) override
Called by the parent on scroll event (either from mouse wheel of from two finger scrolling on a touch...
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer).
void setShowVerticalGridLines(bool showGridLines)
Changes whether lines are drawn between columns.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
Scrollbar::Policy getVerticalScrollbarPolicy() const
Returns when the vertical scrollbar should be displayed.
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.
unsigned int getVerticalScrollbarValue() const
Returns the thumb position of the vertical scrollbar.
void setHorizontalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the horizontal scrollbar should be displayed.
unsigned int getHorizontalScrollbarMaxValue() const
Returns the maximum thumb position of the horizontal scrollbar.
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.
HorizontalAlignment ColumnAlignment
The text alignment for all texts within a column.
Definition ListView.hpp:56
void setColumnWidth(std::size_t index, float width)
Changes the width of a column.
SignalInt onHeaderClick
The header was clicked. Optional parameter: column index.
Definition ListView.hpp:1097
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 setResizableColumns(bool resizable)
Changes whether the user can resize the columns by dragging the border between columns.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
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:48
unsigned int getHorizontalScrollbarValue() const
Returns the thumb position of the horizontal scrollbar.
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.
void setVerticalScrollbarValue(unsigned int value)
Changes the thumb position of the vertical scrollbar.
bool getExpandLastColumn() const
Returns whether the last column is expanded to fill the list view (if all columns fit inside 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.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
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.
Vector2f getFixedIconSize() const
Returns to which size all icons should be scaled.
void setHorizontalScrollbarValue(unsigned int value)
Changes the thumb position of the horizontal scrollbar.
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.
bool getResizableColumns() const
Returns whether the user can resize the columns by dragging the border between columns.
ListViewRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setVerticalScrollbarPolicy(Scrollbar::Policy policy)
Changes when the vertical scrollbar should be displayed.
void setFixedIconSize(Vector2f iconSize)
Sets a size to which all icons should be scaled.
SignalInt onItemSelect
Definition ListView.hpp:1093
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
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:473
void mouseEnteredWidget() override
This function is called when the mouse enters the widget.
static ListView::Ptr create()
Creates a new list view widget.
std::size_t getItemCount() const
Returns the amount of items in the list view.
static constexpr const char StaticWidgetType[]
Type name of the widget.
Definition ListView.hpp:51
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.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
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.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
std::shared_ptr< const ListView > ConstPtr
Shared constant widget pointer.
Definition ListView.hpp:49
void deselectItems()
Deselects the selected items.
void addMultipleItems(const std::vector< std::vector< String > > &items)
Adds multiple items to the list.
void setExpandLastColumn(bool expand)
Changes whether the last column is expanded to fill the list view (if all columns fit inside 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.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
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 scrollbarPolicyChanged(Orientation orientation) override
Called when the policy of one of the scrollbars has been changed calling either getVerticalScrollbar(...
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.
unsigned int getVerticalScrollbarMaxValue() const
Returns the maximum thumb position of the vertical scrollbar.
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.
Scrollbar::Policy getHorizontalScrollbarPolicy() const
Returns when the horizontal scrollbar should be displayed.
void setMultiSelect(bool multiSelect)
Allow multi selection of the items.
void removeAllColumns()
Removes all columns.
SignalInt onDoubleClick
An item was double clicked. Optional parameter: selected item index.
Definition ListView.hpp:1095
bool removeItem(std::size_t index)
Removes the item from the list view.
void mouseLeftWidget() override
This function is called when the mouse leaves the widget.
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.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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.
SignalInt onRightClick
Right mouse pressed. Optional parameter: index of item below mouse (-1 when not on top of item).
Definition ListView.hpp:1096
Scrollbar widget.
Definition Scrollbar.hpp:42
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Definition Sprite.hpp:45
Wrapper class to store strings.
Definition String.hpp:93
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:53
Texture wrapper that internally reuses resources when multiple Texture objects are loaded from the sa...
Definition Texture.hpp:52
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
SignalTyped< int > SignalInt
Signal with one "int" as optional unbound parameter.
Definition Signal.hpp:421
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:60
@ Left
Align to the left side.
Definition Layout.hpp:61
Orientation
Orientation of the object.
Definition Layout.hpp:50
Definition Event.hpp:38
Definition ListView.hpp:66
Definition ListView.hpp:59
States used for drawing.
Definition RenderStates.hpp:38