The Battle for Wesnoth  1.15.0-dev
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gui2::generator< minimum_selection, maximum_selection, my_placement, select_action > Class Template Reference

Basic template class to generate new items. More...

#include <generator_private.hpp>

Inheritance diagram for gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >:
Inheritance graph

Classes

struct  calculate_order_helper
 
struct  child
 Definition of an item. More...
 

Public Member Functions

 generator ()
 
 ~generator ()
 
void delete_item (const unsigned index) override
 Inherited from generator_base. More...
 
void clear () override
 Inherited from generator_base. More...
 
void select_item (const unsigned index, const bool select=true) override
 Inherited from generator_base. More...
 
bool is_selected (const unsigned index) const override
 Inherited from generator_base. More...
 
void set_item_shown (const unsigned index, const bool show) override
 Inherited from generator_base. More...
 
virtual bool get_item_shown (const unsigned index) const override
 Inherited from generator_base. More...
 
unsigned get_item_count () const override
 Inherited from generator_base. More...
 
unsigned get_selected_item_count () const override
 Inherited from generator_base. More...
 
int get_selected_item () const override
 Inherited from generator_base. More...
 
griditem (const unsigned index) override
 Inherited from generator_base. More...
 
const griditem (const unsigned index) const override
 Inherited from generator_base. More...
 
griditem_ordered (const unsigned index) override
 Inherited from generator_base. More...
 
const griditem_ordered (const unsigned index) const override
 Inherited from generator_base. More...
 
gridcreate_item (const int index, builder_grid_const_ptr list_builder, const string_map &item_data, const std::function< void(widget &)> &callback) override
 Inherited from generator_base. More...
 
gridcreate_item (const int index, builder_grid_const_ptr list_builder, const std::map< std::string, string_map > &item_data, const std::function< void(widget &)> &callback) override
 Inherited from generator_base. More...
 
virtual void create_items (const int index, builder_grid_const_ptr list_builder, const std::vector< std::map< std::string, string_map >> &data, const std::function< void(widget &)> &callback) override
 Inherited from generator_base. More...
 
virtual void create_items (const int index, builder_grid_const_ptr list_builder, const std::vector< string_map > &data, const std::function< void(widget &)> &callback) override
 Inherited from generator_base. More...
 
virtual void layout_initialize (const bool full_initialization) override
 See widget::layout_initialize. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See widget::request_reduce_width. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See widget::request_reduce_height. More...
 
virtual point calculate_best_size () const override
 See widget::calculate_best_size. More...
 
virtual void place (const point &origin, const point &size) override
 See widget::place. More...
 
virtual void set_origin (const point &origin) override
 See widget::set_origin. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle) override
 See widget::set_visible_rectangle. More...
 
virtual void impl_draw_children () override
 See widget::impl_draw_children. More...
 
virtual widgetfind_at (const point &coordinate, const bool must_be_active) override
 See widget::find_at. More...
 
virtual const widgetfind_at (const point &coordinate, const bool must_be_active) const override
 See widget::find_at. More...
 
bool disable_click_dismiss () const override
 See widget::disable_click_dismiss. More...
 
virtual iteration::walker_ptr create_walker () override
 See widget::create_walker. More...
 
void handle_key_up_arrow (SDL_Keymod modifier, bool &handled) override
 Inherited from generator_base. More...
 
void handle_key_down_arrow (SDL_Keymod modifier, bool &handled) override
 Inherited from generator_base. More...
 
void handle_key_left_arrow (SDL_Keymod modifier, bool &handled) override
 Inherited from generator_base. More...
 
void handle_key_right_arrow (SDL_Keymod modifier, bool &handled) override
 Inherited from generator_base. More...
 

Protected Member Functions

void do_select_item (const unsigned index) override
 Inherited from generator_base. More...
 
void do_deselect_item (const unsigned index) override
 Inherited from generator_base. More...
 

Private Types

typedef std::vector< std::unique_ptr< child > > child_list
 The items in the generator. More...
 
typedef std::function< bool(unsigned, unsigned)> order_func
 

Private Member Functions

virtual void set_order (const order_func &order) override
 
virtual unsigned get_ordered_index (unsigned index) const override
 
virtual unsigned get_item_at_ordered (unsigned index_ordered) const override
 
void calculate_order () const
 
void set_item_selected (const unsigned index, const bool selected)
 Sets the selected state of an item. More...
 
template<class T >
void impl_create_items (const int index, builder_grid_const_ptr list_builder, const std::vector< T > &data, const std::function< void(widget &)> &callback)
 Helper function for create_items(). More...
 
void init (grid *grid, const std::map< std::string, string_map > &data, const std::function< void(widget &)> &callback)
 Helper function to initialize a grid. More...
 

Private Attributes

unsigned selected_item_count_
 The number of selected items. More...
 
int last_selected_item_
 The last item selected. More...
 
child_list items_
 
std::vector< std::size_t > order_
 the elements of order_ are indexes to items_ More...
 
bool order_dirty_
 whether need to recalculate order_dirty_ More...
 
order_func order_func_
 

Detailed Description

template<class minimum_selection, class maximum_selection, class my_placement, class select_action>
class gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >

