26#ifndef TGUI_LIST_VIEW_HPP
27#define TGUI_LIST_VIEW_HPP
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Widgets/Scrollbar.hpp>
32#include <TGUI/Renderers/ListViewRenderer.hpp>
33#include <TGUI/Text.hpp>
49 using Ptr = std::shared_ptr<ListView>;
50 using ConstPtr = std::shared_ptr<const ListView>;
52 static constexpr const char StaticWidgetType[] =
"ListView";
67 std::vector<Text> texts;
75 float designWidth = 0;
76 float maxItemWidth = 0;
89 ListView(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
130 using Widget::setSize;
273 std::size_t
addItem(
const std::vector<String>& item);
297 void insertItem(std::size_t index,
const std::vector<String>& item);
315 bool changeItem(std::size_t index,
const std::vector<String>& item);
421 template <
typename T>
424 if (index < m_items.size())
425 return AnyCast<T>(m_items[index].data);
427 throw std::bad_cast();
513 void sort(std::size_t index,
const std::function<
bool(
const String&,
const String&)>& cmp);
778 void leftMousePressed(
Vector2f pos)
override;
783 void leftMouseReleased(
Vector2f pos)
override;
788 void rightMousePressed(
Vector2f pos)
override;
793 void mouseMoved(
Vector2f pos)
override;
798 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
803 void mouseNoLongerOnWidget()
override;
808 void leftMouseButtonNoLongerDown()
override;
851 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
857 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
899 virtual void setItemColor(std::size_t index,
const Color& color);
905 float calculateAutoColumnWidth(
const Text& text);
911 void updateSelectedAndhoveredItemColors();
917 void updateItemColors();
923 void updateHeaderTextsColor();
929 void updateHoveredItem(
int item);
935 void updateSelectedItem(
int item);
941 void selectRangeFromEvent(std::size_t item);
948 bool updateLastColumnMaxItemWidth();
955 bool updateLastColumnMaxItemWidthWithNewItem(
const Item& item);
962 bool updateLastColumnMaxItemWidthWithModifiedItem(
const Item& modifiedItem,
float oldDesiredWidthInLastColumn);
968 void addSelectedItem(
int item);
974 void removeSelectedItem(std::size_t item);
980 void updateHoveredItemByMousePos(
Vector2f mousePos);
986 unsigned int getTotalSeparatorWidth()
const;
992 float getItemTotalWidth(
const Item& item, std::size_t columnIndex)
const;
999 int getColumnIndexBelowMouse(
float mouseLeft);
1008 bool findBorderBelowMouse(
Vector2f pos, std::size_t& columnIndex,
float& pixelOffset)
const;
1014 void updateScrollbars();
1019 void updateVerticalScrollbarMaximum();
1024 void updateHorizontalScrollbarMaximum();
1036 void drawColumn(
BackendRenderTarget& target,
RenderStates states, std::size_t firstItem, std::size_t lastItem, std::size_t column,
float columnWidth)
const;
1042 bool updateTime(
Duration elapsedTime)
override;
1069 std::vector<Column> m_columns;
1070 std::vector<Item> m_items;
1071 std::set<std::size_t> m_selectedItems;
1073 int m_hoveredItem = -1;
1074 int m_firstSelectedItemIndex = -1;
1075 int m_focusedItemIndex = -1;
1077 float m_requestedHeaderHeight = 0;
1078 unsigned int m_itemHeight = 0;
1079 unsigned int m_headerTextSize = 0;
1080 unsigned int m_headerSeparatorHeight = 0;
1081 unsigned int m_separatorWidth = 1;
1082 unsigned int m_gridLinesWidth = 1;
1083 unsigned int m_iconCount = 0;
1084 float m_maxIconWidth = 0;
1085 float m_maxItemWidth = 0;
1086 bool m_headerVisible =
true;
1087 bool m_showHorizontalGridLines =
false;
1088 bool m_showVerticalGridLines =
true;
1089 bool m_expandLastColumn =
false;
1090 bool m_multiSelect =
false;
1091 bool m_resizableColumns =
false;
1093 Cursor::Type m_currentListViewMouseCursor = Cursor::Type::Arrow;
1094 std::size_t m_resizingColumn = 0;
1095 float m_resizingColumnPixelOffset = 0;
1102 int m_mouseOnHeaderIndex = -1;
1103 int m_possibleDoubleClick =
false;
1104 bool m_autoScroll =
true;
1106 Sprite m_spriteHeaderBackground;
1107 Sprite m_spriteBackground;
1112 Color m_borderColorCached;
1113 Color m_separatorColorCached;
1114 Color m_gridLinesColorCached;
1115 Color m_headerTextColorCached;
1116 Color m_headerBackgroundColorCached;
1117 Color m_backgroundColorCached;
1118 Color m_backgroundColorHoverCached;
1119 Color m_selectedBackgroundColorCached;
1120 Color m_selectedBackgroundColorHoverCached;
1121 Color m_textColorCached;
1122 Color m_textColorHoverCached;
1123 Color m_selectedTextColorCached;
1124 Color m_selectedTextColorHoverCached;
Base class for render targets.
Definition: BackendRenderTarget.hpp:48
Wrapper for colors.
Definition: Color.hpp:63
Definition: CopiedSharedPtr.hpp:40
Type
List of available cursors.
Definition: Cursor.hpp:48
Wrapper for durations.
Definition: Duration.hpp:52
Class to store the position or size of a widget.
Definition: Layout.hpp:284
Definition: ListViewRenderer.hpp:37
List view widget.
Definition: ListView.hpp:46
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
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.
T getItemData(std::size_t index) const
Returns user data stored in the item.
Definition: ListView.hpp:422
std::size_t addColumn(const String &text, float width=0, ColumnAlignment alignment=ColumnAlignment::Left)
Adds a column.
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.
void removeAllItems()
Removes all items from the list.
void setColumnAlignment(std::size_t columnIndex, ColumnAlignment alignment)
Changes the text alignment within a column.
ColumnAlignment getColumnAlignment(std::size_t columnIndex) const
Returns the current text alignment within a 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 setResizableColumns(bool resizable)
Changes whether the user can resize the columns by dragging the border between columns.
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:49
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.
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 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.
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.
ColumnAlignment
The text alignment for all texts within a column.
Definition: ListView.hpp:59
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.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
ListViewRenderer * getSharedRenderer()
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.
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:50
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 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.
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.
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 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 setGridLinesWidth(unsigned int width)
Changes the width of the grid lines.
ListViewRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:58
Definition: Sprite.hpp:45
Wrapper class to store strings.
Definition: String.hpp:79
Definition: Texture.hpp:52
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition: Event.hpp:167
Definition: ListView.hpp:73
Definition: ListView.hpp:66
States used for drawing.
Definition: RenderStates.hpp:39