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;
126 bool addItem(
const sf::String& itemName,
const sf::String&
id =
"");
326 bool changeItem(
const sf::String& originalValue,
const sf::String& newValue);
509 void leftMousePressed(
Vector2f pos)
override;
514 void leftMouseReleased(
Vector2f pos)
override;
519 void mouseMoved(
Vector2f pos)
override;
524 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
529 void mouseNoLongerOnWidget()
override;
534 void leftMouseButtonNoLongerDown()
override;
544 void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
574 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
580 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
592 void updateSelectedAndHoveringItemColorsAndStyle();
598 void updateItemColorsAndStyle();
604 void updateHoveringItem(
int item);
610 void updateSelectedItem(
int item);
616 bool update(sf::Time elapsedTime)
override;
624 return std::make_shared<ListBox>(*
this);
641 std::vector<Text> m_items;
642 std::vector<sf::String> m_itemIds;
646 int m_selectedItem = -1;
648 int m_hoveringItem = -1;
651 unsigned int m_itemHeight = 0;
652 unsigned int m_requestedTextSize = 0;
655 std::size_t m_maxItems = 0;
661 bool m_possibleDoubleClick =
false;
663 bool m_autoScroll =
true;
665 Sprite m_spriteBackground;
670 Color m_borderColorCached;
671 Color m_backgroundColorCached;
672 Color m_backgroundColorHoverCached;
673 Color m_selectedBackgroundColorCached;
674 Color m_selectedBackgroundColorHoverCached;
675 Color m_textColorCached;
676 Color m_textColorHoverCached;
677 Color m_selectedTextColorCached;
678 Color m_selectedTextColorHoverCached;
Wrapper for colors.
Definition: Color.hpp:49
Definition: CopiedSharedPtr.hpp:40
Class to store the position or size of a widget.
Definition: Layout.hpp:260
Definition: ListBoxRenderer.hpp:37
List box widget.
Definition: ListBox.hpp:43
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the list box.
const std::vector< sf::String > & getItemIds() const
Returns a copy of the item ids 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 changeItemById(const sf::String &id, const sf::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.
void deselectItem()
Deselects the selected item.
int getIndexById(const sf::String &id) const
Returns the index of the item with the given id.
bool addItem(const sf::String &itemName, const sf::String &id="")
Adds an item to the list.
std::shared_ptr< const ListBox > ConstPtr
Shared constant widget pointer.
Definition: ListBox.hpp:47
bool removeItem(const sf::String &itemName)
Removes the item from the list with the given name.
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the list box can contain.
bool containsId(const sf::String &id) const
Returns whether the list box contains an item with the given id.
bool setSelectedItem(const sf::String &itemName)
Selects an item in the list box.
static ListBox::Ptr copy(ListBox::ConstPtr listBox)
Makes a copy of another list box.
static ListBox::Ptr create()
Creates a new list box widget.
bool removeItemById(const sf::String &id)
Removes the item that were added with the given id.
void removeAllItems()
Removes all items from the list.
sf::String getItemByIndex(std::size_t index) const
Returns the item name of the item at the given index.
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.
bool contains(const sf::String &item) const
Returns whether the list box contains the given item.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
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:622
void setSize(const Layout2d &size) override
Changes the size of the list box.
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
std::vector< sf::String > getItems() const
Returns a copy of the items in the list box.
sf::String getIdByIndex(std::size_t index) const
Returns the id of the item at the given index.
bool getAutoScroll() const
Returns whether the list box scrolls to the bottom when a new item is added.
bool setSelectedItemById(const sf::String &id)
Selects an item in the list box.
sf::String getItemById(const sf::String &id) const
Returns the item name of the item with the given id.
int getSelectedItemIndex() const
Gets the index of the selected item.
sf::String getSelectedItem() const
Returns the currently selected item.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
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.
bool changeItemByIndex(std::size_t index, const sf::String &newValue)
Changes the name of an item at the given index to newValue.
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.
sf::String getSelectedItemId() const
Gets the id of the selected item.
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.
Signal & getSignal(std::string signalName) override
Retrieves a signal based on its name.
bool changeItem(const sf::String &originalValue, const sf::String &newValue)
Changes an item with name originalValue to newValue.
Definition: Outline.hpp:39
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:575
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:231
Definition: Sprite.hpp:46
Wrapper for text styles.
Definition: TextStyle.hpp:47
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37