26#ifndef TGUI_COMBO_BOX_HPP
27#define TGUI_COMBO_BOX_HPP
30#include <TGUI/Widgets/ListBox.hpp>
31#include <TGUI/Renderers/ComboBoxRenderer.hpp>
54 typedef std::shared_ptr<ComboBox>
Ptr;
55 typedef std::shared_ptr<const ComboBox>
ConstPtr;
186 bool addItem(
const sf::String& itemName,
const sf::String&
id =
"");
364 bool changeItem(
const sf::String& originalValue,
const sf::String& newValue);
533 void setParent(
Container* parent)
override;
547 void leftMousePressed(
Vector2f pos)
override;
552 bool mouseWheelScrolled(
float delta,
Vector2f pos)
override;
562 void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
592 std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
598 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
610 void updateListBoxHeight();
636 return std::make_shared<ComboBox>(*
this);
651 std::size_t m_nrOfItemsToDisplay = 0;
659 int m_previousSelectedItemIndex = -1;
661 bool m_changeItemOnScroll =
false;
663 bool m_changeItemOnScroll =
true;
667 ExpandDirection m_expandDirection = ExpandDirection::Automatic;
669 ExpandDirection m_expandDirection = ExpandDirection::Down;
672 Sprite m_spriteBackground;
673 Sprite m_spriteBackgroundDisabled;
675 Sprite m_spriteArrowHover;
676 Sprite m_spriteArrowDisabled;
681 Color m_borderColorCached;
682 Color m_backgroundColorCached;
683 Color m_backgroundColorDisabledCached;
684 Color m_arrowColorCached;
685 Color m_arrowColorHoverCached;
686 Color m_arrowColorDisabledCached;
687 Color m_arrowBackgroundColorCached;
688 Color m_arrowBackgroundColorHoverCached;
689 Color m_arrowBackgroundColorDisabledCached;
690 Color m_textColorCached;
691 Color m_textColorDisabledCached;
Wrapper for colors.
Definition: Color.hpp:49
Definition: ComboBoxRenderer.hpp:37
Combo box widget.
Definition: ComboBox.hpp:41
bool contains(const sf::String &item) const
Returns whether the combo box contains the given item.
static ComboBox::Ptr create()
Creates a new combo box widget.
bool removeItem(const sf::String &itemName)
Removes the item from the list with the given name.
void setSize(const Layout2d &size) override
Changes the size of the combo box.
void draw(sf::RenderTarget &target, sf::RenderStates states) const override
Draw the widget to a render target.
std::size_t getItemCount() const
Returns the amount of items in the combo box.
bool removeItemById(const sf::String &id)
Removes the item that were added with the given id.
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the list.
ComboBoxRenderer * getSharedRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool getChangeItemOnScroll() const
Returns whether the mouse wheel can be used to change the selected item while the list is closed.
bool mouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
ExpandDirection
The side where the list will be displayed.
Definition: ComboBox.hpp:46
bool changeItemById(const sf::String &id, const sf::String &newValue)
Changes the name of an item with the given id to newValue.
void setTextSize(unsigned int textSize) override
Changes the text size of the items.
const sf::String & getDefaultText() const
Returns the default text of the combo box. This is the text drawn when no item is selected.
void setChangeItemOnScroll(bool changeOnScroll)
Changes whether the mouse wheel can be used to change the selected item while the list is closed.
bool containsId(const sf::String &id) const
Returns whether the combo box contains an item with the given id.
void setDefaultText(const sf::String &defaultText)
Changes the default text of the combo box. This is the text drawn when no item is selected.
std::vector< sf::String > getItems() const
Returns a copy of the items in the combo box.
std::shared_ptr< ComboBox > Ptr
Shared widget pointer.
Definition: ComboBox.hpp:54
sf::String getItemById(const sf::String &id) const
Returns the item name of the item with the given id.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ComboBox.hpp:634
int getSelectedItemIndex() const
Gets the index of the selected item.
void removeAllItems()
Removes all items from the list.
bool changeItemByIndex(std::size_t index, const sf::String &newValue)
Changes the name of an item at the given index to newValue.
void setExpandDirection(ExpandDirection direction)
Changes the side where the list is displayed.
void deselectItem()
Deselects the selected item.
sf::String getSelectedItemId() const
Gets the id of the selected item.
void setItemsToDisplay(std::size_t nrOfItemsInListToDisplay)
Changes the number of items that are displayed in the list.
const std::vector< sf::String > & getItemIds() const
Returns a copy of the item ids in the combo box.
unsigned int getTextSize() const override
Returns the text size of the items.
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.
std::size_t getMaximumItems() const
Returns the maximum items that the combo box can contain.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
ComboBoxRenderer * getRenderer()
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setEnabled(bool enabled) override
Enables or disables the widget.
bool addItem(const sf::String &itemName, const sf::String &id="")
Adds an item to the list, so that it can be selected later.
static ComboBox::Ptr copy(ComboBox::ConstPtr comboBox)
Makes a copy of another combo box.
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the combo box can contain.
std::size_t getItemsToDisplay() const
Returns the number of items that are displayed in the list.
std::shared_ptr< const ComboBox > ConstPtr
Shared constant widget pointer.
Definition: ComboBox.hpp:55
ExpandDirection getExpandDirection() const
Returns the side where the list is displayed.
void rendererChanged(const std::string &property) override
Function called when one of the properties of the renderer is changed.
sf::String getSelectedItem() const
Returns the currently selected item.
bool setSelectedItemById(const sf::String &id)
Selects an item from the list.
bool setSelectedItem(const sf::String &itemName)
Selects an item from the list.
bool removeItemByIndex(std::size_t index)
Removes the item from the list.
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.
Container widget.
Definition: Container.hpp:48
Class to store the position or size of a widget.
Definition: Layout.hpp:260
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition: ListBox.hpp:46
static ListBox::Ptr create()
Creates a new list box widget.
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
Definition: Vector2f.hpp:39
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:37