26#ifndef TGUI_LIST_BOX_HPP
27#define TGUI_LIST_BOX_HPP
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Widgets/Scrollbar.hpp>
32#include <TGUI/Renderers/ListBoxRenderer.hpp>
33#include <TGUI/Text.hpp>
46 typedef std::shared_ptr<ListBox>
Ptr;
47 typedef std::shared_ptr<const ListBox>
ConstPtr;
68 ListBox(
const char* typeName =
"ListBox",
bool initRenderer =
true);
114 using Widget::setPosition;
124 using Widget::setSize;
420 template <
typename T>
423 if (index < m_items.size())
424 return AnyCast<T>(m_items[index].data);
426 throw std::bad_cast();
568 void leftMousePressed(
Vector2f pos)
override;
573 void leftMouseReleased(
Vector2f pos)
override;
578 void mouseMoved(
Vector2f pos)
override;
583 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
588 void mouseNoLongerOnWidget()
override;
593 void leftMouseButtonNoLongerDown()
override;
638 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
644 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
656 void updateSelectedAndHoveringItemColorsAndStyle();
662 void updateItemColorsAndStyle();
668 void updateHoveringItem(
int item);
674 void updateSelectedItem(
int item);
680 void triggerOnScroll();
686 bool updateTime(
Duration elapsedTime)
override;
694 return std::make_shared<ListBox>(*
this);
718 std::vector<Item> m_items;
722 int m_selectedItem = -1;
724 int m_hoveringItem = -1;
727 unsigned int m_itemHeight = 0;
728 unsigned int m_requestedTextSize = 0;
731 std::size_t m_maxItems = 0;
735 unsigned int m_lastScrollbarValue = 0;
738 bool m_possibleDoubleClick =
false;
740 bool m_autoScroll =
true;
743 Sprite m_spriteBackground;
748 Color m_borderColorCached;
749 Color m_backgroundColorCached;
750 Color m_backgroundColorHoverCached;
751 Color m_selectedBackgroundColorCached;
752 Color m_selectedBackgroundColorHoverCached;
753 Color m_textColorCached;
754 Color m_textColorHoverCached;
755 Color m_selectedTextColorCached;
756 Color m_selectedTextColorHoverCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:48
Wrapper for colors.
Definition Color.hpp:63
Definition CopiedSharedPtr.hpp:40
Wrapper for durations.
Definition Duration.hpp:52
Class to store the position or size of a widget.
Definition Layout.hpp:262
Definition ListBoxRenderer.hpp:37
List box widget.
Definition ListBox.hpp:43
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.
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.
void setTextSize(unsigned int textSize) override
Changes the text size of the items.
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition ListBox.hpp:46
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.
unsigned int getScrollbarValue() const
Returns the thumb position of the scrollbar.
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.
TextAlignment
The horizontal text alignment.
Definition ListBox.hpp:54
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.
std::shared_ptr< const ListBox > ConstPtr
Shared constant widget pointer.
Definition ListBox.hpp:47
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the list box can contain.
static ListBox::Ptr copy(ListBox::ConstPtr listBox)
Makes a copy of another list box.
void setTextAlignment(TextAlignment alignment)
Changes the horizontal text alignment.
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 draw(BackendRenderTargetBase &target, RenderStates states) const override
Draw the widget to a render target.
void removeAllItems()
Removes all items from the list.
TextAlignment getTextAlignment() const
Gets the current horizontal text alignment.
bool removeItemByIndex(std::size_t index)
Removes the item from the list box.
ListBoxRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
bool removeItemById(const String &id)
Removes the item that were added with the given id.
T getItemData(std::size_t index) const
Returns user data stored in the item.
Definition ListBox.hpp:421
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.
void setScrollbarValue(unsigned int value)
Changes the thumb position of the scrollbar.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition ListBox.hpp:692
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.
bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
int getSelectedItemIndex() const
Gets the index of the selected item.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
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.
void setPosition(const Layout2d &position) override
Sets the position of the widget.
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the list box.
ListBoxRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
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.
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:39
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:556
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:58
Wrapper class to store strings.
Definition String.hpp:79
Wrapper for text styles.
Definition TextStyle.hpp:58
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:36
KeyPressed event parameters.
Definition Event.hpp:167
Definition ListBox.hpp:712
States used for drawing.
Definition RenderStates.hpp:39