25#ifndef TGUI_COMBO_BOX_HPP
26#define TGUI_COMBO_BOX_HPP
28#include <TGUI/Widgets/ListBox.hpp>
29#include <TGUI/Renderers/ComboBoxRenderer.hpp>
33TGUI_MODULE_EXPORT
namespace tgui
52 using Ptr = std::shared_ptr<ComboBox>;
53 using ConstPtr = std::shared_ptr<const ComboBox>;
55 static constexpr const char StaticWidgetType[] =
"ComboBox";
64 ComboBox(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
124 using Widget::setSize;
361 TGUI_NODISCARD std::vector<String>
getItems()
const;
396 template <
typename DataType>
399 return m_listBox->getItemData<DataType>(index);
477 void setParent(
Container* parent)
override;
528 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
533 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
543 TGUI_NODISCARD
Vector2f getInnerSize()
const;
548 void updateListBoxHeight();
580 std::size_t m_nrOfItemsToDisplay = 0;
588 int m_previousSelectedItemIndex = -1;
589 bool m_changeItemOnScroll =
false;
591 ExpandDirection m_expandDirection = ExpandDirection::Automatic;
593 Sprite m_spriteBackground;
594 Sprite m_spriteBackgroundDisabled;
596 Sprite m_spriteArrowHover;
597 Sprite m_spriteArrowDisabled;
602 Color m_borderColorCached;
603 Color m_backgroundColorCached;
604 Color m_backgroundColorDisabledCached;
605 Color m_arrowColorCached;
606 Color m_arrowColorHoverCached;
607 Color m_arrowColorDisabledCached;
608 Color m_arrowBackgroundColorCached;
609 Color m_arrowBackgroundColorHoverCached;
610 Color m_arrowBackgroundColorDisabledCached;
611 Color m_textColorCached;
612 Color m_textColorDisabledCached;
Base class for render targets.
Definition BackendRenderTarget.hpp:46
Wrapper for colors.
Definition Color.hpp:73
Definition ComboBoxRenderer.hpp:35
Combo box widget.
Definition ComboBox.hpp:39
TGUI_NODISCARD std::size_t getMaximumItems() const
Returns the maximum items that the combo box can contain.
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
void updateTextSize() override
Called when the text size is changed (either by setTextSize or via the renderer)
bool removeItemById(const String &id)
Removes the item that were added with the given id.
TGUI_NODISCARD std::size_t getItemsToDisplay() const
Returns the number of items that are displayed in the list.
void setSize(const Layout2d &size) override
Changes the size of the combo box.
void draw(BackendRenderTarget &target, RenderStates states) const override
Draw the widget to a render target.
TGUI_NODISCARD std::size_t getItemCount() const
Returns the amount of items in the combo box.
TGUI_NODISCARD bool contains(const String &item) const
Returns whether the combo box contains the given item.
bool setSelectedItemByIndex(std::size_t index)
Selects an item in the list.
TGUI_NODISCARD ComboBoxRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
TGUI_NODISCARD std::vector< String > getItems() const
Returns a copy of the items in the combo box.
TGUI_NODISCARD ExpandDirection getExpandDirection() const
Returns the side where the list is displayed.
TGUI_NODISCARD 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.
bool setSelectedItem(const String &itemName)
Selects an item from the list.
bool changeItemByIndex(std::size_t index, const String &newValue)
Changes the name of an item at the given index to newValue.
ExpandDirection
The side where the list will be displayed.
Definition ComboBox.hpp:44
void setDefaultText(const String &defaultText)
Changes the default text of the combo box. This is the text drawn when no item is selected.
bool changeItem(const String &originalValue, const String &newValue)
Changes an item with name originalValue to newValue.
void setChangeItemOnScroll(bool changeOnScroll)
Changes whether the mouse wheel can be used to change the selected item while the list is closed.
TGUI_NODISCARD bool containsId(const String &id) const
Returns whether the combo box contains an item with the given id.
TGUI_NODISCARD DataType getItemData(std::size_t index) const
Returns user data stored in the item.
Definition ComboBox.hpp:397
bool removeItem(const String &itemName)
Removes the item from the list with the given name.
std::shared_ptr< const ComboBox > ConstPtr
Shared constant widget pointer.
Definition ComboBox.hpp:53
static TGUI_NODISCARD ComboBox::Ptr create()
Creates a new combo box widget.
TGUI_NODISCARD bool getChangeItemOnScroll() const
Returns whether the mouse wheel can be used to change the selected item while the list is closed.
void removeAllItems()
Removes all items from the list.
void setExpandDirection(ExpandDirection direction)
Changes the side where the list is displayed.
TGUI_NODISCARD String getItemById(const String &id) const
Returns the item name of the item with the given id.
void deselectItem()
Deselects the selected item.
void setItemsToDisplay(std::size_t nrOfItemsInListToDisplay)
Changes the number of items that are displayed in the list.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD TGUI_NODISCARD ComboBoxRenderer * getRenderer() override
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.
std::size_t addItem(const String &itemName, const String &id="")
Adds an item to the list, so that it can be selected later.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
void setMaximumItems(std::size_t maximumItems=0)
Changes the maximum items that the combo box can contain.
bool leftMousePressed(Vector2f pos) override
Called by the parent when the left mouse button goes down on top of the widget.
TGUI_NODISCARD String getSelectedItemId() const
Gets the id of the selected item.
TGUI_NODISCARD String getSelectedItem() const
Returns the currently selected item.
bool setSelectedItemById(const String &id)
Selects an item from the list.
static TGUI_NODISCARD ComboBox::Ptr copy(const ComboBox::ConstPtr &comboBox)
Makes a copy of another combo box.
TGUI_NODISCARD bool isMouseOnWidget(Vector2f pos) const override
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget...
TGUI_NODISCARD int getSelectedItemIndex() const
Gets the index of the selected item.
bool scrolled(float delta, Vector2f pos, bool touch) override
Called by the parent on scroll event (either from mouse wheel of from two finger scrolling on a touch...
TGUI_NODISCARD const String & getDefaultText() const
Returns the default text of the combo box. This is the text drawn when no item is selected.
void setItemData(std::size_t index, Any data)
Store some user data with the item.
std::shared_ptr< ComboBox > Ptr
Shared widget pointer.
Definition ComboBox.hpp:52
TGUI_NODISCARD std::vector< String > getItemIds() const
Returns a copy of the item ids in the combo box.
bool removeItemByIndex(std::size_t index)
Removes the item from the list.
bool changeItemById(const String &id, const String &newValue)
Changes the name of an item with the given id to newValue.
Container widget.
Definition Container.hpp:48
Class to store the position or size of a widget.
Definition Layout.hpp:313
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition ListBox.hpp:43
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
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
States used for drawing.
Definition RenderStates.hpp:38