TGUI  v0.6.10
Public Types | Public Member Functions | List of all members
tgui::ComboBox Class Reference
Inheritance diagram for tgui::ComboBox:
tgui::Widget tgui::WidgetBorders tgui::Transformable tgui::CallbackManager

Public Types

- Public Types inherited from tgui::Widget

Public Member Functions

 ComboBox ()
 Default constructor. More...
 
 ComboBox (const ComboBox &copy)
 Copy constructor. More...
 
virtual ~ComboBox ()
 Destructor. More...
 
ComboBoxoperator= (const ComboBox &right)
 Overload of assignment operator. More...
 
bool load (const std::string &configFileFilename, const std::string &sectionName="ComboBox")
 Loads the widget. More...
 
const std::string & getLoadedConfigFile () const
 Returns the filename of the config file that was used to load the widget. More...
 
void setSize (float width, float height)
 Changes the size of the combo box. More...
 
virtual sf::Vector2f getSize () const
 Returns the size of the combo box. More...
 
virtual sf::Vector2f getFullSize () const
 Returns the full size of the combo box. More...
 
void setItemsToDisplay (unsigned int nrOfItemsInListToDisplay)
 Changes the number of items that are displayed in the list. More...
 
unsigned int getItemsToDisplay () const
 Returns the number of items that are displayed in the list. More...
 
void changeColors (const sf::Color &backgroundColor=sf::Color::White, const sf::Color &textColor=sf::Color::Black, const sf::Color &selectedBackgroundColor=sf::Color(50, 100, 200), const sf::Color &selectedTextColor=sf::Color::White, const sf::Color &borderColor=sf::Color::Black)
 Changes the colors that are used in the combo box. More...
 
void setBackgroundColor (const sf::Color &backgroundColor)
 Set the background color that will be used inside the combo box. More...
 
void setTextColor (const sf::Color &textColor)
 Set the text color that will be used inside the combo box. More...
 
void setSelectedBackgroundColor (const sf::Color &selectedBackgroundColor)
 Set the background color of the selected text that will be used inside the combo box. More...
 
void setSelectedTextColor (const sf::Color &selectedTextColor)
 Set the text color of the selected text that will be used inside the combo box. More...
 
void setBorderColor (const sf::Color &borderColor)
 Set the border color text that will be used inside the combo box. More...
 
const sf::Color & getBackgroundColor () const
 Get the background color that is currently being used inside the combo box. More...
 
const sf::Color & getTextColor () const
 Get the text color that is currently being used inside the combo box. More...
 
const sf::Color & getSelectedBackgroundColor () const
 Get the background color of the selected text that is currently being used inside the combo box. More...
 
const sf::Color & getSelectedTextColor () const
 Get the text color of the selected text that is currently being used inside the combo box. More...
 
const sf::Color & getBorderColor () const
 Get the border color that is currently being used inside the combo box. More...
 
void setTextFont (const sf::Font &font)
 Changes the text font. More...
 
const sf::Font * getTextFont () const
 Returns the text font. More...
 
virtual void setBorders (unsigned int leftBorder=0, unsigned int topBorder=0, unsigned int rightBorder=0, unsigned int bottomBorder=0)
 Changes the size of the borders. More...
 
int addItem (const sf::String &itemName, int id=0)
 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 setSelectedItem (int index)
 Selects an item from the list. More...
 
void deselectItem ()
 Deselects the selected item. More...
 
bool removeItem (unsigned int index)
 Removes an item from the list with a given index. More...
 
bool removeItem (const sf::String &itemName)
 Removes the first item from the list with a given name. More...
 
unsigned int removeItemsById (int id)
 Removes all items that were added with the given id. More...
 
void removeAllItems ()
 Removes all items from the list. More...
 
sf::String getItem (unsigned int index) const
 Returns the item name of the item with the given index. More...
 
int getItemIndex (const sf::String &itemName) const
 Returns the index of the first item with the given name. More...
 
std::vector< sf::String > & getItems () const
 Returns the list that contains all the items. More...
 
sf::String getSelectedItem () const
 Returns the currently selected item. More...
 
int getSelectedItemIndex () const
 Get the index of the selected item. More...
 
int getSelectedItemId () const
 Get the id of the selected item. More...
 
bool changeItem (unsigned int index, const sf::String &newValue)
 Changes the value of the item at the given index. More...
 
unsigned int changeItems (const sf::String &originalValue, const sf::String &newValue)
 Changes all items with originalValue to newValue. More...
 
unsigned int changeItemsById (int id, const sf::String &newValue)
 Changes all items with the given id to newValue. More...
 
bool setScrollbar (const std::string &scrollbarConfigFileFilename)
 Changes the scrollbar that is displayed next to the list. More...
 
void removeScrollbar ()
 Removes the scrollbar. More...
 
void setMaximumItems (unsigned int maximumItems=0)
 Changes the maximum items that the combo box can contain. More...
 
unsigned int getMaximumItems () const
 Returns the maximum items that the combo box can contain. More...
 
virtual void setTransparency (unsigned char transparency)
 Changes the transparency of the widget. More...
 
- Public Member Functions inherited from tgui::Widget
 Widget ()
 Default constructor. More...
 
 Widget (const Widget &copy)
 Copy constructor. More...
 
virtual ~Widget ()
 Destructor. More...
 
Widgetoperator= (const Widget &right)
 Overload of assignment operator. More...
 
virtual sf::Vector2f getAbsolutePosition () const
 Get the absolute position of the widget on the screen. More...
 
virtual void show ()
 Shows the widget. More...
 
virtual void hide ()
 Hides the widget. More...
 
bool isVisible () const
 Returns true when the widget is visible. More...
 
virtual void enable ()
 Enables the widget. More...
 
virtual void disable ()
 Disables the widget. More...
 
bool isEnabled () const
 Returns true when the widget is enabled. More...
 
bool isDisabled () const
 Returns true when the widget is disabled. More...
 
bool isLoaded () const
 Returns true when the widget is loaded successfully. More...
 
virtual void focus ()
 Focus the widget. More...
 
virtual void unfocus ()
 Unfocus the widget. More...
 
bool isFocused () const
 Returns true when the widget is focused and false otherwise. More...
 
WidgetTypes getWidgetType () const
 Returns the type of the widget. More...
 
ContainergetParent () const
 Returns a pointer to the parent widget. More...
 
unsigned char getTransparency () const
 Returns the transparency of the widget. More...
 
virtual void moveToFront ()
 Places the widget before all other widgets. More...
 
virtual void moveToBack ()
 Places the widget behind all other widgets. More...
 
void setCallbackId (unsigned int callbackId)
 Changes the callback id of the widget. More...
 
unsigned int getCallbackId ()
 Returns the callback id of the widget. More...
 
- Public Member Functions inherited from tgui::Transformable
 Transformable ()
 Default constructor. More...
 
virtual ~Transformable ()
 Destructor. More...
 
virtual void setPosition (float x, float y)
 Set the position of the widget. More...
 
void setPosition (const sf::Vector2f &position)
 set the position of the widget More...
 
const sf::Vector2f & getPosition () const
 get the position of the widget More...
 
void move (float offsetX, float offsetY)
 Move the widget by a given offset. More...
 
void move (const sf::Vector2f &offset)
 Move the widget by a given offset. More...
 
void scale (float factorX, float factorY)
 Scale the widget. More...
 
void scale (const sf::Vector2f &factors)
 Scale the widget. More...
 
- Public Member Functions inherited from tgui::CallbackManager
void bindCallback (std::function< void()> func, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
template<typename T >
void bindCallback (void(T::*func)(), T *const classPtr, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
void bindCallbackEx (std::function< void(const Callback &)> func, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
template<typename T >
void bindCallbackEx (void(T::*func)(const Callback &), T *const classPtr, unsigned int trigger)
 Bind a function to one or more specific callback trigger(s). More...
 
void bindCallback (unsigned int trigger)
 Bind one or more specific callback trigger(s) to the parent widget. More...
 
void unbindCallback (unsigned int trigger)
 Unbind all callback function bound to the given trigger. More...
 
void unbindAllCallback ()
 Unbind all callback functions bound to any callback. More...
 
- Public Member Functions inherited from tgui::WidgetBorders
 WidgetBorders ()
 Default constructor. More...
 
virtual ~WidgetBorders ()
 Destructor. More...
 
virtual Borders getBorders () const
 Returns the size of the borders as a tgui::Borders. More...
 

Member Enumeration Documentation

Defines specific triggers to ComboBox.

Enumerator
ItemSelected 

A new item was selected.

AllComboBoxCallbacks 

All triggers defined in ComboBox and its base classes.

Constructor & Destructor Documentation

tgui::ComboBox::ComboBox ( )

Default constructor.

tgui::ComboBox::ComboBox ( const ComboBox copy)

Copy constructor.

Parameters
copyInstance to copy
virtual tgui::ComboBox::~ComboBox ( )
virtual

Destructor.

Member Function Documentation

int tgui::ComboBox::addItem ( const sf::String &  itemName,
int  id = 0 
)

Adds an item to the list, so that it can be selected later.

Parameters
itemNameThe name of the item you want to add (this is the text that will be displayed inside the combo box)
idOptional id given to this item for the purpose to later identifying this item.
Returns
  • The index of the item when it was successfully added.
  • -1 when the combo box wasn't loaded correctly
  • -1 when the list is full (you have set a maximum item limit and you are trying to add more items)
  • -1 when there is no scrollbar and you try to have more items than the number of items to display
Warning
The index returned by this function may no longer correct when an item is removed.
See also
setMaximumItems
setItemsToDisplay
void tgui::ComboBox::changeColors ( const sf::Color &  backgroundColor = sf::Color::White,
const sf::Color &  textColor = sf::Color::Black,
const sf::Color &  selectedBackgroundColor = sf::Color(50, 100, 200),
const sf::Color &  selectedTextColor = sf::Color::White,
const sf::Color &  borderColor = sf::Color::Black 
)

Changes the colors that are used in the combo box.

Parameters
backgroundColorThe color of the background of the combo box
textColorThe color of the text
selectedBackgroundColorThe color of the background of the selected item in the list
selectedTextColorThe color of the text when it is selected in the list
borderColorThe color of the borders
bool tgui::ComboBox::changeItem ( unsigned int  index,
const sf::String &  newValue 
)

Changes the value of the item at the given index.

Parameters
indexThe index of the value that should be changed
newValueThe new name for that item
Returns
True when the name was changed, false when the id was too high
unsigned int tgui::ComboBox::changeItems ( const sf::String &  originalValue,
const sf::String &  newValue 
)

Changes all items with originalValue to newValue.

Parameters
originalValueThe name of the items which will change
newValueThe new name for these items
Returns
The amount of items that were changed
unsigned int tgui::ComboBox::changeItemsById ( int  id,
const sf::String &  newValue 
)

Changes all items with the given id to newValue.

Parameters
idThe id of the items which will change
newValueThe new name for these items
Returns
The amount of items that were changed
void tgui::ComboBox::deselectItem ( )

Deselects the selected item.

The combo box will be empty after this function is called.

const sf::Color& tgui::ComboBox::getBackgroundColor ( ) const

Get the background color that is currently being used inside the combo box.

Returns
The color of the background of the combo box
const sf::Color& tgui::ComboBox::getBorderColor ( ) const

Get the border color that is currently being used inside the combo box.

Returns
The color of the borders
virtual sf::Vector2f tgui::ComboBox::getFullSize ( ) const
virtual

Returns the full size of the combo box.

The size returned by this function includes the borders.

Returns
The full size of the combo box

Reimplemented from tgui::Transformable.

sf::String tgui::ComboBox::getItem ( unsigned int  index) const

Returns the item name of the item with the given index.

Parameters
indexThe index of the item
Returns
The requested item. The string will be empty when the index was too high.
See also
getItemIndex
int tgui::ComboBox::getItemIndex ( const sf::String &  itemName) const

Returns the index of the first item with the given name.

Parameters
itemNameThe name of the item
Returns
The index of the item that matches the name. If none of the items matches then the returned index will be -1.
Warning
This index may become wrong when an item is removed from the list.
See also
getItem
std::vector<sf::String>& tgui::ComboBox::getItems ( ) const

Returns the list that contains all the items.

Returns
The vector of strings
unsigned int tgui::ComboBox::getItemsToDisplay ( ) const

Returns the number of items that are displayed in the list.

Returns
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).

const std::string& tgui::ComboBox::getLoadedConfigFile ( ) const

Returns the filename of the config file that was used to load the widget.

Returns
Filename of loaded config file. Empty string when no config file was loaded yet.
unsigned int tgui::ComboBox::getMaximumItems ( ) const

Returns the maximum items that the combo box can contain.

Returns
The maximum items inside the list. If the function returns 0 then there is no limit.
const sf::Color& tgui::ComboBox::getSelectedBackgroundColor ( ) const

Get the background color of the selected text that is currently being used inside the combo box.

Returns
The color of the background of the selected item in the list
sf::String tgui::ComboBox::getSelectedItem ( ) const

Returns the currently selected item.

Returns
The selected item. When no item was selected then this function will return an empty string.
See also
getSelectedItemIndex
int tgui::ComboBox::getSelectedItemId ( ) const

Get the id of the selected item.

Returns
The id of the selected item, which was the optional id passed to the addItem function. When no item was selected then this function returns 0.
int tgui::ComboBox::getSelectedItemIndex ( ) const

Get the index of the selected item.

Returns
The index of the selected item. When no item was selected then this function returns -1.
Warning
This index may become wrong when an item is removed from the list.
See also
getSelectedItem
const sf::Color& tgui::ComboBox::getSelectedTextColor ( ) const

Get the text color of the selected text that is currently being used inside the combo box.

Returns
The color of the text when it is selected in the list
virtual sf::Vector2f tgui::ComboBox::getSize ( ) const
virtual

Returns the size of the combo box.

The size returned by this function does not include the borders.

Returns
The size of the combo box

Implements tgui::Transformable.

const sf::Color& tgui::ComboBox::getTextColor ( ) const

Get the text color that is currently being used inside the combo box.

Returns
The color of the text
const sf::Font* tgui::ComboBox::getTextFont ( ) const

Returns the text font.

Returns
Pointer to the font that is currently being used.
bool tgui::ComboBox::load ( const std::string &  configFileFilename,
const std::string &  sectionName = "ComboBox" 
)

Loads the widget.

Parameters
configFileFilenameFilename of the config file.
sectionNameName of the section in the file to load

The config file must contain a ComboBox section with the needed information.

ComboBox& tgui::ComboBox::operator= ( const ComboBox right)

Overload of assignment operator.

Parameters
rightInstance to assign
Returns
Reference to itself
void tgui::ComboBox::removeAllItems ( )

Removes all items from the list.

bool tgui::ComboBox::removeItem ( unsigned int  index)

Removes an item from the list with a given index.

Parameters
indexThe index of the item to remove
Returns
  • true when the item was removed
  • false when the index was too high
bool tgui::ComboBox::removeItem ( const sf::String &  itemName)

Removes the first item from the list with a given name.

Parameters
itemNameThe item to remove
Returns
  • true when the item was removed
  • false when the name didn't match any item
unsigned int tgui::ComboBox::removeItemsById ( int  id)

Removes all items that were added with the given id.

Parameters
idId that was given to the addItem function.
Returns
Amount of items that were removed.
void tgui::ComboBox::removeScrollbar ( )

Removes the scrollbar.

When there are too many items to fit in the list then the items will be removed.

void tgui::ComboBox::setBackgroundColor ( const sf::Color &  backgroundColor)

Set the background color that will be used inside the combo box.

Parameters
backgroundColorThe color of the background of the combo box
void tgui::ComboBox::setBorderColor ( const sf::Color &  borderColor)

Set the border color text that will be used inside the combo box.

Parameters
borderColorThe color of the borders
virtual void tgui::ComboBox::setBorders ( unsigned int  leftBorder = 0,
unsigned int  topBorder = 0,
unsigned int  rightBorder = 0,
unsigned int  bottomBorder = 0 
)
virtual

Changes the size of the borders.

Parameters
leftBorderThe width of the left border
topBorderThe height of the top border
rightBorderThe width of the right border
bottomBorderThe height of the bottom border

Implements tgui::WidgetBorders.

void tgui::ComboBox::setItemsToDisplay ( unsigned int  nrOfItemsInListToDisplay)

Changes the number of items that are displayed in the list.

Parameters
nrOfItemsInListToDisplayThe 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 ( unsigned int  maximumItems = 0)

Changes the maximum items that the combo box can contain.

Parameters
maximumItemsThe 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::setScrollbar ( const std::string &  scrollbarConfigFileFilename)

Changes the scrollbar that is displayed next to the list.

Parameters
scrollbarConfigFileFilenameFilename of the config file. The config file must contain a Scrollbar section with the needed information.
Returns
  • true when the scrollbar was successfully loaded
  • false when the loading of the scrollbar failed
void tgui::ComboBox::setSelectedBackgroundColor ( const sf::Color &  selectedBackgroundColor)

Set the background color of the selected text that will be used inside the combo box.

Parameters
selectedBackgroundColorThe color of the background of the selected item in the list
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. The first item that matches the name will be selected.

Parameters
itemNameThe item you want to select
Returns
  • true on success
  • false when none of the items matches the name
See also
setSelectedItem(unsigned int)
bool tgui::ComboBox::setSelectedItem ( int  index)

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. If the index is -1 then the deselectItem function will be called.

Parameters
indexThe index of the item
Returns
  • true on success
  • false when the index was too high
See also
setSelectedItem(sf::String)
void tgui::ComboBox::setSelectedTextColor ( const sf::Color &  selectedTextColor)

Set the text color of the selected text that will be used inside the combo box.

Parameters
selectedTextColorThe color of the text when it is selected in the list
void tgui::ComboBox::setSize ( float  width,
float  height 
)
virtual

Changes the size of the combo box.

This size does not include the borders.

Parameters
widthThe new width of the combo box
heightThe new height of the combo box

Implements tgui::Transformable.

void tgui::ComboBox::setTextColor ( const sf::Color &  textColor)

Set the text color that will be used inside the combo box.

Parameters
textColorThe color of the text
void tgui::ComboBox::setTextFont ( const sf::Font &  font)

Changes the text font.

When you don't call this function then the global font will be use. This global font can be changed with the setGlobalFont function from the parent.

Parameters
fontThe new font.
virtual void tgui::ComboBox::setTransparency ( unsigned char  transparency)
virtual

Changes the transparency of the widget.

Parameters
transparencyThe transparency of the widget. 0 is completely transparent, while 255 (default) means fully opaque.

Note that this will only change the transparency of the images. The parts of the widgets that use a color will not be changed. You must change them yourself by setting the alpha channel of the color.

Reimplemented from tgui::Widget.


The documentation for this class was generated from the following file: