#include <listbox.hpp>
Public Member Functions | |
tlistbox () | |
void | set_active (const bool active) |
Sets the control in the active state, when inactive a control can't be used and doesn't react to events. | |
bool | get_active () const |
Gets the active state of the control. | |
unsigned | get_state () const |
Returns the id of the state, which is also the index for the canvas. | |
bool | has_vertical_scrollbar () const |
Inherited from twidget. | |
void | list_item_selected (twidget *caller) |
When an item in the list is selected by the user we need to update the state. | |
void | scrollbar_moved (twidget *) |
Callback when the scrollbar moves. | |
void | scrollbar_click (twidget *caller) |
When an item scrollbar control button is clicked we need to move the scrollbar and update the list. | |
void | finalize_setup () |
The builder needs to call us so we can write in the proper callbacks. | |
void | set_list_builder (tbuilder_grid *list_builder) |
void | set_assume_fixed_row_size (bool assume=true) |
tpoint | get_best_size () const |
Inherited from tcontainer. | |
void | draw (surface &surface) |
Inherited from tcontainer. | |
void | set_size (const SDL_Rect &rect) |
Inherited from tcontainer. | |
twidget * | find_widget (const tpoint &coordinate, const bool must_be_active) |
Inherited from tcontainer. | |
const twidget * | find_widget (const tpoint &coordinate, const bool must_be_active) const |
Inherited from tcontainer. | |
void | add_item (const t_string &label) |
Adds an item to the list, it requires the builder_list to be defined. | |
unsigned | get_item_count () const |
bool | select_row (const unsigned row, const bool select=true) |
Selects an entire row. | |
unsigned | get_selected_row () const |
void | set_row_active (const unsigned row, const bool active) |
Makes a row active or inactive. | |
Private Types | |
enum | tstate { ENABLED, DISABLED, COUNT } |
Note the order of the states must be the same as defined in settings.hpp. More... | |
Private Member Functions | |
void | set_scrollbar_button_status () |
Sets the status of the scrollbar buttons. | |
void | set_state (tstate state) |
tscrollbar_ * | scrollbar () |
Returns the scrollbar widget. | |
const tscrollbar_ * | scrollbar () const |
Returns the scrollbar widget. | |
tspacer * | list () |
Returns the spacer widget which is used to reserve space of the real list. | |
const tspacer * | list () const |
Returns the spacer widget which is used to reserve space of the real list. | |
const std::string & | get_control_type () const |
Inherited from tcontrol. | |
Private Attributes | |
tstate | state_ |
tbuilder_grid * | list_builder_ |
It's possible to let the engine build the contents, we need the builder in that case. | |
bool | assume_fixed_row_size_ |
unsigned | selected_row_ |
The (lastly) selected row. | |
unsigned | selection_count_ |
Number of items selected. | |
bool | row_select_ |
Select per cell or an entire row. | |
bool | must_select_ |
At least 1 item must be selected. | |
bool | multi_select_ |
Multiple items can be selected. | |
SDL_Rect | list_rect_ |
The sizes of the spacer. | |
surface | list_background_ |
The background of the list, needed for redrawing. | |
tpoint | best_spacer_size_ |
The best size for the spacer, if not set it's calculated. | |
std::vector< trow > | rows_ |
Friends | |
class | tbuilder_listbox |
Classes | |
class | trow |
Definition at line 34 of file listbox.hpp.
enum gui2::tlistbox::tstate [private] |
Note the order of the states must be the same as defined in settings.hpp.
Definition at line 147 of file listbox.hpp.
gui2::tlistbox::tlistbox | ( | ) |
Definition at line 74 of file listbox.cpp.
void gui2::tlistbox::set_active | ( | const bool | active | ) | [inline, virtual] |
Sets the control in the active state, when inactive a control can't be used and doesn't react to events.
(Note read-only for a ttext_ is a different state.)
Implements gui2::tcontrol.
Definition at line 42 of file listbox.hpp.
References DISABLED, ENABLED, and set_state().
bool gui2::tlistbox::get_active | ( | ) | const [inline, virtual] |
Gets the active state of the control.
Implements gui2::tcontrol.
Definition at line 43 of file listbox.hpp.
unsigned gui2::tlistbox::get_state | ( | ) | const [inline, virtual] |
Returns the id of the state, which is also the index for the canvas.
Implements gui2::tcontrol.
Definition at line 44 of file listbox.hpp.
References state_.
bool gui2::tlistbox::has_vertical_scrollbar | ( | ) | const [inline, virtual] |
void gui2::tlistbox::list_item_selected | ( | twidget * | caller | ) |
When an item in the list is selected by the user we need to update the state.
We installed a callback handler which calls us.
Definition at line 91 of file listbox.cpp.
References gui2::tscrollbar_::get_item_position(), gui2::tscrollbar_::get_visible_items(), gui2::tcontainer_::grid(), gui2::tcontainer_::has_widget(), rows_, scrollbar(), select_row(), and gui2::tselectable_::set_selected().
Referenced by gui2::callback_select_list_item().
void gui2::tlistbox::scrollbar_moved | ( | twidget * | ) | [inline] |
Callback when the scrollbar moves.
Definition at line 59 of file listbox.hpp.
References gui2::twidget::set_dirty(), and set_scrollbar_button_status().
Referenced by gui2::callback_scrollbar().
void gui2::tlistbox::scrollbar_click | ( | twidget * | caller | ) |
When an item scrollbar control button is clicked we need to move the scrollbar and update the list.
Definition at line 115 of file listbox.cpp.
References gui2::tscrollbar_::BEGIN, gui2::tscrollbar_::END, gui2::tscrollbar_::HALF_JUMP_BACKWARDS, gui2::tscrollbar_::HALF_JUMP_FORWARD, gui2::twidget::id(), gui2::tscrollbar_::ITEM_BACKWARDS, gui2::tscrollbar_::ITEM_FORWARD, gui2::tscrollbar_::JUMP_BACKWARDS, gui2::tscrollbar_::JUMP_FORWARD, gui2::tscrollbar_::scroll(), scrollbar(), and set_scrollbar_button_status().
Referenced by gui2::callback_scrollbar_button().
void gui2::tlistbox::finalize_setup | ( | ) |
The builder needs to call us so we can write in the proper callbacks.
Definition at line 140 of file listbox.cpp.
References gui2::callback_scrollbar(), gui2::callback_scrollbar_button(), gui2::callback_select_list_item(), gui2::tcontainer_::find_widget(), gui2::tgrid::get_cols(), gui2::tgrid::get_rows(), gui2::tcontainer_::grid(), list(), name, scrollbar(), gui2::tbutton::set_callback_mouse_left_click(), gui2::ttoggle_button::set_callback_mouse_left_click(), gui2::tscrollbar_::set_callback_positioner_move(), and gui2::tgrid::widget().
Referenced by gui2::tbuilder_listbox::build().
void gui2::tlistbox::set_list_builder | ( | tbuilder_grid * | list_builder | ) | [inline] |
Definition at line 71 of file listbox.hpp.
References list_builder_.
Referenced by gui2::tbuilder_listbox::build().
void gui2::tlistbox::set_assume_fixed_row_size | ( | bool | assume = true |
) | [inline] |
Definition at line 74 of file listbox.hpp.
References assume_fixed_row_size_.
Referenced by gui2::tbuilder_listbox::build().
tpoint gui2::tlistbox::get_best_size | ( | ) | const [virtual] |
Inherited from tcontainer.
Reimplemented from gui2::tcontainer_.
Definition at line 243 of file listbox.cpp.
References best_spacer_size_, gui2::tcontainer_::get_best_size(), gui2::tgrid::get_best_size(), gui2::tlistbox::trow::grid(), list(), rows_, gui2::tpoint::x, and gui2::tpoint::y.
Referenced by set_size().
void gui2::tlistbox::draw | ( | surface & | surface | ) | [virtual] |
Inherited from tcontainer.
Reimplemented from gui2::tcontainer_.
Definition at line 275 of file listbox.cpp.
References surface::assign(), blit_surface(), gui2::tlistbox::trow::canvas(), gui2::twidget::dirty(), gui2::tgrid::draw(), cursor::draw(), gui2::tlistbox::trow::get_height(), gui2::tscrollbar_::get_item_position(), gui2::tscrollbar_::get_visible_items(), gui2::tlistbox::trow::grid(), list_background_, list_rect_, rect, gui2::restore_background(), rows_, gui2::save_background(), and scrollbar().
void gui2::tlistbox::set_size | ( | const SDL_Rect & | rect | ) | [virtual] |
Inherited from tcontainer.
Reimplemented from gui2::tcontainer_.
Definition at line 307 of file listbox.cpp.
References surface::assign(), assume_fixed_row_size_, best_spacer_size_, gui2::tlistbox::trow::canvas(), gui2::create_rect(), gui2::tgrid::get_best_size(), gui2::tspacer::get_best_size(), get_best_size(), gui2::twidget::get_rect(), gui2::tlistbox::trow::grid(), list(), list_rect_, rows, rows_, scrollbar(), gui2::tlistbox::trow::set_height(), set_scrollbar_button_status(), gui2::tgrid::set_size(), gui2::tcontainer_::set_size(), gui2::tscrollbar_::set_visible_items(), and gui2::tpoint::y.
twidget * gui2::tlistbox::find_widget | ( | const tpoint & | coordinate, | |
const bool | must_be_active | |||
) | [virtual] |
Inherited from tcontainer.
Reimplemented from gui2::tcontainer_.
Definition at line 361 of file listbox.cpp.
References gui2::tgrid::find_widget(), gui2::tcontainer_::find_widget(), gui2::tlistbox::trow::get_height(), gui2::tscrollbar_::get_item_position(), gui2::tscrollbar_::get_visible_items(), gui2::tlistbox::trow::grid(), gui2::twidget::id(), list_rect_, rows_, scrollbar(), gui2::tpoint::x, and gui2::tpoint::y.
const twidget * gui2::tlistbox::find_widget | ( | const tpoint & | coordinate, | |
const bool | must_be_active | |||
) | const [virtual] |
Inherited from tcontainer.
Reimplemented from gui2::tcontainer_.
Definition at line 387 of file listbox.cpp.
References gui2::tgrid::find_widget(), gui2::tcontainer_::find_widget(), gui2::tlistbox::trow::get_height(), gui2::tscrollbar_::get_item_position(), gui2::tscrollbar_::get_visible_items(), gui2::tlistbox::trow::grid(), gui2::twidget::id(), list_rect_, rows_, scrollbar(), gui2::tpoint::x, and gui2::tpoint::y.
void gui2::tlistbox::add_item | ( | const t_string & | label | ) |
Adds an item to the list, it requires the builder_list to be defined.
NOTE this is for a listbox with one item per row, for multiple items there will be a version with gets a vector with values. Probably there also will be a version which gets the name of an image next to the label so we can define lists even easier.
Probably the hardcoded list will disappear as well at some point
Definition at line 413 of file listbox.cpp.
References get_item_count(), gui2::tlistbox::trow::grid(), list_builder_, must_select_, rows_, scrollbar(), select_row(), selection_count_, gui2::tscrollbar_::set_item_count(), gui2::twidget::set_parent(), and set_scrollbar_button_status().
Referenced by gui2::tmp_method_selection::show(), and gui2::tlanguage_selection::show().
unsigned gui2::tlistbox::get_item_count | ( | ) | const [inline] |
Definition at line 111 of file listbox.hpp.
References rows_.
Referenced by add_item(), select_row(), set_row_active(), and gui2::tlanguage_selection::show().
bool gui2::tlistbox::select_row | ( | const unsigned | row, | |
const bool | select = true | |||
) |
Selects an entire row.
row | The row to (de)select. | |
select | true select, false deselect. |
Definition at line 465 of file listbox.cpp.
References get_item_count(), multi_select_, must_select_, rows_, selected_row_, and selection_count_.
Referenced by add_item(), list_item_selected(), gui2::tmp_method_selection::show(), and gui2::tlanguage_selection::show().
unsigned gui2::tlistbox::get_selected_row | ( | ) | const [inline] |
Definition at line 124 of file listbox.hpp.
References selected_row_.
Referenced by gui2::tmp_method_selection::show(), and gui2::tlanguage_selection::show().
void gui2::tlistbox::set_row_active | ( | const unsigned | row, | |
const bool | active | |||
) |
Makes a row active or inactive.
NOTE this doesn't change the select status of the row.
row | The row to (de)activate. | |
select | true activate, false deactivate. |
Definition at line 495 of file listbox.cpp.
References get_item_count(), gui2::tcontainer_::grid(), and rows_.
Referenced by gui2::tlanguage_selection::show().
void gui2::tlistbox::set_scrollbar_button_status | ( | ) | [private] |
Sets the status of the scrollbar buttons.
This is needed after the scrollbar moves so the status of the buttons will be active or inactive as needed.
Definition at line 205 of file listbox.cpp.
References gui2::tcontainer_::find_widget(), name, scrollbar(), gui2::tscrollbar_::set_active(), and gui2::tbutton::set_active().
Referenced by add_item(), scrollbar_click(), scrollbar_moved(), and set_size().
void gui2::tlistbox::set_state | ( | tstate | state | ) | [inline, private] |
tscrollbar_ * gui2::tlistbox::scrollbar | ( | ) | [private] |
Returns the scrollbar widget.
Definition at line 431 of file listbox.cpp.
References gui2::tcontainer_::find_widget().
Referenced by add_item(), draw(), finalize_setup(), find_widget(), list_item_selected(), scrollbar_click(), set_scrollbar_button_status(), and set_size().
const tscrollbar_ * gui2::tlistbox::scrollbar | ( | ) | const [private] |
Returns the scrollbar widget.
Definition at line 440 of file listbox.cpp.
References gui2::tcontainer_::find_widget().
tspacer * gui2::tlistbox::list | ( | ) | [private] |
Returns the spacer widget which is used to reserve space of the real list.
Definition at line 449 of file listbox.cpp.
References gui2::tcontainer_::find_widget().
Referenced by finalize_setup(), get_best_size(), list(), and set_size().
const tspacer * gui2::tlistbox::list | ( | ) | const [private] |
Returns the spacer widget which is used to reserve space of the real list.
Definition at line 457 of file listbox.cpp.
References gui2::tcontainer_::find_widget(), and list().
const std::string& gui2::tlistbox::get_control_type | ( | ) | const [inline, private, virtual] |
Inherited from tcontrol.
Implements gui2::tcontrol.
Definition at line 170 of file listbox.hpp.
References type.
friend class tbuilder_listbox [friend] |
Definition at line 36 of file listbox.hpp.
tstate gui2::tlistbox::state_ [private] |
tbuilder_grid* gui2::tlistbox::list_builder_ [private] |
It's possible to let the engine build the contents, we need the builder in that case.
Definition at line 153 of file listbox.hpp.
Referenced by add_item(), and set_list_builder().
bool gui2::tlistbox::assume_fixed_row_size_ [private] |
Definition at line 167 of file listbox.hpp.
Referenced by set_assume_fixed_row_size(), and set_size().
unsigned gui2::tlistbox::selected_row_ [private] |
The (lastly) selected row.
Definition at line 174 of file listbox.hpp.
Referenced by get_selected_row(), and select_row().
unsigned gui2::tlistbox::selection_count_ [private] |
Number of items selected.
Definition at line 177 of file listbox.hpp.
Referenced by add_item(), and select_row().
bool gui2::tlistbox::row_select_ [private] |
bool gui2::tlistbox::must_select_ [private] |
At least 1 item must be selected.
Definition at line 183 of file listbox.hpp.
Referenced by add_item(), and select_row().
bool gui2::tlistbox::multi_select_ [private] |
Multiple items can be selected.
Definition at line 186 of file listbox.hpp.
Referenced by select_row().
SDL_Rect gui2::tlistbox::list_rect_ [private] |
The sizes of the spacer.
Definition at line 189 of file listbox.hpp.
Referenced by draw(), find_widget(), and set_size().
surface gui2::tlistbox::list_background_ [private] |
The background of the list, needed for redrawing.
Definition at line 192 of file listbox.hpp.
Referenced by draw().
tpoint gui2::tlistbox::best_spacer_size_ [private] |
The best size for the spacer, if not set it's calculated.
Definition at line 195 of file listbox.hpp.
Referenced by get_best_size(), and set_size().
std::vector<trow> gui2::tlistbox::rows_ [private] |
Definition at line 229 of file listbox.hpp.
Referenced by add_item(), draw(), find_widget(), get_best_size(), get_item_count(), list_item_selected(), select_row(), set_row_active(), and set_size().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |