15 #ifndef GUI2_EXPERIMENTAL_LISTBOX
17 #define GETTEXT_DOMAIN "wesnoth-lib"
38 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
39 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
53 void callback_list_item_clicked(twidget& caller)
55 get_parent<tlistbox>(caller).list_item_clicked(caller);
61 const bool has_maximum,
65 , generator_(
tgenerator_::
build(has_minimum, has_maximum, placement, select))
66 , is_horizonal_(placement ==
tgenerator_::horizontal_list)
67 , list_builder_(nullptr)
68 , callback_value_changed_()
106 int height_reduced = 0;
107 int width_reduced = 0;
124 if((height_reduced != 0 || width_reduced != 0) &&
get_item_count() != 0) {
125 resize_content(-width_reduced, -height_reduced, row_pos_x, row_pos_y);
195 for(
size_t i = 0;
i < shown.size(); ++
i) {
204 window->invalidate_layout();
305 if(selected_item != -1) {
317 const int height_modification,
318 const int width_modification_pos,
319 const int height_modification_pos)
322 <<
" width_modification " << width_modification
323 <<
" height_modification " << height_modification <<
".\n";
325 if(
content_resize_request(width_modification, height_modification, width_modification_pos, height_modification_pos)) {
329 size.
x += width_modification;
330 size.
y += height_modification;
338 if(width_modification < 0 || height_modification < 0) {
358 if(size.
x < content.
x) {
374 const std::vector<twidget*>& call_stack)
380 std::vector<twidget*> child_call_stack = call_stack;
502 assert(content_grid);
509 tgrid* parent_grid =
nullptr;
511 parent_grid = find_widget<tgrid>(
grid,
id,
false,
false);
514 parent_grid = find_widget<tgrid>(content_grid,
id,
true,
false);
516 parent_grid =
dynamic_cast<tgrid*
>(parent_grid->
parent());
520 widget = parent_grid->
swap_child(
id, widget,
false);
530 const std::vector<string_map>& list_data)
540 tgrid&
p = find_widget<tgrid>(
this,
"_header_grid",
false);
542 if(
tselectable_* selectable = find_widget<tselectable_>(&p,
"sort_" + std::to_string(
i),
false,
false)) {
559 bool default_sort(
unsigned i1,
unsigned i2)
573 if(pair.first !=
nullptr && pair.first != &selectable) {
610 const tpoint s(size.
x, size.
y < best_height ? size.
y : best_height);
641 DBG_GUI_P <<
"Parsing listbox " <<
id <<
'\n';
643 load_resolutions<tresolution>(cfg);
836 tbuilder_listbox::tbuilder_listbox(
const config& cfg)
838 , vertical_scrollbar_mode(
840 , horizontal_scrollbar_mode(
844 , list_builder(nullptr)
846 , has_minimum_(cfg[
"has_minimum"].to_bool(true))
847 , has_maximum_(cfg[
"has_maximum"].to_bool(true))
863 _(
"A 'list_definition' should contain one row."));
874 for(
const auto &
c :
row.child_range(
"column"))
877 for(
const auto &
i :
c.attribute_range())
885 _(
"'list_data' must have the same number of "
886 "columns as the 'list_definition'."));
892 #ifdef GUI2_EXPERIMENTAL_LISTBOX
893 tlist* widget =
new tlist(
940 DBG_GUI_G <<
"Window builder: placed listbox '" <<
id
941 <<
"' with definition '" <<
definition <<
"'.\n";
1017 , vertical_scrollbar_mode(
1019 , horizontal_scrollbar_mode(
1021 , list_builder(nullptr)
1030 _(
"A 'list_definition' should contain one row."));
1040 for(
const auto &
c :
row.child_range(
"column"))
1043 for(
const auto &
i :
c.attribute_range())
1051 _(
"'list_data' must have "
1052 "the same number of columns as the 'list_definition'."));
1058 #ifdef GUI2_EXPERIMENTAL_LISTBOX
1059 tlist* widget =
new tlist(
1078 DBG_GUI_G <<
"Window builder: placed listbox '" <<
id
1079 <<
"' with definition '" <<
definition <<
"'.\n";
Define the common log macros for the gui toolkit.
virtual void set_content_size(const tpoint &origin, const tpoint &size)
Inherited from tscrollbar_container.
bool new_widgets
Do we wish to use the new library or not.
child_itors child_range(const std::string &key)
Abstract base class for the generator.
Defines the exception classes for the layout algorithm.
void set_list_builder(tbuilder_grid_ptr list_builder)
void finalize(tbuilder_grid_const_ptr header, tbuilder_grid_const_ptr footer, const std::vector< string_map > &list_data)
Finishes the building initialization of the widget.
virtual void select_item(const unsigned index, const bool select)=0
(De)selects an item.
static const unsigned BORDER_ALL
const tgrid & grid() const
virtual void place(const tpoint &origin, const tpoint &size) override=0
See twidget::place.
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
tbuilder_grid_const_ptr list_builder_
Contains the builder for the new items.
virtual unsigned get_value() const =0
Is the control selected?
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
twindow * build(CVideo &video, const twindow_builder::tresolution *definition)
Builds a window.
bool update_content_size()
Request to update the size of the content after changing the content.
GLuint GLuint GLsizei GLenum type
tresolution(const config &cfg)
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
tresolution_definition_ptr config()
virtual int get_selected_item() const =0
Returns the selected item.
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
tbuilder_grid_ptr list_builder
virtual void handle_key_right_arrow(SDLMod modifier, bool &handled)=0
Right arrow key pressed.
virtual tgrid & item(const unsigned index)=0
Gets the grid of an item.
unsigned int get_rows() const
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
tplacement
Determines how the items are placed.
void set_row_active(const unsigned row, const bool active)
Makes a row active or inactive.
tbuilder_horizontal_listbox(const config &cfg)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
tscrollbar_container::tscrollbar_mode get_scrollbar_mode(const std::string &scrollbar_mode)
Returns the scrollbar mode flags.
std::function< bool(unsigned, unsigned)> torder_func
Base class of a resolution, contains the common keys for a resolution.
virtual void layout_children() override
See twidget::layout_children.
virtual void set_value(const unsigned)=0
Select the control.
void order_by_column(unsigned column, twidget &widget)
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.
void init_control(tcontrol *control) const
std::string definition
Parameters for the control.
static UNUSEDNOWARN std::string _(const char *str)
virtual void handle_key_down_arrow(SDLMod modifier, bool &handled)=0
Down arrow key pressed.
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
void order_by(const tgenerator_::torder_func &func)
unsigned get_item_count() const
Returns the number of items in the listbox.
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
virtual unsigned get_item_count() const =0
Returns the number of items.
virtual void set_self_active(const bool active) override
See tcontainer_::set_self_active.
tbuilder_grid_ptr list_builder
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.
void handle_key_up_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode
tgenerator_ * generator_
Contains a pointer to the generator.
virtual void handle_key_up_arrow(SDLMod modifier, bool &handled)=0
Up arrow key pressed.
void set_column_order(unsigned col, const std::vector< tgenerator_::torder_func > &func)
void init_grid(const boost::intrusive_ptr< tbuilder_grid > &grid_builder)
Initializes and builds the grid.
tlistbox(const bool has_minimum, const bool has_maximum, const tgenerator_::tplacement placement, const bool select)
Constructor.
std::vector< string_map > list_data
Listbox data.
void set_active(const bool active)
Activates all children.
void resize_content(const int width_modification, const int height_modification, const int width__modification_pos=-1, const int height_modification_pos=-1)
Resizes the content.
static size_t id
Ids for the timers.
virtual void set_item_shown(const unsigned index, const bool show)=0
Shows or hides an item.
GLuint GLuint GLsizei count
Contains the state info for a resolution.
std::map< std::string, t_string > string_map
virtual bool has_widget(const twidget &widget) const override
See twidget::has_widget.
Small abstract helper class.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
virtual void set_order(const torder_func &order)=0
void handle_key_down_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
GLenum GLenum GLvoid GLvoid * column
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode
tlistbox_definition(const config &cfg)
void handle_key_right_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
virtual tpoint calculate_best_size() const override=0
See twidget::calculate_best_size.
GLfloat GLfloat GLfloat GLfloat h
twidget * swap_child(const std::string &id, twidget *widget, const bool recurse, twidget *new_parent=nullptr)
Exchanges a child in the grid.
void toggle_item(const unsigned index)
Toggles the selection state of an 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)=0
Creates one or more new item(s).
Helper class to block invalidate_layout.
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
GLenum GLenum GLvoid * row
std::vector< tstate_definition > state
std::function< void(twidget &)> callback_value_changed_
This callback is called when the value in the listbox changes.
virtual void handle_key_left_arrow(SDLMod modifier, bool &handled)=0
Left arrow key pressed.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
std::vector< string_map > list_data
Listbox data.
tscrollbar_container::tscrollbar_mode horizontal_scrollbar_mode
void set_child(twidget *widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
void keyboard_capture(twidget *widget)
tscrollbar_container::tscrollbar_mode vertical_scrollbar_mode
A config object defines a single node in a WML file, with access to child nodes.
void handle_key_left_arrow(SDLMod modifier, bool &handled)
Inherited from tscrollbar_container.
void list_item_clicked(twidget &caller)
Function to call after the user clicked on a row.
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
int get_selected_row() const
Returns the first selected row.
unsigned int get_cols() const
GLsizei const GLcharARB ** string
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
void clear()
Removes all the rows in the listbox, clearing it.
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Contains the implementation details for lexical_cast and shouldn't be used directly.
void invalidate_layout()
Updates the size of the window.
std::function< void(size_t)> callback_item_changed_
This callback is called when a list item is clicked (toggled).
virtual void delete_item(const unsigned index)=0
Deletes an item.