40 namespace minimum_selection
126 namespace maximum_selection
383 const bool )
override;
388 const bool )
const override;
458 widget*
find(
const std::string_view
id,
const bool must_be_active)
override;
461 const widget*
find(
const std::string_view
id,
const bool must_be_active)
const override;
498 namespace select_action
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()
596 minimum_selection::delete_item(
index);
616 maximum_selection::select_item(
index,
true);
619 if(!minimum_selection::deselect_item(
index)) {
622 select_action::select(
item(
index),
true);
644 minimum_selection::set_item_shown(
index,
show);
677 for(std::size_t
i = 0;
i <
items_.size(); ++
i) {
684 "No item selected.",
"selected_item_count_ was non-zero, yet no selected item was found.");
722 const std::function<
void(
widget&)>& callback)
override
726 data.emplace(
"", item_data);
734 const std::function<
void(
widget&)>& callback)
override
741 init(&
item->child_grid, item_data, callback);
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
772 const std::vector<widget_item>&
data,
773 const std::function<
void(
widget&)>& callback)
override
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);
849 return my_placement::find_at(
coordinate, must_be_active);
855 return my_placement::find_at(
coordinate, must_be_active);
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);
979 this->queue_redraw();
991 assert(index_ordered <
items_.size());
993 return order_[index_ordered];
1002 for(std::size_t
i = 0;
i <
items_.size(); ++
i) {
1011 for(std::size_t
i = 0;
i <
order_.size(); ++
i) {
1052 const std::vector<T>&
data,
1053 const std::function<
void(
widget&)>& callback)
1057 for(
const auto& item_data :
data) {
1078 const std::function<
void(
widget&)>& callback)
Abstract base class for the generator.
virtual unsigned get_selected_item_count() const =0
Returns the number of selected items.
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 bool is_selected(const unsigned index) const =0
Returns whether the item is selected.
virtual void do_select_item(const unsigned index)=0
Selects a not selected item.
virtual void do_deselect_item(const unsigned index)=0
Deselects a selected item.
virtual int get_selected_item() const =0
Returns the selected item.
Basic template class to generate new items.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
int last_selected_item_
The last item selected.
void calculate_order() const
std::function< bool(unsigned, unsigned)> order_func
unsigned selected_item_count_
The number of selected items.
void clear() override
Inherited from generator_base.
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
const grid & item(const unsigned index) const override
Inherited from generator_base.
bool order_dirty_
whether need to recalculate order_dirty_
std::vector< std::unique_ptr< child > > child_list
The items in the generator.
void set_item_shown(const unsigned index, const bool show) override
Inherited from generator_base.
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
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.
void delete_item(const unsigned index) override
Inherited from generator_base.
virtual bool get_item_shown(const unsigned index) const override
Inherited from generator_base.
void set_item_selected(const unsigned index, const bool selected)
Sets the selected state of an item.
bool is_selected(const unsigned index) const override
Inherited from generator_base.
void select_item(const unsigned index, const bool select=true) override
Inherited from generator_base.
virtual void impl_draw_children() override
See widget::impl_draw_children.
grid & item(const unsigned index) override
Inherited from generator_base.
virtual void set_order(const order_func &order) override
virtual unsigned get_item_at_ordered(unsigned index_ordered) const override
unsigned get_selected_item_count() const override
Inherited from generator_base.
void init(grid *grid, const widget_data &data, const std::function< void(widget &)> &callback)
Helper function to initialize a grid.
std::vector< std::size_t > order_
the elements of order_ are indexes to items_
virtual const widget * find_at(const point &coordinate, const bool must_be_active) const override
See widget::find_at.
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.
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.
virtual void set_origin(const point &origin) override
See widget::set_origin.
grid & item_ordered(const unsigned index) override
Inherited from generator_base.
const grid & item_ordered(const unsigned index) const override
Inherited from generator_base.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See widget::set_visible_rectangle.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
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.
void do_select_item(const unsigned index) override
Inherited from generator_base.
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
void do_deselect_item(const unsigned index) override
Inherited from generator_base.
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.
int get_selected_item() const override
Inherited from generator_base.
virtual void place(const point &origin, const point &size) override
See widget::place.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
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 unsigned get_ordered_index(unsigned index) const override
unsigned get_item_count() const override
Inherited from generator_base.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
std::unique_ptr< class walker_base > walker_ptr
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
struct utils::detail::formula_initer init
virtual std::unique_ptr< widget > build() const override
Inherited from builder_widget.
grid child_grid
The grid containing the widgets.
bool selected
Is the item selected or not.
bool shown
Is the row shown or not.
std::size_t ordered_index
No maximum amount of items to select.
void select_item(const unsigned index, const bool select) override
See one_item::select_item().
May select only one item.
void select_item(const unsigned index, const bool select) override
Called when an item is selected.
void delete_item(const unsigned index)
See minimum_selection::one_item::delete_item()
bool deselect_item(const unsigned index)
See minimum_selection::one_item::deselect_item()
void create_item(const unsigned)
See minimum_selection::one_item::create_item()
void set_item_shown(const unsigned index, const bool show)
See minimum_selection::one_item::set_item_shown().
Must select at least one item.
void delete_item(const unsigned index)
Called just before an item is deleted.
bool deselect_item(const unsigned index)
Called when the users wants to deselect an item.
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.
void set_item_shown(const unsigned index, const bool show)
Called when an item is shown or hidden.
Places the items in a horizontal row.
virtual void set_origin(const point &origin) override
See widget::set_origin.
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 point calculate_best_size() const override
See widget::calculate_best_size.
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.
void handle_key_left_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
void handle_key_right_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
virtual void place(const point &origin, const point &size) override
See widget::place.
bool placed_
Has the grid already been placed?
void set_visible_rectangle(const SDL_Rect &rectangle) override
Sets the visible rectangle of the generator.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
void handle_key_down_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
void handle_key_up_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
Places the items independent of each other.
void handle_key_left_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
void handle_key_down_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
void set_visible_rectangle(const SDL_Rect &rectangle) override
See horizontal_list::set_visible_rectangle().
virtual void request_reduce_height(const unsigned maximum_height) override
See horizontal_list::request_reduce_height.
virtual void place(const point &origin, const point &size) override
See widget::place.
void handle_key_up_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
void create_item(const unsigned)
See horizontal_list::create_item().
void handle_key_right_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
virtual void set_origin(const point &origin) override
See widget::set_origin.
Places the items in a grid.
virtual void place(const point &, const point &) override
See widget::place.
bool placed_
Has the grid already been placed?
void handle_key_up_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
void handle_key_right_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual void set_origin(const point &) override
See widget::set_origin.
void handle_key_down_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
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 point calculate_best_size() const override
See widget::calculate_best_size.
virtual void request_reduce_width(const unsigned) override
See widget::request_reduce_width.
void handle_key_left_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual widget * find_at(const point &, const bool) override
See widget::find_at.
void set_visible_rectangle(const SDL_Rect &) override
See horizontal_list::set_visible_rectangle().
virtual void request_reduce_height(const unsigned) override
See widget::request_reduce_height.
Places the items in a vertical column.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
virtual void set_origin(const point &origin) override
See widget::set_origin.
void handle_key_up_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
void handle_key_right_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
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 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 place(const point &origin, const point &size) override
See widget::place.
bool placed_
Has the grid already been placed?
void set_visible_rectangle(const SDL_Rect &rectangle) override
See horizontal_list::set_visible_rectangle().
void handle_key_left_arrow(SDL_Keymod, bool &) override
Inherited from generator_base.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
void handle_key_down_arrow(SDL_Keymod modifier, bool &handled) override
Inherited from generator_base.
Select the item, this requires the grid to contain a selectable_item.
void init(grid *grid, const widget_data &data, const std::function< void(widget &)> &callback)
Helper function to initialize a grid.
void select(grid &grid, const bool select)
void select(grid &grid, const bool show)
void init(grid *grid, const widget_data &data, const std::function< void(widget &)> &callback)
Helper function to initialize a grid.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define FAIL_WITH_DEV_MESSAGE(message, dev_message)