25#ifndef TGUI_LIST_BOX_HPP
26#define TGUI_LIST_BOX_HPP
28#include <TGUI/Widgets/Scrollbar.hpp>
29#include <TGUI/Renderers/ListBoxRenderer.hpp>
30#include <TGUI/Text.hpp>
34TGUI_MODULE_EXPORT
namespace tgui
43 using Ptr = std::shared_ptr<ListBox>;
44 using ConstPtr = std::shared_ptr<const ListBox>;
46 static constexpr const char StaticWidgetType[] =
"ListBox";
60 ListBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
83 TGUI_NODISCARD
const ListBoxRenderer* getSharedRenderer()
const override;
98 using Widget::setSize;
339 TGUI_NODISCARD std::vector<String>
getItems()
const;
370 template <
typename DataType>
373 if (index < m_items.size())
374 return AnyCast<DataType>(m_items[index].data);
376 throw std::bad_cast();
467 TGUI_DEPRECATED(
"Use getScrollbar()->setValue(value) instead") void setScrollbarValue(
unsigned int value);
474 TGUI_DEPRECATED("Use getScrollbar()->getValue() instead") TGUI_NODISCARD
unsigned int getScrollbarValue() const;
483 TGUI_DEPRECATED("Use getScrollbar()->getMaxValue() instead") TGUI_NODISCARD
unsigned int getScrollbarMaxValue() const;
490 TGUI_NODISCARD
bool isMouseOnWidget(
Vector2f pos) const override;
500 void leftMouseReleased(
Vector2f pos) override;
505 void mouseMoved(
Vector2f pos) override;
510 bool scrolled(
float delta,
Vector2f pos,
bool touch) override;
515 void mouseNoLongerOnWidget() override;
520 void leftMouseButtonNoLongerDown() override;
525 void keyPressed(const
Event::KeyEvent& event) override;
536 bool canHandleKeyPress(const
Event::KeyEvent& event) override;
565 void rendererChanged(const
String& property) override;
570 TGUI_NODISCARD std::unique_ptr<DataIO::Node> save(SavingRenderersMap& renderers) const override;
575 void load(const std::unique_ptr<DataIO::Node>& node, const LoadingRenderersMap& renderers) override;
580 void updateTextSize() override;
585 void scrollbarValueChanged() override;
590 TGUI_NODISCARD
Vector2f getInnerSize() const;
595 void updateItemPositions();
600 void updateSelectedAndHoveringItemColorsAndStyle();
605 void updateItemColorsAndStyle();
610 void updateHoveringItem(
int item);
615 void updateSelectedItem(
int item);
620 void triggerOnScroll();
625 void addItemImpl(const
String& itemName, const
String&
id);
630 bool updateTime(
Duration elapsedTime) override;
656 std::vector<Item> m_items;
660 int m_selectedItem = -1;
662 int m_hoveringItem = -1;
664 unsigned int m_itemHeight = 0;
667 std::size_t m_maxItems = 0;
670 unsigned int m_lastScrollbarValue = 0;
673 bool m_possibleDoubleClick =
false;
675 bool m_autoScroll =
true;
678 Sprite m_spriteBackground;
683 Color m_borderColorCached;
684 Color m_backgroundColorCached;
685 Color m_backgroundColorHoverCached;
686 Color m_selectedBackgroundColorCached;
687 Color m_selectedBackgroundColorHoverCached;
688 Color m_textColorCached;
689 Color m_textColorHoverCached;
690 Color m_selectedTextColorCached;
691 Color m_selectedTextColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Wrapper for durations.
Definition Duration.hpp:55
Class to store the position or size of a widget.
Definition Layout.hpp:323
Definition ListBoxRenderer.hpp:35
List box widget.
Definition ListBox.hpp:40
std::vector< String > getItemIds() const
Returns a copy of the item ids in the list box.
bool changeItem(const String &originalValue, const String &newValue)
Changes an item with name originalValue to newValue.
DataType getItemData(std::size_t index) const
Returns user data stored in the item.
Definition ListBox.hpp:371
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the list box.
std::size_t getItemCount() const
Returns the amount of items in the list box.
bool changeItemByIndex(std::size_t index, const String &newValue)
Changes the name of an item at the given index to newValue.
bool changeItemById(const String &id, const String &newValue)
Changes the name of an item with the given id to newValue.
void setTextAlignment(HorizontalAlignment alignment)
Changes the horizontal text alignment.
unsigned int getItemHeight() const
Returns the height of the items in the list box.
std::vector< String > getItems() const
Returns a copy of the items in the list box.
HorizontalAlignment getTextAlignment() const
Gets the current horizontal text alignment.
static ListBox::Ptr copy(const ListBox::ConstPtr &listBox)
Makes a copy of another list box.
void addMultipleItems(const std::vector< String > &itemNames)
Adds multiple items to the list.
ListBoxRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setItemData(std::size_t index, Any data)
Store some user data with the item.
String getItemById(const String &id) const
Returns the item name of the item with the given id.
void deselectItem()
Deselects the selected item.
ListBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
std::shared_ptr< const ListBox > ConstPtr
Shared constant widget pointer.
Definition ListBox.hpp:44
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the list box can contain.
int getHoveredItemIndex() const
Gets the index of the item below the mouse cursor.
String getSelectedItemId() const
Gets the id of the selected item.
static ListBox::Ptr create()
Creates a new list box widget.
bool contains(const String &item) const
Returns whether the list box contains the given item.
void removeAllItems()
Removes all items from the list.
bool removeItemByIndex(std::size_t index)
Removes the item from the list box.
bool removeItemById(const String &id)
Removes the item that were added with the given id.
String getIdByIndex(std::size_t index) const
Returns the id of the item at the given index.
bool setSelectedItemById(const String &id)
Selects an item in the list box.
bool setSelectedItem(const String &itemName)
Selects an item in the list box.
bool removeItem(const String &itemName)
Removes the item from the list with the given name.
void setSize(const Layout2d &size) override
Changes the size of the list box.
bool containsId(const String &id) const
Returns whether the list box contains an item with the given id.
String getItemByIndex(std::size_t index) const
Returns the item name of the item at the given index.
std::size_t addItem(const String &itemName, const String &id="")
Adds an item to the list.
bool getAutoScroll() const
Returns whether the list box scrolls to the bottom when a new item is added.
int getSelectedItemIndex() const
Gets the index of the selected item.
void setAutoScroll(bool autoScroll)
Changes whether the list box scrolls to the bottom when a new item is added.
std::size_t getMaximumItems() const
Returns the maximum items that the list box can contain.
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition ListBox.hpp:43
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the list box.
int getIndexById(const String &id) const
Returns the index of the item with the given id.
String getSelectedItem() const
Returns the currently selected item.
Definition Outline.hpp:38
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:522
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:61
Wrapper class to store strings.
Definition String.hpp:96
Wrapper for text styles.
Definition TextStyle.hpp:55
Backend-independent wrapper around the backend-specific text class.
Definition Text.hpp:48
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
HorizontalAlignment
The horizontal alignment.
Definition Layout.hpp:62
Definition ListBox.hpp:650
States used for drawing.
Definition RenderStates.hpp:38