gui2::tlistbox Class Reference

#include <listbox.hpp>

Inheritance diagram for gui2::tlistbox:

Inheritance graph
[legend]
Collaboration diagram for gui2::tlistbox:

Collaboration graph
[legend]

List of all members.

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.
twidgetfind_widget (const tpoint &coordinate, const bool must_be_active)
 Inherited from tcontainer.
const twidgetfind_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.
tspacerlist ()
 Returns the spacer widget which is used to reserve space of the real list.
const tspacerlist () 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_gridlist_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< trowrows_

Friends

class tbuilder_listbox

Classes

class  trow


Detailed Description

Todo:
list header row + footer row same width as client data cell or row select sort at some way

Definition at line 34 of file listbox.hpp.


Member Enumeration Documentation

enum gui2::tlistbox::tstate [private]

Note the order of the states must be the same as defined in settings.hpp.

Enumerator:
ENABLED 
DISABLED 
COUNT 

Definition at line 147 of file listbox.hpp.


Constructor & Destructor Documentation

gui2::tlistbox::tlistbox (  ) 

Definition at line 74 of file listbox.cpp.


Member Function Documentation

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.

References DISABLED, and state_.

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]

Inherited from twidget.

Implements gui2::tcontainer_.

Definition at line 47 of file listbox.hpp.

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  ) 

void gui2::tlistbox::finalize_setup (  ) 

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]

void gui2::tlistbox::set_size ( const SDL_Rect &  rect  )  [virtual]

twidget * gui2::tlistbox::find_widget ( const tpoint coordinate,
const bool  must_be_active 
) [virtual]

const twidget * gui2::tlistbox::find_widget ( const tpoint coordinate,
const bool  must_be_active 
) const [virtual]

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.

Parameters:
row The row to (de)select.
select true select, false deselect.
Returns:
false if deselecting wasn't allowed. true otherwise.

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.

Parameters:
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]

Definition at line 149 of file listbox.hpp.

Referenced by set_active().

tscrollbar_ * gui2::tlistbox::scrollbar (  )  [private]

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.


Friends And Related Function Documentation

friend class tbuilder_listbox [friend]

Definition at line 36 of file listbox.hpp.


Member Data Documentation

Definition at line 150 of file listbox.hpp.

Referenced by get_active(), and get_state().

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

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

Number of items selected.

Definition at line 177 of file listbox.hpp.

Referenced by add_item(), and select_row().

Select per cell or an entire row.

Definition at line 180 of file listbox.hpp.

At least 1 item must be selected.

Definition at line 183 of file listbox.hpp.

Referenced by add_item(), and select_row().

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

The background of the list, needed for redrawing.

Definition at line 192 of file listbox.hpp.

Referenced by draw().

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]


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

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs