15 #ifndef GUI_WIDGETS_GENERATOR_PRIVATE_HPP_INCLUDED
16 #define GUI_WIDGETS_GENERATOR_PRIVATE_HPP_INCLUDED
38 namespace minimum_selection
126 namespace maximum_selection
227 const bool must_be_active)
override;
231 const bool must_be_active)
const override;
302 const bool must_be_active)
override;
306 const bool must_be_active)
const override;
403 const bool )
override
411 const bool )
const override
481 const bool must_be_active)
override;
485 const bool must_be_active)
const override;
492 const bool must_be_active)
const override;
529 namespace select_action
547 const std::map<std::string /* widget id */, string_map>&
data,
548 const std::function<
void(
twidget&)>& callback);
571 const std::map<std::string /* widget id */, string_map>&
data,
572 const std::function<
void(
twidget&)>& callback);
586 template <
class minimum_selection,
587 class maximum_selection,
591 public maximum_selection,
597 : minimum_selection()
598 , maximum_selection()
620 assert(index <
items_.size());
629 minimum_selection::delete_item(index);
650 assert(index <
items_.size());
653 maximum_selection::select_item(index,
true);
656 if(!minimum_selection::deselect_item(index)) {
659 select_action::select(
item(index),
true);
667 assert(index <
items_.size());
668 return (*
items_[index]).selected;
674 assert(index <
items_.size());
675 if(
items_[index]->shown != show) {
684 minimum_selection::set_item_shown(index, show);
691 assert(index <
items_.size());
721 for(
size_t i = 0;
i <
items_.size(); ++
i) {
733 assert(index <
items_.size());
740 assert(index <
items_.size());
748 assert(index <
items_.size());
756 assert(index <
items_.size());
765 const std::function<
void(
twidget&)>& callback)
767 std::map<std::string, string_map>
data;
769 data.insert(std::make_pair(
"", item_data));
770 return create_item(index, list_builder, data, callback);
777 const std::map<std::string /* widget id */, string_map>& item_data,
778 const std::function<
void(
twidget&)>& callback)
780 assert(list_builder);
781 assert(index == -1 || static_cast<unsigned>(index) <
items_.size());
784 list_builder->build(&item->grid);
785 init(&item->grid, item_data, callback);
787 const unsigned item_index = index == -1 ?
items_.size() :
index;
791 minimum_selection::create_item(item_index);
792 placement::create_item(item_index);
794 select_action::select(item->grid,
false);
803 const std::vector<std::map<std::string /*widget id*/, string_map> >&
805 const std::function<
void(
twidget&)>& callback)
813 const std::vector<string_map>&
data,
814 const std::function<
void(
twidget&)>& callback)
835 placement::request_reduce_width(maximum_width);
841 placement::request_reduce_height(maximum_height);
847 return placement::calculate_best_size();
856 placement::place(origin, size);
865 placement::set_origin(origin);
871 placement::set_visible_rectangle(rectangle);
877 int y_offset)
override
895 const std::vector<twidget*>& call_stack)
override
899 std::vector<twidget*> child_call_stack = call_stack;
906 const bool must_be_active)
override
908 return placement::find_at(coordinate, must_be_active);
913 const bool must_be_active)
const override
915 return placement::find_at(coordinate, must_be_active);
945 placement::handle_key_up_arrow(modifier, handled);
951 placement::handle_key_down_arrow(modifier, handled);
957 placement::handle_key_left_arrow(modifier, handled);
963 placement::handle_key_right_arrow(modifier, handled);
970 assert(index <
items_.size());
979 assert(index <
items_.size());
1035 order_func_ =
order;
1036 order_dirty_ =
true;
1037 this->set_is_dirty(
true);
1046 : order_func_(order_func)
1059 assert(index < items_.size());
1061 return items_[
index]->ordered_index;
1066 assert(index_ordered < items_.size());
1068 return order_[index_ordered];
1074 if(order_.size() != items_.size()) {
1075 order_.resize(items_.size());
1076 for(
size_t i = 0;
i < items_.size(); ++
i) {
1083 for(
size_t i = 0;
i < order_.size(); ++
i) {
1084 items_[order_[
i]]->ordered_index =
i;
1087 order_dirty_ =
false;
1090 assert(order_.size() == items_.size());
1101 assert(index < items_.size());
1103 (*items_[
index]).selected = selected;
1104 select_action::select((*items_[index]).
grid, selected);
1125 const std::vector<T>& data,
1126 const std::function<
void(
twidget&)>& callback)
1129 for(
const auto & item_data : data)
1131 create_item(i, list_builder, item_data, callback);
1151 const std::map<std::string /* widget id */, string_map>& data,
1152 const std::function<
void(
twidget&)>& callback)
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
void impl_create_items(const int index, tbuilder_grid_const_ptr list_builder, const std::vector< T > &data, const std::function< void(twidget &)> &callback)
Helper function for create_items().
void select(tgrid &grid, const bool select)
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
May select only one item.
Abstract base class for the generator.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
virtual void set_origin(const tpoint &) override
See twidget::set_origin.
void handle_key_left_arrow(SDLMod, bool &)
Inherited from tgenerator_.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
const tgrid & item_ordered(const unsigned index) const
Inherited from tgenerator_.
GLuint GLdouble GLdouble GLint GLint order
void handle_key_up_arrow(SDLMod, bool &)
Inherited from tgenerator_.
void set_visible_rectangle(const SDL_Rect &)
See thorizontal_list::set_visible_rectangle().
virtual unsigned get_selected_item_count() const =0
Returns the number of selected items.
void create_item(const unsigned)
See thorizontal_list::create_item().
Select the item, this requires the grid to contain a tselectable_.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
tgrid & create_item(const int index, tbuilder_grid_const_ptr list_builder, const string_map &item_data, const std::function< void(twidget &)> &callback)
Inherited from tgenerator_.
virtual unsigned get_ordered_index(unsigned index) const
Must select at least one item.
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
unsigned get_selected_item_count() const
Inherited from tgenerator_.
virtual int get_selected_item() const =0
Returns the selected item.
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
void set_item_shown(const unsigned index, const bool show)
Inherited from tgenerator_.
tgrid grid
The grid containing the widgets.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
tgrid & item_ordered(const unsigned index)
Inherited from tgenerator_.
tgrid & create_item(const int index, tbuilder_grid_const_ptr list_builder, const std::map< std::string, string_map > &item_data, const std::function< void(twidget &)> &callback)
Inherited from tgenerator_.
const std::vector< std::string > items
virtual const twidget * find_at(const tpoint &, const bool) const override
See twidget::find_at.
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
std::vector< size_t > order_
the elements of order_ are indexes to items_
virtual bool get_item_shown(const unsigned index) const
Inherited from tgenerator_.
calculate_order_helper(const torder_func &order_func, const titems &items)
bool order_dirty_
whether need to recalculate order_dirty_
void select_item(const unsigned index, const bool select) override
See tone::select_item().
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
void set_visible_rectangle(const SDL_Rect &rectangle)
See thorizontal_list::set_visible_rectangle().
void set_visible_rectangle(const SDL_Rect &rectangle)
Sets the visible rectangle of the generator.
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
unsigned selected_item_count_
The number of selected items.
int last_selected_item_
The last item selected.
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
base class of top level items, the only item which needs to store the final canvases to draw on ...
A class inherited from ttext_box that displays its input as stars.
virtual void request_reduce_width(const unsigned) override
See twidget::request_reduce_width.
GLdouble GLdouble GLdouble b
void set_item_selected(const unsigned index, const bool selected)
Sets the selected state of an item.
bool placed_
Has the grid already been placed?
bool is_selected(const unsigned index) const
Inherited from tgenerator_.
void select_item(const unsigned index, const bool select) override
Called when an item is selected.
bool deselect_item(const unsigned index)
See minimum_selection::tone::deselect_item()
void handle_key_right_arrow(SDLMod, bool &)
Inherited from tgenerator_.
void delete_item(const unsigned index)
Called just before an item is deleted.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
void delete_item(const unsigned index)
See minimum_selection::tone::delete_item()
void create_item(const unsigned)
See minimum_selection::tone::create_item()
virtual void create_items(const int index, tbuilder_grid_const_ptr list_builder, const std::vector< std::map< std::string, string_map > > &data, const std::function< void(twidget &)> &callback)
Inherited from tgenerator_.
void create_item(const unsigned index)
See thorizontal_list::create_item().
void handle_key_up_arrow(SDLMod, bool &)
Inherited from tgenerator_.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
virtual bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
void handle_key_right_arrow(SDLMod, bool &)
Inherited from tgenerator_.
virtual twidget * find_at(const tpoint &, const bool) override
See twidget::find_at.
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
virtual void request_reduce_height(const unsigned) override
See twidget::request_reduce_height.
virtual tgrid & create_item(const int index, tbuilder_grid_const_ptr list_builder, const string_map &item_data, const std::function< void(twidget &)> &callback)=0
Creates a new item.
GLboolean GLboolean GLboolean GLboolean a
Basic template class to generate new items.
virtual void place(const tpoint &, const tpoint &) override
See twidget::place.
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
bool deselect_item(const unsigned index)
Called when the users wants to deselect an item.
bool shown
Is the row shown or not.
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
virtual unsigned get_item_at_ordered(unsigned index_ordered) const
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
virtual void request_reduce_height(const unsigned maximum_height) override
See twidget::request_reduce_height.
virtual void request_reduce_height(const unsigned) override
See twidget::request_reduce_height.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
void init()
Initializes the gui subsystems.
tgrid & item(const unsigned index)
Inherited from tgenerator_.
std::map< std::string, t_string > string_map
std::vector< titem * > titems
The items in the generator.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
void show(CVideo &video, const std::string &window_id, const t_string &message, const tpoint &mouse)
Shows a tip.
void delete_item(const unsigned index)
Inherited from tgenerator_.
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
virtual void set_order(const torder_func &order) override
void handle_key_right_arrow(SDLMod, bool &)
Inherited from tgenerator_.
virtual const twidget * find_at(const tpoint &coordinate, const bool must_be_active) const override
See twidget::find_at.
void create_item(const unsigned index)
Called when an item is created.
int get_selected_item() const
Inherited from tgenerator_.
void init(tgrid *grid, const std::map< std::string, string_map > &data, const std::function< void(twidget &)> &callback)
Helper function to initialize a grid.
virtual void request_reduce_height(const unsigned) override
See twidget::request_reduce_height.
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
bool operator()(size_t a, size_t b)
No maximum amount of items to select.
bool selected
Is the item selected or not.
Places the items in a horizontal row.
std::function< bool(unsigned, unsigned)> torder_func
Places the items independent of each other.
void do_select_item(const unsigned index)
Inherited from tgenerator_.
const tgrid & item(const unsigned index) const
Inherited from tgenerator_.
void handle_key_left_arrow(SDLMod, bool &)
Inherited from tgenerator_.
void handle_key_up_arrow(SDLMod, bool &)
Inherited from tgenerator_.
Places the items in a vertical column.
virtual void do_select_item(const unsigned index)=0
Selects a not selected item.
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
void set_item_shown(const unsigned index, const bool show)
Called when an item is shown or hidden.
void calculate_order() const
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
const torder_func & order_func_
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tgenerator_.
unsigned get_item_count() const
Inherited from tgenerator_.
void create_item(const unsigned index)
Called when an item is created.
virtual void request_reduce_width(const unsigned) override
See twidget::request_reduce_width.
void handle_key_down_arrow(SDLMod, bool &)
Inherited from tgenerator_.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
void create_item(const unsigned)
See thorizontal_list::create_item().
virtual void create_items(const int index, tbuilder_grid_const_ptr list_builder, const std::vector< string_map > &data, const std::function< void(twidget &)> &callback)
Inherited from tgenerator_.
virtual void request_reduce_height(const unsigned maximum_height)
See thorizontal_list::request_reduce_height.
virtual void do_deselect_item(const unsigned index)=0
Deselects a selected item.
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
virtual void request_reduce_width(const unsigned) override
See twidget::request_reduce_width.
void handle_key_down_arrow(SDLMod, bool &)
Inherited from tgenerator_.
The walker abstract base class.
bool placed_
Has the grid already been placed?
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_children.
void set_visible_rectangle(const SDL_Rect &rectangle)
See thorizontal_list::set_visible_rectangle().
void set_item_shown(const unsigned index, const bool show)
See minimum_selection::tone::set_item_shown().
GLsizei const GLcharARB ** string
void handle_key_left_arrow(SDLMod, bool &)
Inherited from tgenerator_.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
void handle_key_down_arrow(SDLMod, bool &)
Inherited from tgenerator_.
void clear()
Inherited from tgenerator_.
void select(tgrid &grid, const bool show)
void do_deselect_item(const unsigned index)
Inherited from tgenerator_.
void select_item(const unsigned index, const bool select=true)
Inherited from tgenerator_.
Places the items in a grid.