26#ifndef TGUI_LIST_BOX_HPP
27#define TGUI_LIST_BOX_HPP
30#include <TGUI/Widgets/Scrollbar.hpp>
37 class ListBoxRenderer;
70 typedef std::shared_ptr<ListBox>
Ptr;
71 typedef std::shared_ptr<const ListBox>
ConstPtr;
128 return std::static_pointer_cast<ListBoxRenderer>(m_renderer);
194 bool addItem(
const sf::String& itemName,
const sf::String&
id =
"");
362 bool changeItem(
const sf::String& originalValue,
const sf::String& newValue);
403 return m_items.size();
571 virtual bool mouseOnWidget(
float x,
float y)
const override;
576 virtual void leftMousePressed(
float x,
float y)
override;
581 virtual void leftMouseReleased(
float x,
float y)
override;
586 virtual void mouseMoved(
float x,
float y)
override;
591 virtual void mouseWheelMoved(
int delta,
int x,
int y)
override;
596 virtual void mouseNoLongerOnWidget()
override;
601 virtual void mouseNoLongerDown()
override;
610 void updateItemColors();
625 virtual void reload(
const std::string& primary =
"",
const std::string& secondary =
"",
bool force =
false)
override;
633 return std::make_shared<ListBox>(*
this);
640 virtual void update(sf::Time elapsedTime)
override;
646 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
653 std::vector<Label> m_items;
654 std::vector<sf::String> m_itemIds;
658 int m_selectedItem = -1;
660 int m_hoveringItem = -1;
663 unsigned int m_itemHeight = 22;
664 unsigned int m_requestedTextSize = 0;
665 unsigned int m_textSize = 18;
668 std::size_t m_maxItems = 0;
674 bool m_possibleDoubleClick =
false;
676 bool m_autoScroll =
true;
711 virtual void setProperty(std::string property,
const std::string& value)
override;
854 void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
863 Padding getScaledPadding()
const;
869 virtual std::shared_ptr<WidgetRenderer> clone(
Widget* widget)
override;
879 sf::Color m_backgroundColor;
880 sf::Color m_textColor;
881 sf::Color m_hoverBackgroundColor;
882 sf::Color m_hoverTextColor;
883 sf::Color m_selectedBackgroundColor;
884 sf::Color m_selectedTextColor;
885 sf::Color m_borderColor;
Definition: Borders.hpp:38
Implicit converter for colors.
Definition: Color.hpp:40
Definition: ComboBox.hpp:694
Combo box widget.
Definition: ComboBox.hpp:52
Class to store the position or size of a widget.
Definition: Layout.hpp:255
Definition: ListBox.hpp:689
void setTextColorNormal(const Color &color)
Changes the color of the text in the normal state (mouse not on top of the item).
void setSelectedBackgroundColor(const Color &selectedBackgroundColor)
Set the background color of the selected text that will be used inside the list box.
void setHoverBackgroundColor(const Color &hoverBackgroundColor)
Set the background color of the unselected item on which the mouse is standing.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setTextColorHover(const Color &color)
Changes the color of the text in the hover state (mouse is standing on top of the item).
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
ListBoxRenderer(ListBox *listBox)
Constructor.
Definition: ListBox.hpp:698
void setTextColor(const Color &textColor)
Set the text color that will be used inside the list box.
void setBackgroundTexture(const Texture &texture)
Changes the background image.
void setBackgroundColor(const Color &backgroundColor)
Set the background color that will be used inside the list box.
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setBorderColor(const Color &borderColor)
Set the border color text that will be used inside the list box.
virtual void setPadding(const Padding &padding) override
Changes the padding of the list box.
void setSelectedTextColor(const Color &selectedTextColor)
Set the text color of the selected text that will be used inside the list box.
List box widget.
Definition: ListBox.hpp:67
void setTextSize(unsigned int textSize)
Changes the text size of the items.
void setItemHeight(unsigned int itemHeight)
Changes the height of the items in the list box.
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition: ListBox.hpp:70
bool changeItemById(const sf::String &id, const sf::String &newValue)
Changes the name of an item with the given id to newValue.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
unsigned int getItemHeight() const
Returns the height of the items in the list box.
Scrollbar::Ptr getScrollbar() const
Access the scrollbar of the list box.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
void deselectItem()
Deselects the selected item.
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:71
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.
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ListBox.hpp:631
bool setSelectedItem(const sf::String &itemName)
Selects an item in the list box.
virtual sf::Vector2f getFullSize() const override
Returns the full size of 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.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the 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.
const std::vector< sf::String > & getItemIds()
Return a copy of the item ids in the list box.
bool removeItemByIndex(std::size_t index)
Removes the item from the list box.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
std::shared_ptr< ListBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: ListBox.hpp:126
void setSize(const Layout2d &size) override
Changes the size of the list box.
std::size_t getItemCount()
Returns the amount of items in the list box.
Definition: ListBox.hpp:401
ListBox(const ListBox ©)
Copy constructor.
bool getAutoScroll() const
Returns the maximum items that the list box can contain.
Definition: ListBox.hpp:542
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
Get the index of the selected item.
sf::String getSelectedItem() const
Returns the currently 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.
Definition: ListBox.hpp:518
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
bool changeItemByIndex(std::size_t index, const sf::String &newValue)
Changes the name of an item at the given index to newValue.
void setScrollbar(Scrollbar::Ptr scrollbar)
Changes the scrollbar of the list box.
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the list box.
sf::String getSelectedItemId() const
Get the id of the selected item.
unsigned int getTextSize() const
Returns the text size of the items.
std::vector< sf::String > getItems()
Return a copy of the items in the list box.
bool changeItem(const sf::String &originalValue, const sf::String &newValue)
Changes an item with name originalValue to newValue.
Implicit converter for settable properties.
Definition: ObjectConverter.hpp:43
Definition: Texture.hpp:45
Namespace that contains all TGUI functions and classes.
Definition: Animation.hpp:34