Entire Class Index | Main Class Index | Cross Index | Global Index

# Class CL_ListBox

Listbox component
Contained in: global
Derived from: CL_Component
Derived by: none
Group: GUI (Controls)

#include <ClanLib/gui.h>

### public function member index:
### Construction:
`` | `CL_ListBox` | `(`CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;
`` | `CL_ListBox` | `(`const` `CL_Rect`& `pos`, `CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;
`` | `CL_ListBox` | `(`const` `CL_Rect`& `pos`, `int` `max_visible_items`, `CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;
``virtual`` | `~CL_ListBox` | `()`;
### Attributes:
``CL_Component`*` | `get_client_area` | `() `const``;
``int`` | `get_count` | `() `const``;
``std::vector`<`CL_ListItem`>&` | `get_items` | `() `const``;
``std::vector`<`std::string`>` | `get_selected_items` | `() `const``;
``const` `std::string`&` | `get_current_text` | `() `const``;
``const` `std::string`&` | `get_text` | `(`int` `index`) `const``;
``int`` | `get_current_item` | `() `const``;
``bool`` | `is_selected` | `(`int` `index`) `const``;
``bool`` | `is_multi_selection` | `() `const``;
``int`` | `get_item_height` | `() `const``;
``int`` | `get_top_item` | `() `const``;
``int`` | `get_max_visible_items` | `() `const``;
``bool`` | `has_scrollbar` | `() `const``;
### Operations:
``int`` | `insert_item` | `(`const` `std::string`& `text`, `int` `index` = -1)`;
``void`` | `remove_item` | `(`int` `index`)`;
``void`` | `change_item` | `(`const` `std::string`& `text`, `int` `index`)`;
``void`` | `set_current_item` | `(`int` `index`)`;
``void`` | `set_selected` | `(`int` `index`, `bool` `select`)`;
``void`` | `clear_selection` | `()`;
``void`` | `select_all` | `(`bool` `select` = true)`;
``void`` | `invert_selection` | `()`;
``void`` | `set_multi_selection` | `(`bool` `enable` = true)`;
``void`` | `set_item_height` | `(`int` `height`)`;
``void`` | `set_max_visible_items` | `(`int` `count`)`;
``void`` | `set_top_item` | `(`int` `index`)`;
``void`` | `sort` | `(`bool` `ascending` = true)`;
``void`` | `clear` | `()`;
### Signals:
``CL_Signal_v1`<`int`>&` | `sig_highlighted` | `()`;
``CL_Signal_v1`<`int`>&` | `sig_activated` | `()`;
``CL_Signal_v0`&` | `sig_selection_changed` | `()`;
### private function member index:
### Implementation:
`` | `CL_ListBox` | `(`const` `CL_ListBox`& `copy`)`;

## Description:

## Function Member Descriptions:

CL_ListBox::CL_ListBox - Listbox constructor
`` `CL_ListBox``(`CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;

CL_ListBox::CL_ListBox - Listbox constructor
`` `CL_ListBox``(`const` `CL_Rect`& `pos`, `CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;

CL_ListBox::CL_ListBox - Creates a listbox with max_visible_items visible. It auto-calculates the height of the listbox.
`` `CL_ListBox``(`const` `CL_Rect`& `pos`, `int` `max_visible_items`, `CL_Component`* `parent`, `CL_StyleManager`* `style` = NULL)`;

CL_ListBox::change_item - Replaces the item at position index with text.
``void`` `change_item``(`const` `std::string`& `text`, `int` `index`)`;

CL_ListBox::clear - Deletes all items in the list.
``void`` `clear``()`;

CL_ListBox::clear_selection - Deselects current selected item.
``void`` `clear_selection``()`;

CL_ListBox::get_client_area - Returns the client area of the component.
``CL_Component`*` `get_client_area``() `const``;

CL_ListBox::get_count - Returns the number of items in the list box.
``int`` `get_count``() `const``;

CL_ListBox::get_current_item - Returns the index of the current item of the listbox, or -1 if no item has been selected.
``int`` `get_current_item``() `const``;

