26#ifndef TGUI_COMBO_BOX_HPP
27#define TGUI_COMBO_BOX_HPP
30#include <TGUI/Widgets/Label.hpp>
31#include <TGUI/Widgets/ListBox.hpp>
37 class ComboBoxRenderer;
55 typedef std::shared_ptr<ComboBox>
Ptr;
56 typedef std::shared_ptr<const ComboBox>
ConstPtr;
113 return std::static_pointer_cast<ComboBoxRenderer>(m_renderer);
194 return m_nrOfItemsToDisplay;
214 bool addItem(
const sf::String& itemName,
const sf::String&
id =
"");
349 return m_listBox->getItemById(
id);
362 return m_listBox->getSelectedItem();
375 return m_listBox->getSelectedItemId();
387 return m_listBox->getSelectedItemIndex();
404 bool changeItem(
const sf::String& originalValue,
const sf::String& newValue);
445 return m_listBox->getItemCount();
591 virtual void setParent(
Container* parent)
override;
597 virtual bool mouseOnWidget(
float x,
float y)
const override;
602 virtual void leftMousePressed(
float x,
float y)
override;
607 virtual void mouseWheelMoved(
int delta,
int x,
int y)
override;
625 virtual void reload(
const std::string& primary =
"",
const std::string& secondary =
"",
bool force =
false)
override;
633 return std::make_shared<ComboBox>(*
this);
658 void newItemSelectedCallbackFunction();
664 void listBoxUnfocusedCallbackFunction();
670 virtual void draw(sf::RenderTarget& target, sf::RenderStates states)
const override;
678 std::size_t m_nrOfItemsToDisplay = 0;
716 virtual void setProperty(std::string property,
const std::string& value)
override;
952 void draw(sf::RenderTarget& target, sf::RenderStates states)
const;
961 Padding getScaledPadding()
const;
967 virtual std::shared_ptr<WidgetRenderer> clone(
Widget* widget)
override;
977 Texture m_textureArrowUpNormal;
979 Texture m_textureArrowDownNormal;
980 Texture m_textureArrowDownHover;
982 sf::Color m_textColor;
983 sf::Color m_arrowBackgroundColorNormal;
984 sf::Color m_arrowBackgroundColorHover;
985 sf::Color m_arrowColorNormal;
986 sf::Color m_arrowColorHover;
Definition: Borders.hpp:38
Implicit converter for colors.
Definition: Color.hpp:40
Definition: ComboBox.hpp:694
void setArrowBackgroundColor(const Color &color)
Set the background color of the arrow that will be used inside the combo box.
void setArrowUpHoverTexture(const Texture &texture)
Changes the arrow up image when the mouse is on top of the arrow.
virtual ObjectConverter getProperty(std::string property) const override
Retrieve the value of a certain property.
void setBackgroundTexture(const Texture &texture)
Changes the background image.
virtual void setProperty(std::string property, const std::string &value) override
Change a property of the renderer.
void setBackgroundColor(const Color &backgroundColor)
Set the background color that will be used inside the combo box.
virtual void setBorders(const Borders &borders) override
Changes the size of the borders.
virtual void setPadding(const Padding &padding) override
Changes the padding of the list box.
void setTextColor(const Color &textColor)
Set the text color that will be used inside the combo box.
void setArrowDownTexture(const Texture &texture)
Changes the arrow down image.
void setArrowBackgroundColorHover(const Color &color)
Set the background color of the arrow when the mouse is standing on top of the combo box.
std::shared_ptr< ListBoxRenderer > getListBox() const
Returns the renderer of the list box.
void setArrowColor(const Color &color)
Set the color of the arrow that will be used inside the combo box.
void setArrowColorNormal(const Color &color)
Set the color of the arrow when the mouse is not on top of the combo box.
void setBorderColor(const Color &borderColor)
Set the border color text that will be used inside the combo box.
virtual void setProperty(std::string property, ObjectConverter &&value) override
Change a property of the renderer.
void setArrowColorHover(const Color &color)
Set the color of the arrow when the mouse is standing on top of the combo box.
void setArrowUpTexture(const Texture &texture)
Changes the arrow up image.
ComboBoxRenderer(ComboBox *comboBox)
Constructor.
Definition: ComboBox.hpp:703
virtual std::map< std::string, ObjectConverter > getPropertyValuePairs() const override
Get a map with all properties and their values.
void setArrowBackgroundColorNormal(const Color &color)
Set the background color of the arrow when the mouse is not on top of the combo box.
void setArrowDownHoverTexture(const Texture &texture)
Changes the arrow down image when the mouse is on top of the arrow.
Combo box widget.
Definition: ComboBox.hpp:52
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.
virtual void reload(const std::string &primary="", const std::string &secondary="", bool force=false) override
Reload the widget.
void setSize(const Layout2d &size) override
Changes the size of the combo box.
void setTextSize(unsigned int textSize)
Changes the text size of the items.
const std::vector< sf::String > & getItemIds()
Return a copy of the item ids in the combo box.
ComboBox(const ComboBox ©)
Copy constructor.
std::vector< sf::String > getItems()
Return a copy of the items in the combo box.
unsigned int getTextSize() const
Returns the text size of the items.
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.
virtual sf::Vector2f getWidgetOffset() const override
Returns the distance between the position where the widget is drawn and where the widget is placed.
void setListBox(ListBox::Ptr listBox)
Change the internal list box.
bool changeItemById(const sf::String &id, const sf::String &newValue)
Changes the name of an item with the given id to newValue.
virtual void setPosition(const Layout2d &position) override
Set the position of the widget.
std::shared_ptr< ComboBox > Ptr
Shared widget pointer.
Definition: ComboBox.hpp:55
sf::String getItemById(const sf::String &id) const
Returns the item name of the item with the given id.
Definition: ComboBox.hpp:347
int getSelectedItemIndex() const
Get the index of the selected item.
Definition: ComboBox.hpp:385
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 deselectItem()
Deselects the selected item.
sf::String getSelectedItemId() const
Get the id of the selected item.
Definition: ComboBox.hpp:373
void setItemsToDisplay(std::size_t nrOfItemsInListToDisplay)
Changes the number of items that are displayed in the list.
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.
virtual void setFont(const Font &font) override
Changes the font of the text in the widget.
Scrollbar::Ptr getScrollbar() const
Access the scrollbar.
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.
Definition: ComboBox.hpp:192
virtual sf::Vector2f getFullSize() const override
Returns the full size of the combo box.
ListBox::Ptr getListBox() const
Returns the internal list box.
std::size_t getItemCount()
Returns the amount of items in the combo box.
Definition: ComboBox.hpp:443
virtual Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
Definition: ComboBox.hpp:631
std::shared_ptr< const ComboBox > ConstPtr
Shared constant widget pointer.
Definition: ComboBox.hpp:56
sf::String getSelectedItem() const
Returns the currently selected item.
Definition: ComboBox.hpp:360
bool setSelectedItemById(const sf::String &id)
Selects an item from the list.
bool setSelectedItem(const sf::String &itemName)
Selects an item from the list.
void setScrollbar(Scrollbar::Ptr scrollbar)
Changes the scrollbar.
virtual void setOpacity(float opacity) override
Changes the opacity of the widget.
std::shared_ptr< ComboBoxRenderer > getRenderer() const
Returns the renderer, which gives access to functions that determine how the widget is displayed.
Definition: ComboBox.hpp:111
bool removeItemByIndex(std::size_t index)
Removes the item from the list.
Container widget.
Definition: Container.hpp:48
Label widget.
Definition: Label.hpp:50
Class to store the position or size of a widget.
Definition: Layout.hpp:255
std::shared_ptr< ListBox > Ptr
Shared widget pointer.
Definition: ListBox.hpp:70
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