25#ifndef TGUI_PANEL_LIST_BOX_HPP
26#define TGUI_PANEL_LIST_BOX_HPP
28#include <TGUI/Widgets/ScrollablePanel.hpp>
29#include <TGUI/Renderers/PanelListBoxRenderer.hpp>
33TGUI_MODULE_EXPORT
namespace tgui
42 using Ptr = std::shared_ptr<PanelListBox>;
43 using ConstPtr = std::shared_ptr<const PanelListBox>;
45 static constexpr const char StaticWidgetType[] =
"PanelListBox";
54 PanelListBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
88 using ScrollablePanel::setSize;
311 TGUI_NODISCARD std::vector<Panel::Ptr>
getItems()
const;
357 void mouseMoved(
Vector2f pos)
override;
362 void mouseNoLongerOnWidget()
override;
393 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
398 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
403 void updateItemsPositions()
const;
408 void updateItemsSize()
const;
413 TGUI_NODISCARD
float getAllItemsHeight()
const;
425 void updateSelectedItem(
int item);
430 void updateHoveringItem(
int item);
435 void updateSelectedAndHoveringItemColorsAndStyle()
const;
447 void clearAllItemsStyle()
const;
467 std::vector<Item> m_items;
468 std::size_t m_maxItems = 0;
471 int m_selectedItem = -1;
472 int m_hoveringItem = -1;
475 Color m_itemsBackgroundColorCached;
476 Color m_itemsBackgroundColorHoverCached;
477 Color m_selectedItemsBackgroundColorCached;
478 Color m_selectedItemsBackgroundColorHoverCached;
Wrapper for colors.
Definition Color.hpp:73
Class to store the position or size of a widget.
Definition Layout.hpp:323
Class to store the left, top, width or height of a widget.
Definition Layout.hpp:102
Definition PanelListBoxRenderer.hpp:36
List of panels, which can be flexible changed.
Definition PanelListBox.hpp:40
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
bool removeItemById(const String &id)
Removes the item that were added with the given id.
bool setSelectedItemById(const String &id)
Selects an item in the panel list box.
PanelListBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< PanelListBox > Ptr
Shared widget pointer.
Definition PanelListBox.hpp:42
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
int getSelectedItemIndex() const
Gets the index of the selected item.
bool setSelectedItem(const Panel::Ptr &panelPtr)
Selects an item in the panel list box.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
Layout getItemsWidth() const
Returns the width of the items in the list box.
String getIdByIndex(std::size_t index) const
Returns the id of the item at the given index.
std::vector< String > getItemIds() const
Returns a vector of stored items ids.
Panel::Ptr addItem(const String &id={}, int index=-1)
Adds an item to the list.
Panel::Ptr getItemByIndex(std::size_t index) const
Returns the item name of the item at the given index.
bool containsId(const String &id) const
Returns whether the panel list box contains an item with the given id.
PanelListBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
static Ptr copy(const ConstPtr &panelListBox)
Makes a copy of another panel list box.
Panel::Ptr getPanelTemplate() const
Get panel template from which new elements are created.
Panel::Ptr getSelectedItem() const
Returns the currently selected item.
std::size_t getItemCount() const
Returns the amount of items in the panel list box.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
void setItemsHeight(const Layout &height)
Changes the height of the items in the list box.
std::size_t getMaximumItems() const
Returns the maximum items that the list box can contain.
Layout getItemsHeight() const
Returns the height of the items in the list box.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void clearItemStyle(int item) const
std::vector< Panel::Ptr > getItems() const
Returns a copy of the items in the list box.
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the list box can contain.
std::shared_ptr< const PanelListBox > ConstPtr
Shared constant widget pointer.
Definition PanelListBox.hpp:43
String getSelectedItemId() const
Gets the id of the selected item.
static Ptr create()
Creates a new panel list box widget.
float getItemsHeightUpToIndex(std::size_t index) const
void deselectItem()
Deselects the selected item.
Panel::Ptr getItemById(const String &id) const
Returns the item name of the item with the given id.
bool removeItem(const Panel::Ptr &panelPtr)
Removes the item from the panel list with the given pointer.
bool removeItemByIndex(std::size_t index)
Removes the item from the panel list box.
bool contains(const Panel::Ptr &panelPtr) const
Returns whether the panel list box contains the given item.
int getIndexByItem(const Panel::Ptr &panelPtr) const
Returns the index of the given item.
int getHoveredItemIndex() const
Gets the index of the item below the mouse cursor.
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.
void setSize(const Layout2d &size) override
Changes the size of the panel list box.
void removeAllItems()
Removes all items from the list.
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the panel list box.
int getIndexById(const String &id) const
Returns the index of the item with the given id.
std::shared_ptr< Panel > Ptr
Shared widget pointer.
Definition Panel.hpp:42
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:630
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
Definition PanelListBox.hpp:462