TGUI
0.8.9
|
Combo box widget. More...
#include <TGUI/Widgets/ComboBox.hpp>
Public Types | |
enum class | ExpandDirection { Down , Up , Automatic } |
The side where the list will be displayed. More... | |
typedef std::shared_ptr< ComboBox > | Ptr |
Shared widget pointer. | |
typedef std::shared_ptr< const ComboBox > | ConstPtr |
Shared constant widget pointer. | |
Public Types inherited from tgui::Widget | |
typedef std::shared_ptr< Widget > | Ptr |
Shared widget pointer. | |
typedef std::shared_ptr< const Widget > | ConstPtr |
Shared constant widget pointer. | |
Public Member Functions | |
ComboBoxRenderer * | getSharedRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
ComboBoxRenderer * | getRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
void | setSize (const Layout2d &size) override |
Changes the size of the combo box. More... | |
void | setEnabled (bool enabled) override |
Enables or disables the widget. More... | |
void | setItemsToDisplay (std::size_t nrOfItemsInListToDisplay) |
Changes the number of items that are displayed in the list. More... | |
std::size_t | getItemsToDisplay () const |
Returns the number of items that are displayed in the list. More... | |
bool | addItem (const sf::String &itemName, const sf::String &id="") |
Adds an item to the list, so that it can be selected later. More... | |
bool | setSelectedItem (const sf::String &itemName) |
Selects an item from the list. More... | |
bool | setSelectedItemById (const sf::String &id) |
Selects an item from the list. More... | |
bool | setSelectedItemByIndex (std::size_t index) |
Selects an item in the list. More... | |
void | deselectItem () |
Deselects the selected item. More... | |
bool | removeItem (const sf::String &itemName) |
Removes the item from the list with the given name. More... | |
bool | removeItemById (const sf::String &id) |
Removes the item that were added with the given id. More... | |
bool | removeItemByIndex (std::size_t index) |
Removes the item from the list. More... | |
void | removeAllItems () |
Removes all items from the list. | |
sf::String | getItemById (const sf::String &id) const |
Returns the item name of the item with the given id. More... | |
sf::String | getSelectedItem () const |
Returns the currently selected item. More... | |
sf::String | getSelectedItemId () const |
Gets the id of the selected item. More... | |
int | getSelectedItemIndex () const |
Gets the index of the selected item. More... | |
bool | changeItem (const sf::String &originalValue, const sf::String &newValue) |
Changes an item with name originalValue to newValue. More... | |
bool | changeItemById (const sf::String &id, const sf::String &newValue) |
Changes the name of an item with the given id to newValue. More... | |
bool | changeItemByIndex (std::size_t index, const sf::String &newValue) |
Changes the name of an item at the given index to newValue. More... | |
std::size_t | getItemCount () const |
Returns the amount of items in the combo box. More... | |
std::vector< sf::String > | getItems () const |
Returns a copy of the items in the combo box. More... | |
const std::vector< sf::String > & | getItemIds () const |
Returns a copy of the item ids in the combo box. More... | |
void | setMaximumItems (std::size_t maximumItems=0) |
Changes the maximum items that the combo box can contain. More... | |
std::size_t | getMaximumItems () const |
Returns the maximum items that the combo box can contain. More... | |
void | setTextSize (unsigned int textSize) override |
Changes the text size of the items. More... | |
unsigned int | getTextSize () const override |
Returns the text size of the items. More... | |
void | setDefaultText (const sf::String &defaultText) |
Changes the default text of the combo box. This is the text drawn when no item is selected. More... | |
const sf::String & | getDefaultText () const |
Returns the default text of the combo box. This is the text drawn when no item is selected. More... | |
void | setExpandDirection (ExpandDirection direction) |
Changes the side where the list is displayed. More... | |
ExpandDirection | getExpandDirection () const |
Returns the side where the list is displayed. More... | |
bool | contains (const sf::String &item) const |
Returns whether the combo box contains the given item. More... | |
bool | containsId (const sf::String &id) const |
Returns whether the combo box contains an item with the given id. More... | |
void | setChangeItemOnScroll (bool changeOnScroll) |
Changes whether the mouse wheel can be used to change the selected item while the list is closed. More... | |
bool | getChangeItemOnScroll () const |
Returns whether the mouse wheel can be used to change the selected item while the list is closed. More... | |
bool | mouseOnWidget (Vector2f pos) const override |
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget. More... | |
void | draw (sf::RenderTarget &target, sf::RenderStates states) const override |
Draw the widget to a render target. More... | |
virtual void | setSize (const Layout2d &size) |
Changes the size of the widget. More... | |
void | setSize (Layout width, Layout height) |
Changes the size of the widget. More... | |
Public Member Functions inherited from tgui::Widget | |
Widget () | |
Default constructor. | |
Widget (const Widget &) | |
Copy constructor. | |
Widget (Widget &&) | |
Move constructor. | |
~Widget () | |
Destructor. | |
Widget & | operator= (const Widget &) |
Overload of copy assignment operator. | |
Widget & | operator= (Widget &&) |
Move assignment. | |
void | setRenderer (std::shared_ptr< RendererData > rendererData) |
Sets a new renderer for the widget. The renderer determines how the widget looks. More... | |
WidgetRenderer * | getSharedRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
WidgetRenderer * | getRenderer () |
Returns the renderer, which gives access to functions that determine how the widget is displayed. More... | |
virtual void | setPosition (const Layout2d &position) |
sets the position of the widget More... | |
void | setPosition (Layout x, Layout y) |
Sets the position of the widget. More... | |
Vector2f | getPosition () const |
Gets the position of the widget. More... | |
void | setSize (Layout width, Layout height) |
Changes the size of the widget. More... | |
Vector2f | getSize () const |
Returns the size of the widget. More... | |
virtual Vector2f | getFullSize () const |
Returns the entire size that the widget is using. More... | |
virtual Vector2f | getAbsolutePosition () const |
Get the absolute position of the widget instead of the relative position to its parent. More... | |
virtual Vector2f | getWidgetOffset () const |
Returns the distance between the position where the widget is drawn and where the widget is placed. More... | |
virtual void | showWithEffect (ShowAnimationType type, sf::Time duration) |
Shows the widget by introducing it with an animation. More... | |
virtual void | hideWithEffect (ShowAnimationType type, sf::Time duration) |
Hides the widget by making it leave with an animation. More... | |
virtual void | setVisible (bool visible) |
Shows or hides a widget. More... | |
bool | isVisible () const |
Returns true when the widget is visible. More... | |
bool | isEnabled () const |
Returns true when the widget is enabled. More... | |
virtual void | setFocused (bool focused) |
Focus or unfocus the widget. More... | |
bool | isFocused () const |
Returns true when the widget is focused and false otherwise. More... | |
const std::string & | getWidgetType () const |
Returns the type of the widget. More... | |
Container * | getParent () const |
Returns a pointer to the parent widget. More... | |
bool | isAnimationPlaying () const |
Returns whether there is an active animation (started with showWithEffect or hideWithEffect) More... | |
virtual void | moveToFront () |
Places the widget before all other widgets. More... | |
virtual void | moveToBack () |
Places the widget behind all other widgets. More... | |
void | setUserData (std::any userData) |
Stores some data into the widget. More... | |
template<typename T > | |
T | getUserData () const |
Returns data stored in the widget. More... | |
void | setInheritedFont (const Font &font) |
Sets the font of the widget that is used when no font is set in the renderer. More... | |
const Font & | getInheritedFont () const |
Returns the font of the widget that is used when no font is set in the renderer. More... | |
void | setInheritedOpacity (float opacity) |
Sets the opacity of the widget that will be multiplied with the opacity set in the renderer. More... | |
float | getInheritedOpacity () const |
Returns the opacity of the widget that is multiplied with the opacity set in the renderer. More... | |
void | setToolTip (Widget::Ptr toolTip) |
Sets the tool tip that should be displayed when hovering over the widget. More... | |
Widget::Ptr | getToolTip () const |
Returns the tool tip that is displayed when hovering over the widget. More... | |
void | setWidgetName (const sf::String &name) |
Changes the name of a widget. More... | |
sf::String | getWidgetName () const |
Returns the name of a widget. More... | |
void | setFocusable (bool focusable) |
Changes whether a widget could be focused. More... | |
bool | isFocusable () const |
Returns whether a widget could be focused. More... | |
virtual bool | canGainFocus () const |
Returns whether the widget can currently gain focus. More... | |
bool | isContainer () const |
Returns whether the widget is a container widget or not. More... | |
template<typename WidgetType > | |
std::shared_ptr< const WidgetType > | cast () const |
Downcast const widget. | |
template<typename WidgetType > | |
std::shared_ptr< WidgetType > | cast () |
Downcast widget. | |
Public Member Functions inherited from tgui::SignalWidgetBase | |
template<typename Func , typename... Args, typename std::enable_if< std::is_convertible< Func, std::function< void(const Args &...)> >::value >::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, const Args &... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs, typename std::enable_if<!std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value &&std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const std::string &)> >::value , ::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, BoundArgs &&... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs, typename std::enable_if<!std::is_convertible< Func, std::function< void(const BoundArgs &...)> >::value &&!std::is_convertible< Func, std::function< void(const BoundArgs &..., std::shared_ptr< Widget >, const std::string &)> >::value , ::type * = nullptr> | |
unsigned int | connect (std::string signalName, Func &&handler, BoundArgs &&... args) |
Connects a signal handler that will be called when this signal is emitted. More... | |
template<typename Func , typename... BoundArgs> | |
unsigned int | connect (std::initializer_list< std::string > signalNames, Func &&handler, BoundArgs &&... args) |
Connect a signal handler to multiple signals. More... | |
bool | disconnect (unsigned int id) |
Disconnects a signal handler. More... | |
void | disconnectAll (std::string signalName) |
Disconnects all signal handler from a certain signal. More... | |
void | disconnectAll () |
Disconnects all signal handlers from signals. | |
Static Public Member Functions | |
static ComboBox::Ptr | create () |
Creates a new combo box widget. More... | |
static ComboBox::Ptr | copy (ComboBox::ConstPtr comboBox) |
Makes a copy of another combo box. More... | |
Public Attributes | |
SignalItem | onItemSelect = {"ItemSelected"} |
An item was selected in the combo box. Optional parameter: selected item or its index. | |
Public Attributes inherited from tgui::Widget | |
SignalVector2f | onPositionChange = {"PositionChanged"} |
The position of the widget changed. Optional parameter: new position. | |
SignalVector2f | onSizeChange = {"SizeChanged"} |
The size of the widget changed. Optional parameter: new size. | |
Signal | onFocus = {"Focused"} |
The widget was focused. | |
Signal | onUnfocus = {"Unfocused"} |
The widget was unfocused. | |
Signal | onMouseEnter = {"MouseEntered"} |
The mouse entered the widget. | |
Signal | onMouseLeave = {"MouseLeft"} |
The mouse left the widget. | |
SignalAnimation | onAnimationFinished = {"AnimationFinished"} |
A show or hide animation finished. Optional parameters: animation type, new widget visibility or both. | |
Protected Member Functions | |
Signal & | getSignal (std::string signalName) override |
Retrieves a signal based on its name. More... | |
void | rendererChanged (const std::string &property) override |
Function called when one of the properties of the renderer is changed. More... | |
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. | |
void | load (const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override |
Loads the widget from a tree of nodes. | |
Widget::Ptr | clone () const override |
Makes a copy of the widget if you don't know its exact type. More... | |
Protected Member Functions inherited from tgui::Widget | |
virtual void | mouseEnteredWidget () |
This function is called when the mouse enters the widget. | |
virtual void | mouseLeftWidget () |
This function is called when the mouse leaves the widget. | |
Combo box widget.
|
strong |
bool tgui::ComboBox::addItem | ( | const sf::String & | itemName, |
const sf::String & | id = "" |
||
) |
Adds an item to the list, so that it can be selected later.
itemName | The name of the item you want to add (this is the text that will be displayed inside the combo box) |
id | Optional unique id given to this item for the purpose to later identifying this item |
bool tgui::ComboBox::changeItem | ( | const sf::String & | originalValue, |
const sf::String & | newValue | ||
) |
Changes an item with name originalValue to newValue.
originalValue | The name of the item which you want to change |
newValue | The new name for that item |
In case the names are not unique, only the first item with that name will be changed.
bool tgui::ComboBox::changeItemById | ( | const sf::String & | id, |
const sf::String & | newValue | ||
) |
Changes the name of an item with the given id to newValue.
id | The unique id of the item which you want to change |
newValue | The new name for that item |
In case the id is not unique, only the first item with that id will be changed.
bool tgui::ComboBox::changeItemByIndex | ( | std::size_t | index, |
const sf::String & | newValue | ||
) |
Changes the name of an item at the given index to newValue.
index | The index of the item which you want to change |
newValue | The new name for that item |
|
inlineoverrideprotectedvirtual |
Makes a copy of the widget if you don't know its exact type.
This function should only be used when you don't know the type of the widget. If you know what kind of widget you are copying, you should use the copy function.
Implements tgui::Widget.
bool tgui::ComboBox::contains | ( | const sf::String & | item | ) | const |
Returns whether the combo box contains the given item.
bool tgui::ComboBox::containsId | ( | const sf::String & | id | ) | const |
Returns whether the combo box contains an item with the given id.
|
static |
Makes a copy of another combo box.
comboBox | The other combo box |
|
static |
Creates a new combo box widget.
void tgui::ComboBox::deselectItem | ( | ) |
Deselects the selected item.
The combo box will be empty after this function is called.
|
overridevirtual |
Draw the widget to a render target.
target | Render target to draw to |
states | Current render states |
Implements tgui::Widget.
bool tgui::ComboBox::getChangeItemOnScroll | ( | ) | const |
Returns whether the mouse wheel can be used to change the selected item while the list is closed.
const sf::String & tgui::ComboBox::getDefaultText | ( | ) | const |
Returns the default text of the combo box. This is the text drawn when no item is selected.
ExpandDirection tgui::ComboBox::getExpandDirection | ( | ) | const |
Returns the side where the list is displayed.
sf::String tgui::ComboBox::getItemById | ( | const sf::String & | id | ) | const |
Returns the item name of the item with the given id.
id | The id of the item that was given to it when it was added |
In case the id is not unique, the first item with that id will be returned.
std::size_t tgui::ComboBox::getItemCount | ( | ) | const |
Returns the amount of items in the combo box.
const std::vector< sf::String > & tgui::ComboBox::getItemIds | ( | ) | const |
Returns a copy of the item ids in the combo box.
Items that were not given an id simply have an empty string as id.
std::vector< sf::String > tgui::ComboBox::getItems | ( | ) | const |
Returns a copy of the items in the combo box.
std::size_t tgui::ComboBox::getItemsToDisplay | ( | ) | const |
Returns the number of items that are displayed in the list.
When there is no scrollbar then this is the maximum number of items. If there is one, then it will only become visible when there are more items than this number.
When set to zero then all items are shown (then there will never be a scrollbar).
std::size_t tgui::ComboBox::getMaximumItems | ( | ) | const |
Returns the maximum items that the combo box can contain.
ComboBoxRenderer * tgui::ComboBox::getRenderer | ( | ) |
Returns the renderer, which gives access to functions that determine how the widget is displayed.
sf::String tgui::ComboBox::getSelectedItem | ( | ) | const |
Returns the currently selected item.
sf::String tgui::ComboBox::getSelectedItemId | ( | ) | const |
Gets the id of the selected item.
int tgui::ComboBox::getSelectedItemIndex | ( | ) | const |
Gets the index of the selected item.
ComboBoxRenderer * tgui::ComboBox::getSharedRenderer | ( | ) |
Returns the renderer, which gives access to functions that determine how the widget is displayed.
|
overrideprotectedvirtual |
Retrieves a signal based on its name.
signalName | Name of the signal |
Exception | when the name does not match any signal |
Reimplemented from tgui::Widget.
|
overridevirtual |
|
overridevirtual |
Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget.
Implements tgui::Widget.
bool tgui::ComboBox::removeItem | ( | const sf::String & | itemName | ) |
Removes the item from the list with the given name.
itemName | The item to remove |
In case the names are not unique, only the first item with that name will be removed.
bool tgui::ComboBox::removeItemById | ( | const sf::String & | id | ) |
Removes the item that were added with the given id.
id | Id that was given to the addItem function |
In case the id is not unique, only the first item with that id will be removed.
bool tgui::ComboBox::removeItemByIndex | ( | std::size_t | index | ) |
Removes the item from the list.
index | Index of the item in the list |
|
overrideprotectedvirtual |
Function called when one of the properties of the renderer is changed.
property | Lowercase name of the property that was changed |
Reimplemented from tgui::Widget.
void tgui::ComboBox::setChangeItemOnScroll | ( | bool | changeOnScroll | ) |
Changes whether the mouse wheel can be used to change the selected item while the list is closed.
changeOnScroll | Should the selected item be changed when scrolling while the mouse is on top of the combo box? |
void tgui::ComboBox::setDefaultText | ( | const sf::String & | defaultText | ) |
Changes the default text of the combo box. This is the text drawn when no item is selected.
defaultText | The new default text |
|
overridevirtual |
Enables or disables the widget.
enabled | Is the widget enabled? |
The disabled widget will no longer receive events and thus no longer send callbacks. All widgets are enabled by default.
Reimplemented from tgui::Widget.
void tgui::ComboBox::setExpandDirection | ( | ExpandDirection | direction | ) |
Changes the side where the list is displayed.
direction | On which side of the combo box should the list be displayed? |
void tgui::ComboBox::setItemsToDisplay | ( | std::size_t | nrOfItemsInListToDisplay | ) |
Changes the number of items that are displayed in the list.
nrOfItemsInListToDisplay | The maximum number of items to display when the list of items is shown |
When there is no scrollbar then this is the maximum number of items. If there is one, then it will only become visible when there are more items than this number.
When set to zero then all items are shown (then there will never be a scrollbar).
void tgui::ComboBox::setMaximumItems | ( | std::size_t | maximumItems = 0 | ) |
Changes the maximum items that the combo box can contain.
maximumItems | The maximum items inside the combo box. When the maximum is set to 0 then the limit will be disabled |
If no scrollbar was loaded then there is always a limitation because there will be a limited space for the items.
bool tgui::ComboBox::setSelectedItem | ( | const sf::String & | itemName | ) |
Selects an item from the list.
When adding items to the combo box with the addItem function, none of them will be selected. If you don't want the combo box to stay empty until the user selects something, but you want a default item instead, then you can use this function to select an item.
itemName | The item you want to select |
In case the names are not unique, the first item with that name will be selected.
bool tgui::ComboBox::setSelectedItemById | ( | const sf::String & | id | ) |
Selects an item from the list.
When adding items to the combo box with the addItem function, none of them will be selected. If you don't want the combo box to stay empty until the user selects something, but you want a default item instead, then you can use this function to select an item.
id | Unique id passed to addItem |
In case the id would not be unique, the first item with that id will be selected.
bool tgui::ComboBox::setSelectedItemByIndex | ( | std::size_t | index | ) |
Selects an item in the list.
index | Index of the item in the list |
|
virtual |
Changes the size of the widget.
size | Size of the widget |
Usage examples:
Reimplemented from tgui::Widget.
|
overridevirtual |
Changes the size of the combo box.
This size does not include the borders.
size | The new size of the combo box |
Reimplemented from tgui::Widget.
Changes the size of the widget.
width | Width of the widget |
height | Height of the widget |
|
overridevirtual |
Changes the text size of the items.
textSize | The size size of the text |
When passing 0 to this function, the text will be auto-sized to nicely fit inside the combo box.
Reimplemented from tgui::Widget.