Basic template class to generate new items.

The class is policy based so the behavior can be selected.

Definition at line 555 of file generator_private.hpp.

Member Typedef Documentation

◆ child_list

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
typedef std::vector<std::unique_ptr<child> > gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::child_list
private

The items in the generator.

Definition at line 963 of file generator_private.hpp.

◆ order_func

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
typedef std::function<bool(unsigned, unsigned)> gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::order_func
private

Definition at line 971 of file generator_private.hpp.

Constructor & Destructor Documentation

◆ generator()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::generator ( )
inline

Definition at line 561 of file generator_private.hpp.

◆ ~generator()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::~generator ( )
inline

Definition at line 575 of file generator_private.hpp.

References gui2::generator_base::clear().

Member Function Documentation

◆ calculate_best_size()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual point gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::calculate_best_size ( ) const
inlineoverridevirtual

See widget::calculate_best_size.

Definition at line 800 of file generator_private.hpp.

◆ calculate_order()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::calculate_order ( ) const
inlineprivate

Definition at line 1011 of file generator_private.hpp.

References i.

◆ clear()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::clear ( )
inlineoverride

Inherited from generator_base.

Definition at line 601 of file generator_private.hpp.

◆ create_item() [1/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::create_item ( const int  index,
builder_grid_const_ptr  list_builder,
const string_map item_data,
const std::function< void(widget &)> &  callback 
)
inlineoverride

◆ create_item() [2/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::create_item ( const int  index,
builder_grid_const_ptr  list_builder,
const std::map< std::string, string_map > &  item_data,
const std::function< void(widget &)> &  callback 
)
inlineoverride

◆ create_items() [1/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::create_items ( const int  index,
builder_grid_const_ptr  list_builder,
const std::vector< std::map< std::string, string_map >> &  data,
const std::function< void(widget &)> &  callback 
)
inlineoverridevirtual

Inherited from generator_base.

Definition at line 760 of file generator_private.hpp.

◆ create_items() [2/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::create_items ( const int  index,
builder_grid_const_ptr  list_builder,
const std::vector< string_map > &  data,
const std::function< void(widget &)> &  callback 
)
inlineoverridevirtual

Inherited from generator_base.

Definition at line 769 of file generator_private.hpp.

◆ create_walker()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual iteration::walker_ptr gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::create_walker ( )
inlineoverridevirtual

See widget::create_walker.

Todo:
Implement properly.

Definition at line 874 of file generator_private.hpp.

◆ delete_item()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::delete_item ( const unsigned  index)
inlineoverride

◆ disable_click_dismiss()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
bool gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::disable_click_dismiss ( ) const
inlineoverride

◆ do_deselect_item()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::do_deselect_item ( const unsigned  index)
inlineoverrideprotected

Inherited from generator_base.

Definition at line 916 of file generator_private.hpp.

◆ do_select_item()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::do_select_item ( const unsigned  index)
inlineoverrideprotected

Inherited from generator_base.

Definition at line 907 of file generator_private.hpp.

◆ find_at() [1/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual widget* gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::find_at ( const point coordinate,
const bool  must_be_active 
)
inlineoverridevirtual

See widget::find_at.

Definition at line 846 of file generator_private.hpp.

◆ find_at() [2/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual const widget* gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::find_at ( const point coordinate,
const bool  must_be_active 
) const
inlineoverridevirtual

See widget::find_at.

Definition at line 852 of file generator_private.hpp.

◆ get_item_at_ordered()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual unsigned gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_item_at_ordered ( unsigned  index_ordered) const
inlineoverrideprivatevirtual

Definition at line 1004 of file generator_private.hpp.

◆ get_item_count()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
unsigned gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_item_count ( ) const
inlineoverride

Inherited from generator_base.

Definition at line 654 of file generator_private.hpp.

◆ get_item_shown()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual bool gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_item_shown ( const unsigned  index) const
inlineoverridevirtual

Inherited from generator_base.

Definition at line 647 of file generator_private.hpp.

References utf8::index(), and gui2::widget::invisible.

◆ get_ordered_index()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual unsigned gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_ordered_index ( unsigned  index) const
inlineoverrideprivatevirtual

Definition at line 997 of file generator_private.hpp.

References utf8::index().

◆ get_selected_item()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
int gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_selected_item ( ) const
inlineoverride

Inherited from generator_base.

Definition at line 666 of file generator_private.hpp.

References FAIL_WITH_DEV_MESSAGE, and i.

◆ get_selected_item_count()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
unsigned gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::get_selected_item_count ( ) const
inlineoverride

Inherited from generator_base.

Definition at line 660 of file generator_private.hpp.

◆ handle_key_down_arrow()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::handle_key_down_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
inlineoverride

Inherited from generator_base.

Definition at line 888 of file generator_private.hpp.

◆ handle_key_left_arrow()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::handle_key_left_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
inlineoverride

Inherited from generator_base.

Definition at line 894 of file generator_private.hpp.

◆ handle_key_right_arrow()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::handle_key_right_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
inlineoverride

Inherited from generator_base.

Definition at line 900 of file generator_private.hpp.

◆ handle_key_up_arrow()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::handle_key_up_arrow ( SDL_Keymod  modifier,
bool &  handled 
)
inlineoverride

Inherited from generator_base.

Definition at line 882 of file generator_private.hpp.

◆ impl_create_items()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
template<class T >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::impl_create_items ( const int  index,
builder_grid_const_ptr  list_builder,
const std::vector< T > &  data,
const std::function< void(widget &)> &  callback 
)
inlineprivate

Helper function for create_items().

Template Parameters
TType of the data, this should be one of the valid parameters for create_item().
Parameters
indexThe item before which to add the new item, 0 == begin, -1 == end.
list_builderA grid builder that's will build the contents of the new item.
dataThe data to initialize the parameters of the new item.
callbackThe callback function to call when an item in the grid is (de)selected.

Definition at line 1065 of file generator_private.hpp.

References gui2::policy::minimum_selection::one_item::create_item(), i, and utf8::index().

◆ impl_draw_children()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::impl_draw_children ( )
inlineoverridevirtual

◆ init()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::init ( grid grid,
const std::map< std::string, string_map > &  data,
const std::function< void(widget &)> &  callback 
)
inlineprivate

Helper function to initialize a grid.

The actual part is implemented in select_action, see those implementations for more information.

Parameters
gridThe grid to initialize.
dataThe data to initialize the parameters of the new item.
callbackThe callback function to call when an item in the grid is (de)selected.

Definition at line 1092 of file generator_private.hpp.

References utils::detail::init, and gui2::widget::set_parent().

◆ is_selected()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
bool gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::is_selected ( const unsigned  index) const
inlineoverride

Inherited from generator_base.

Definition at line 626 of file generator_private.hpp.

◆ item() [1/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::item ( const unsigned  index)
inlineoverride

Inherited from generator_base.

Definition at line 687 of file generator_private.hpp.

References utf8::index().

◆ item() [2/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
const grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::item ( const unsigned  index) const
inlineoverride

Inherited from generator_base.

Definition at line 694 of file generator_private.hpp.

References utf8::index().

◆ item_ordered() [1/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::item_ordered ( const unsigned  index)
inlineoverride

Inherited from generator_base.

Definition at line 701 of file generator_private.hpp.

References utf8::index().

◆ item_ordered() [2/2]

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
const grid& gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::item_ordered ( const unsigned  index) const
inlineoverride

Inherited from generator_base.

Definition at line 709 of file generator_private.hpp.

References utf8::index().

◆ layout_initialize()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::layout_initialize ( const bool  full_initialization)
inlineoverridevirtual

◆ place()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::place ( const point origin,
const point size 
)
inlineoverridevirtual

See widget::place.

Definition at line 806 of file generator_private.hpp.

References gui2::widget::place().

◆ request_reduce_height()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::request_reduce_height ( const unsigned  maximum_height)
inlineoverridevirtual

See widget::request_reduce_height.

Definition at line 794 of file generator_private.hpp.

◆ request_reduce_width()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::request_reduce_width ( const unsigned  maximum_width)
inlineoverridevirtual

See widget::request_reduce_width.

Definition at line 788 of file generator_private.hpp.

◆ select_item()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::select_item ( const unsigned  index,
const bool  select = true 
)
inlineoverride

◆ set_item_selected()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_item_selected ( const unsigned  index,
const bool  selected 
)
inlineprivate

Sets the selected state of an item.

Parameters
indexThe item to modify.
selectedSelect or deselect.

Definition at line 1041 of file generator_private.hpp.

References utf8::index().

◆ set_item_shown()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_item_shown ( const unsigned  index,
const bool  show 
)
inlineoverride

◆ set_order()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_order ( const order_func order)
inlineoverrideprivatevirtual

Definition at line 974 of file generator_private.hpp.

◆ set_origin()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_origin ( const point origin)
inlineoverridevirtual

See widget::set_origin.

Definition at line 815 of file generator_private.hpp.

References gui2::widget::set_origin().

◆ set_visible_rectangle()

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
virtual void gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_visible_rectangle ( const SDL_Rect &  rectangle)
inlineoverridevirtual

See widget::set_visible_rectangle.

Definition at line 824 of file generator_private.hpp.

Member Data Documentation

◆ items_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
child_list gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::items_
private

Definition at line 964 of file generator_private.hpp.

◆ last_selected_item_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
int gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::last_selected_item_
private

The last item selected.

Definition at line 960 of file generator_private.hpp.

◆ order_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
std::vector<std::size_t> gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::order_
mutableprivate

the elements of order_ are indexes to items_

Definition at line 967 of file generator_private.hpp.

◆ order_dirty_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
bool gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::order_dirty_
mutableprivate

whether need to recalculate order_dirty_

Definition at line 969 of file generator_private.hpp.

◆ order_func_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
order_func gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::order_func_
private

Definition at line 972 of file generator_private.hpp.

◆ selected_item_count_

template<class minimum_selection , class maximum_selection , class my_placement , class select_action >
unsigned gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::selected_item_count_
private

The number of selected items.

Definition at line 957 of file generator_private.hpp.


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