CL_ListBox::get_current_text - Returns the text of the current item.
``const` `std::string`&` `get_current_text``() `const``;

CL_ListBox::get_item_height - Returns the height of one item.
``int`` `get_item_height``() `const``;

CL_ListBox::get_items - Returns all items in the list.
``std::vector`<`CL_ListItem`>&` `get_items``() `const``;

CL_ListBox::get_max_visible_items - Returns number of items maximum visible in listbox (without scrolling)
``int`` `get_max_visible_items``() `const``;

CL_ListBox::get_selected_items - Returns all selected items.
``std::vector`<`std::string`>` `get_selected_items``() `const``;

CL_ListBox::get_text - Returns the text at position index.
``const` `std::string`&` `get_text``(`int` `index`) `const``;

CL_ListBox::get_top_item - Returns the index of the item at the top of the screen.
``int`` `get_top_item``() `const``;

CL_ListBox::has_scrollbar - Returns true if a scrollbar is visible in the listbox.
``bool`` `has_scrollbar``() `const``;

CL_ListBox::insert_item - Inserts text into the list at index.
``int`` `insert_item``(`const` `std::string`& `text`, `int` `index` = -1)`;

> If index is negative, text is inserted at the end of the list.
> Returns the index of the text

CL_ListBox::invert_selection - Inverts the selection.
Works only in Multi selection mode.
``void`` `invert_selection``()`;

CL_ListBox::is_multi_selection - Returns true if the listbox is in multiselection mode.
``bool`` `is_multi_selection``() `const``;

CL_ListBox::is_selected - Returns true if item index is selected. Returns false if it is not selected or if there is an error.
``bool`` `is_selected``(`int` `index`) `const``;

CL_ListBox::remove_item - Removes and deletes the item at position index.
If index is equal to get_current_item(), a new item gets highlighted and the sig_highlighted() signal is emitted.
``void`` `remove_item``(`int` `index`)`;

CL_ListBox::select_all - If select is true, all items get selected, else all get unselected.
This works only in Multi selection mode.
``void`` `select_all``(`bool` `select` = true)`;

CL_ListBox::set_current_item - Sets the highlighted item to the item index.
The highlighting is moved and the listbox scrolled as necessary.
``void`` `set_current_item``(`int` `index`)`;

CL_ListBox::set_item_height - Sets the height of each item.
``void`` `set_item_height``(`int` `height`)`;

CL_ListBox::set_max_visible_items - Sets the number of items maximum visible in listbox (without scrolling)
``void`` `set_max_visible_items``(`int` `count`)`;

CL_ListBox::set_multi_selection - Sets the listbox to multiselection if enable is true,
single selection otherwise.
``void`` `set_multi_selection``(`bool` `enable` = true)`;

CL_ListBox::set_selected - Selects item at index if select is true, or unselects it if select is false.
If the listbox is a single-selection listbox and and select is true, set_current_item() is called.
If the listbox is a single-selection listbox and and select is false, clear_selection()
is called if index is the currently selected item.
``void`` `set_selected``(`int` `index`, `bool` `select`)`;

CL_ListBox::set_top_item - Scrolls the list box so the item at position index in the list is displayed in the top row of the listbox.
``void`` `set_top_item``(`int` `index`)`;

CL_ListBox::sig_activated - This signal is emitted when the user clicks on an item or presses return when an item is highlighted.
The argument is the index of the selected item.
``CL_Signal_v1`<`int`>&` `sig_activated``()`;

CL_ListBox::sig_highlighted - This signal is emitted when the user highlights a new current item.
The argument is the index of the new item, which is already current.
``CL_Signal_v1`<`int`>&` `sig_highlighted``()`;

CL_ListBox::sig_selection_changed - This signal is emitted when the selection set of a listbox changes.
``CL_Signal_v0`&` `sig_selection_changed``()`;

CL_ListBox::sort - Sorts the items in ascending order, if ascending is true, or descending otherwise.
``void`` `sort``(`bool` `ascending` = true)`;

CL_ListBox::~CL_ListBox - Listbox destructor
``virtual`` `~CL_ListBox``()`;

## Variable Member Descriptions: