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

Public Types

- Public Types inherited from tgui::Widget

Public Member Functions

 ListBox ()
 Default constructor. More...
 
 ListBox (const ListBox &copy)
 Copy constructor. More...
 
virtual ~ListBox ()
 Destructor. More...
 
ListBoxoperator= (const ListBox &right)
 Overload of assignment operator. More...
 
bool load (const std::string &configFileFilename, const std::string &sectionName="ListBox")
 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 list box. More...
 
virtual sf::Vector2f getSize () const
 Returns the size of the list box. More...
 
virtual sf::Vector2f getFullSize () const
 Returns the full size of the list box. 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 used in the list box. More...
 
void setBackgroundColor (const sf::Color &backgroundColor)
 Set the background color that will be used inside the list box. More...
 
void setTextColor (const sf::Color &textColor)
 Set the text color that will be used inside the list box. More...
 
void setSelectedBackgroundColor (const sf::Color &selectedBackgroundColor)
 Set the background color of the selected text that will be used inside the list box. More...
 
void setSelectedTextColor (const sf::Color &selectedTextColor)
 Set the text color of the selected text that will be used inside the list box. More...
 
void setBorderColor (const sf::Color &borderColor)
 Set the border color text that will be used inside the list box. More...
 
const sf::Color & getBackgroundColor () const
 Get the background color that is currently being used inside the list box. More...
 
const sf::Color & getTextColor () const
 Get the text color that is currently being used inside the list box. More...
 
const sf::Color & getSelectedBackgroundColor () const
 Get the background color of the selected text that is currently being used inside the list box. More...
 
const sf::Color & getSelectedTextColor () const
 Get the text color of the selected text that is currently being used inside the list box. More...
 
const sf::Color & getBorderColor () const
 Get the border color that is currently being used inside the list box. More...
 
void setTextFont (const sf::Font &font)
 Changes the font of the items. More...
 
const sf::Font * getTextFont () const
 Returns the font of the items. More...
 
int addItem (const sf::String &itemName, int id=0)
 Adds an item to the list. More...
 
bool setSelectedItem (const sf::String &itemName)
 Selects an item in the list box. More...
 
bool setSelectedItem (int index)
 Selects an item in the list box. 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 the 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 ()
 Returns the list of 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 of the list box. More...
 
void removeScrollbar ()
 Removes the scrollbar from the list box. More...
 
void setItemHeight (unsigned int itemHeight)
 Changes the height of the items in the list box. More...
 
unsigned int getItemHeight () const
 Returns the height of the items in the list box. More...
 
void setMaximumItems (unsigned int maximumItems=0)
 Changes the maximum items that the list box can contain. More...
 
unsigned int getMaximumItems () const
 Returns the maximum items that the list box can contain. 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...
 
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 ListBox.

Enumerator
ItemSelected 

A new item was selected.

AllListBoxCallbacks 

All triggers defined in ListBox and its base classes.

Constructor & Destructor Documentation

tgui::ListBox::ListBox ( )

Default constructor.

tgui::ListBox::ListBox ( const ListBox copy)

Copy constructor.

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

Destructor.

Member Function Documentation

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

Adds an item to the list.

Parameters
itemNameThe name of the item you want to add (this is the text that will be displayed inside the list 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 list box 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 fit inside the list box
Warning
The index returned by this function is no longer correct when an item is removed.
See also
setMaximumItems
setScrollbar
void tgui::ListBox::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 used in the list box.

Parameters
backgroundColorThe color of the background of the list box
textColorThe color of the text
selectedBackgroundColorThe color of the background of the selected item
selectedTextColorThe color of the text when it is selected
borderColorThe color of the borders
bool tgui::ListBox::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::ListBox::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::ListBox::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::ListBox::deselectItem ( )

Deselects the selected item.

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

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

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

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

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

Returns the full size of the list box.

The size returned by this function includes the borders.

Returns
Full size of the list box

Reimplemented from tgui::Transformable.

sf::String tgui::ListBox::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
unsigned int tgui::ListBox::getItemHeight ( ) const

Returns the height of the items in the list box.

Returns
The item height
int tgui::ListBox::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::ListBox::getItems ( )

Returns the list of all the items.

Returns
The vector of strings
const std::string& tgui::ListBox::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::ListBox::getMaximumItems ( ) const

Returns the maximum items that the list box can contain.

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

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

Returns
The color of the background of the selected item
sf::String tgui::ListBox::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::ListBox::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::ListBox::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::ListBox::getSelectedTextColor ( ) const

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

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

Returns the size of the list box.

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

Returns
Size of the list box

Implements tgui::Transformable.

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

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

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

Returns the font of the items.

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

Loads the widget.

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

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

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

Overload of assignment operator.

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

Removes all items from the list.

bool tgui::ListBox::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::ListBox::removeItem ( const sf::String &  itemName)

Removes the first item from the list with the 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::ListBox::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::ListBox::removeScrollbar ( )

Removes the scrollbar from the list box.

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

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

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

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

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

Parameters
borderColorThe color of the borders
virtual void tgui::ListBox::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::ListBox::setItemHeight ( unsigned int  itemHeight)

Changes the height of the items in the list box.

Parameters
itemHeightThe size of a single item in the list
Remarks
  • This size is always a little big greater than the text size.
  • When there is no scrollbar then the items will be removed when they no longer fit inside the list box.
void tgui::ListBox::setMaximumItems ( unsigned int  maximumItems = 0)

Changes the maximum items that the list box can contain.

Parameters
maximumItemsThe maximum items inside the list 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::ListBox::setScrollbar ( const std::string &  scrollbarConfigFileFilename)

Changes the scrollbar of the list box.

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::ListBox::setSelectedBackgroundColor ( const sf::Color &  selectedBackgroundColor)

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

Parameters
selectedBackgroundColorThe color of the background of the selected item
bool tgui::ListBox::setSelectedItem ( const sf::String &  itemName)

Selects an item in the list box.

When adding items to the list box with the addItem function, none of them will be selected. If you want a default item selected then you can use this function to select it. 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::ListBox::setSelectedItem ( int  index)

Selects an item in the list box.

When adding items to the list box with the addItem function, none of them will be selected. If you want a default item selected then you can use this function to select it. 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::ListBox::setSelectedTextColor ( const sf::Color &  selectedTextColor)

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

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

Changes the size of the list box.

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

Implements tgui::Transformable.

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

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

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

Changes the font of the items.

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::ListBox::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: