diff --git a/data/gui/schema.cfg b/data/gui/schema.cfg index 362b528b4db..e1a0c7959ab 100644 --- a/data/gui/schema.cfg +++ b/data/gui/schema.cfg @@ -125,6 +125,41 @@ type="t_string" default="" [/key] + [key] + name="help" + type="t_string" + default="" + [/key] + [tag] + name="widget" + min="0" + max="-1" + [key] + name="id" + type="t_string" + default="" + [/key] + [key] + name="icon" + type="t_string" + default="" + [/key] + [key] + name="label" + type="t_string" + default="" + [/key] + [key] + name="tooltip" + type="t_string" + default="" + [/key] + [key] + name="help" + type="t_string" + default="" + [/key] + [/tag] [/tag] [key] name="grow_factor" diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 6473cce7bae..749728ff3a6 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -529,7 +529,7 @@ void swap_grid(tgrid* grid, void tlistbox::finalize(tbuilder_grid_const_ptr header, tbuilder_grid_const_ptr footer, - const std::vector& list_data) + const std::vector>& list_data) { // "Inherited." tscrollbar_container::finalize_setup(); @@ -835,6 +835,33 @@ tlistbox_definition::tresolution::tresolution(const config& cfg) namespace implementation { +static std::vector> parse_list_data(const config& data, size_t req_cols) +{ + std::vector> list_data; + for(const auto & row : data.child_range("row")) + { + auto cols = row.child_range("column"); + VALIDATE(cols.size() == req_cols, _("'list_data' must have the same number of columns as the 'list_definition'.")); + + for(const auto & c : cols) + { + list_data.emplace_back(); + for(const auto & i : c.attribute_range()) + { + list_data.back()[""][i.first] = i.second; + } + for(const auto& w : c.child_range("widget")) + { + VALIDATE(w.has_attribute("id"), missing_mandatory_wml_key("[list_data][row][column][widget]", "id")); + for(const auto& i : w.attribute_range()) { + list_data.back()[w["id"]][i.first] = i.second; + } + } + } + } + return list_data; +} + tbuilder_listbox::tbuilder_listbox(const config& cfg) : tbuilder_control(cfg) , vertical_scrollbar_mode( @@ -864,28 +891,8 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg) VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row.")); - const config& data = cfg.child("list_data"); - if(!data) { - return; - } - - for(const auto & row : data.child_range("row")) - { - unsigned col = 0; - - for(const auto & c : row.child_range("column")) - { - list_data.push_back(string_map()); - for(const auto & i : c.attribute_range()) - { - list_data.back()[i.first] = i.second; - } - ++col; - } - - VALIDATE(col == list_builder->cols, - _("'list_data' must have the same number of " - "columns as the 'list_definition'.")); + if(cfg.has_child("list_data")) { + list_data = parse_list_data(cfg.child("list_data"), list_builder->cols); } } @@ -1037,27 +1044,8 @@ tbuilder_horizontal_listbox::tbuilder_horizontal_listbox(const config& cfg) VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row.")); - const config& data = cfg.child("list_data"); - if(!data) - return; - - for(const auto & row : data.child_range("row")) - { - unsigned col = 0; - - for(const auto & c : row.child_range("column")) - { - list_data.push_back(string_map()); - for(const auto & i : c.attribute_range()) - { - list_data.back()[i.first] = i.second; - } - ++col; - } - - VALIDATE(col == list_builder->cols, - _("'list_data' must have " - "the same number of columns as the 'list_definition'.")); + if(cfg.has_child("list_data")) { + list_data = parse_list_data(cfg.child("list_data"), list_builder->cols); } } @@ -1181,27 +1169,8 @@ tbuilder_grid_listbox::tbuilder_grid_listbox(const config& cfg) VALIDATE(list_builder->rows == 1, _("A 'list_definition' should contain one row.")); - const config& data = cfg.child("list_data"); - if(!data) - return; - - for(const auto & row : data.child_range("row")) - { - unsigned col = 0; - - for(const auto & c : row.child_range("column")) - { - list_data.push_back(string_map()); - for(const auto & i : c.attribute_range()) - { - list_data.back()[i.first] = i.second; - } - ++col; - } - - VALIDATE(col == list_builder->cols, - _("'list_data' must have " - "the same number of columns as the 'list_definition'.")); + if(cfg.has_child("list_data")) { + list_data = parse_list_data(cfg.child("list_data"), list_builder->cols); } } diff --git a/src/gui/widgets/listbox.hpp b/src/gui/widgets/listbox.hpp index 09abe37349e..0558b7e5d22 100644 --- a/src/gui/widgets/listbox.hpp +++ b/src/gui/widgets/listbox.hpp @@ -287,7 +287,7 @@ private: */ void finalize(tbuilder_grid_const_ptr header, tbuilder_grid_const_ptr footer, - const std::vector& list_data); + const std::vector>& list_data); /** * Contains a pointer to the generator. * @@ -405,7 +405,7 @@ struct tbuilder_listbox : public tbuilder_control * Contains a vector with the data to set in every cell, it's used to * serialize the data in the config, so the config is no longer required. */ - std::vector list_data; + std::vector> list_data; bool has_minimum_, has_maximum_; }; @@ -429,7 +429,7 @@ struct tbuilder_horizontal_listbox : public tbuilder_control * Contains a vector with the data to set in every cell, it's used to * serialize the data in the config, so the config is no longer required. */ - std::vector list_data; + std::vector> list_data; bool has_minimum_, has_maximum_; }; @@ -453,7 +453,7 @@ struct tbuilder_grid_listbox : public tbuilder_control * Contains a vector with the data to set in every cell, it's used to * serialize the data in the config, so the config is no longer required. */ - std::vector list_data; + std::vector> list_data; bool has_minimum_, has_maximum_; };