40 namespace minimum_selection
126 namespace maximum_selection
228 virtual const widget*
find_at(
const point& coordinate,
const bool must_be_active)
const override;
300 virtual const widget*
find_at(
const point& coordinate,
const bool must_be_active)
const override;
383 const bool )
override;
388 const bool )
const override;
455 virtual const widget*
find_at(
const point& coordinate,
const bool must_be_active)
const override;
458 widget*
find(
const std::string&
id,
const bool must_be_active)
override;
461 const widget*
find(
const std::string&
id,
const bool must_be_active)
const override;
498 namespace select_action
503 void select(
grid&
grid,
const bool select);
514 void init(grid* grid,
516 const std::function<
void(
widget&)>& callback);
539 const std::function<
void(
widget&)>& callback);
553 template<
class minimum_selection,
554 class maximum_selection,
558 public maximum_selection,
564 : minimum_selection()
565 , maximum_selection()
568 , selected_item_count_(0)
569 , last_selected_item_(-1)
587 assert(index < items_.size());
596 minimum_selection::delete_item(index);
598 items_.erase(items_.begin() +
index);
607 selected_item_count_ = 0;
613 assert(index < items_.size());
616 maximum_selection::select_item(index,
true);
617 last_selected_item_ =
index;
619 if(!minimum_selection::deselect_item(index)) {
622 select_action::select(
item(index),
true);
630 assert(index < items_.size());
631 return (*items_[index]).selected;
637 assert(index < items_.size());
638 if(items_[index]->shown != show) {
644 minimum_selection::set_item_shown(index, show);
651 assert(index < items_.size());
658 return items_.size();
664 return selected_item_count_;
670 if(selected_item_count_ == 0) {
672 }
else if(last_selected_item_ != -1 && last_selected_item_ < static_cast<int>(items_.size())
673 && (*items_[last_selected_item_]).selected)
675 return last_selected_item_;
677 for(std::size_t
i = 0;
i < items_.size(); ++
i) {
678 if((*items_[
i]).selected) {
684 "No item selected.",
"selected_item_count_ was non-zero, yet no selected item was found.");
691 assert(index < items_.size());
692 return items_[
index]->child_grid;
698 assert(index < items_.size());
699 return items_[
index]->child_grid;
706 assert(index < items_.size());
707 return items_[order_[
index]]->child_grid;
714 assert(index < items_.size());
715 return items_[order_[
index]]->child_grid;
722 const std::function<
void(
widget&)>& callback)
override 726 data.emplace(
"", item_data);
727 return create_item(index, list_builder, data, callback);
734 const std::function<
void(
widget&)>& callback)
override 736 assert(index == -1 || static_cast<unsigned>(index) <= items_.size());
739 list_builder.
build(item->child_grid);
741 init(&item->child_grid, item_data, callback);
743 const unsigned item_index = index == -1 ? items_.size() :
index;
745 items_.emplace(items_.begin() + item_index,
item);
749 minimum_selection::create_item(item_index);
751 my_placement::create_item(item_index);
754 select_action::select(item->child_grid,
false);
757 return item->child_grid;
763 const std::vector<widget_data>&
data,
764 const std::function<
void(
widget&)>& callback)
override 766 impl_create_items(index, list_builder, data, callback);
772 const std::vector<widget_item>& data,
773 const std::function<
void(
widget&)>& callback)
override 775 impl_create_items(index, list_builder, data, callback);
781 for(
auto&
item : items_) {
791 my_placement::request_reduce_width(maximum_width);
797 my_placement::request_reduce_height(maximum_height);
803 return my_placement::calculate_best_size();
812 my_placement::place(origin, size);
821 my_placement::set_origin(origin);
827 my_placement::set_visible_rectangle(rectangle);
837 for(
auto index : order_) {
849 return my_placement::find_at(coordinate, must_be_active);
855 return my_placement::find_at(coordinate, must_be_active);
861 for(
auto&
item : items_) {
885 my_placement::handle_key_up_arrow(modifier, handled);
891 my_placement::handle_key_down_arrow(modifier, handled);
897 my_placement::handle_key_left_arrow(modifier, handled);
903 my_placement::handle_key_right_arrow(modifier, handled);
910 assert(index < items_.size());
912 ++selected_item_count_;
913 set_item_selected(index,
true);
919 assert(index < items_.size());
921 --selected_item_count_;
922 set_item_selected(index,
false);
975 virtual void set_order(
const order_func& order)
override 984 assert(index < items_.size());
986 return items_[
index]->ordered_index;
991 assert(index_ordered < items_.size());
993 return order_[index_ordered];
999 if(order_.size() != items_.size()) {
1000 order_.resize(items_.size());
1002 for(std::size_t
i = 0;
i < items_.size(); ++
i) {
1008 std::stable_sort(order_.begin(), order_.end(), order_func_);
1011 for(std::size_t
i = 0;
i < order_.size(); ++
i) {
1012 items_[order_[
i]]->ordered_index =
i;
1015 order_dirty_ =
false;
1017 assert(order_.size() == items_.size());
1028 assert(index < items_.size());
1030 (*items_[
index]).selected = selected;
1031 select_action::select((*items_[index]).child_grid, selected);
1052 const std::vector<T>& data,
1053 const std::function<
void(
widget&)>& callback)
1057 for(
const auto& item_data : data) {
1058 create_item(i, list_builder, item_data, callback);
1078 const std::function<
void(
widget&)>& callback)
bool shown
Is the row shown or not.
std::size_t ordered_index
virtual void handle_key_left_arrow(SDL_Keymod modifier, bool &handled)=0
Left arrow key pressed.
void create_item(const unsigned)
See minimum_selection::one_item::create_item()
unsigned get_selected_item_count() const override
Inherited from generator_base.
virtual void handle_key_up_arrow(SDL_Keymod modifier, bool &handled)=0
Up arrow key pressed.
virtual void request_reduce_width(const unsigned maximum_width) override=0
See widget::request_reduce_width.
May select only one item.
void impl_create_items(const int index, const builder_grid &list_builder, const std::vector< T > &data, const std::function< void(widget &)> &callback)
Helper function for create_items().
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
void handle_key_left_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
std::unique_ptr< class walker_base > walker_ptr
virtual widget * find_at(const point &coordinate, const bool must_be_active) override=0
See widget::find_at.
const grid & item(const unsigned index) const override
Inherited from generator_base.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
virtual void handle_key_right_arrow(SDL_Keymod modifier, bool &handled)=0
Right arrow key pressed.
virtual const widget * find_at(const point &coordinate, const bool must_be_active) const override
See widget::find_at.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
void handle_key_right_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
No maximum amount of items to select.
bool deselect_item(const unsigned index)
See minimum_selection::one_item::deselect_item()
bool placed_
Has the grid already been placed?
virtual void place(const point &origin, const point &size) override=0
See widget::place.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
bool order_dirty_
whether need to recalculate order_dirty_
void set_item_shown(const unsigned index, const bool show)
Called when an item is shown or hidden.
grid & item_ordered(const unsigned index) override
Inherited from generator_base.
int get_selected_item() const override
Inherited from generator_base.
void do_deselect_item(const unsigned index) override
Inherited from generator_base.
virtual bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
void delete_item(const unsigned index)
See minimum_selection::one_item::delete_item()
virtual void do_select_item(const unsigned index)=0
Selects a not selected item.
Places the items in a grid.
virtual void request_reduce_height(const unsigned) override
See widget::request_reduce_height.
void calculate_order() const
virtual grid & item(const unsigned index)=0
Gets the grid of an item.
void select_item(const unsigned index, const bool select) override
Called when an item is selected.
virtual void request_reduce_width(const unsigned) override
See widget::request_reduce_width.
virtual void create_items(const int index, const builder_grid &list_builder, const std::vector< widget_item > &data, const std::function< void(widget &)> &callback) override
Inherited from generator_base.
virtual unsigned get_selected_item_count() const =0
Returns the number of selected items.
void handle_key_left_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
void create_item(const unsigned index)
Called when an item is created.
void set_item_selected(const unsigned index, const bool selected)
Sets the selected state of an item.
void delete_item(const unsigned index)
Called just before an item is deleted.
void handle_key_right_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
grid & create_item(const int index, const builder_grid &list_builder, const widget_data &item_data, const std::function< void(widget &)> &callback) override
Inherited from generator_base.
const grid & item_ordered(const unsigned index) const override
Inherited from generator_base.
std::vector< std::size_t > order_
the elements of order_ are indexes to items_
virtual point calculate_best_size() const override=0
See widget::calculate_best_size.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
virtual void request_reduce_height(const unsigned maximum_height) override=0
See widget::request_reduce_height.
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
virtual void set_order(const order_func &order) override
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
std::map< std::string, t_string > widget_item
void select_item(const unsigned index, const bool select) override
See one_item::select_item().
struct utils::detail::formula_initer init
void clear() override
Inherited from generator_base.
virtual void request_reduce_width(const unsigned) override
See widget::request_reduce_width.
void init(grid *grid, const widget_data &data, const std::function< void(widget &)> &callback)
Helper function to initialize a grid.
Abstract base class for the generator.
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
virtual bool get_item_shown(const unsigned index) const override
Inherited from generator_base.
grid & item(const unsigned index) override
Inherited from generator_base.
void init()
Initializes the GUI subsystems.
Places the items independent of each other.
std::function< bool(unsigned, unsigned)> order_func
virtual void place(const point &origin, const point &size) override
See widget::place.
placement
Determines how the items are placed.
bool deselect_item(const unsigned index)
Called when the users wants to deselect an item.
void delete_item(const unsigned index) override
Inherited from generator_base.
int last_selected_item_
The last item selected.
Basic template class to generate new items.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
void handle_key_down_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
void set_item_shown(const unsigned index, const bool show) override
Inherited from generator_base.
void select(grid &grid, const bool show)
#define FAIL_WITH_DEV_MESSAGE(message, dev_message)
virtual std::unique_ptr< widget > build() const override
Inherited from builder_widget.
std::vector< std::unique_ptr< child > > child_list
The items in the generator.
Places the items in a horizontal row.
virtual int get_selected_item() const =0
Returns the selected item.
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override=0
See widget::set_visible_rectangle.
virtual void clear()=0
Deletes all items.
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
bool is_selected(const unsigned index) const override
Inherited from generator_base.
bool placed_
Has the grid already been placed?
unsigned selected_item_count_
The number of selected items.
virtual unsigned get_item_at_ordered(unsigned index_ordered) const override
virtual unsigned get_ordered_index(unsigned index) const override
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
virtual grid & create_item(const int index, const builder_grid &list_builder, const widget_item &item_data, const std::function< void(widget &)> &callback)=0
Creates a new item.
virtual void impl_draw_children() override
See widget::impl_draw_children.
Must select at least one item.
void handle_key_down_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
void handle_key_up_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual void request_reduce_height(const unsigned) override
See widget::request_reduce_height.
bool selected
Is the item selected or not.
virtual void handle_key_down_arrow(SDL_Keymod modifier, bool &handled)=0
Down arrow key pressed.
bool placed_
Has the grid already been placed?
virtual void select_item(const unsigned index, const bool select)=0
(De)selects an item.
Select the item, this requires the grid to contain a selectable_item.
grid child_grid
The grid containing the widgets.
Places the items in a vertical column.
grid & create_item(const int index, const builder_grid &list_builder, const widget_item &item_data, const std::function< void(widget &)> &callback) override
Inherited from generator_base.
std::map< std::string, widget_item > widget_data
void handle_key_right_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
unsigned get_item_count() const override
Inherited from generator_base.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
virtual void set_origin(const point &origin) override=0
See widget::set_origin.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
void create_item(const unsigned)
See horizontal_list::create_item().
virtual void do_deselect_item(const unsigned index)=0
Deselects a selected item.
void do_select_item(const unsigned index) override
Inherited from generator_base.
virtual void create_items(const int index, const builder_grid &list_builder, const std::vector< widget_data > &data, const std::function< void(widget &)> &callback) override
Inherited from generator_base.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
virtual void request_reduce_height(const unsigned) override
See widget::request_reduce_height.
virtual void request_reduce_width(const unsigned) override
See widget::request_reduce_width.
virtual void set_origin(const point &origin) override
See widget::set_origin.
void select_item(const unsigned index, const bool select=true) override
Inherited from generator_base.
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
void handle_key_up_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.