Allow composite widgets to inject linked groups

This commit is contained in:
Jyrki Vesterinen 2017-01-28 17:59:36 +02:00
parent 688f85cf94
commit 6f94a8ffed
5 changed files with 74 additions and 0 deletions

View file

@ -481,6 +481,26 @@
type="unsigned"
default=0
[/key]
[tag]
name="linked_group"
min="0"
max="-1"
[key]
name="fixed_height"
type="bool"
default=false
[/key]
[key]
name="fixed_width"
type="bool"
default=false
[/key]
[key]
name="id"
type="string"
mandatory="true"
[/key]
[/tag]
[key]
name="text_extra_height"
type="unsigned"

View file

@ -16,9 +16,11 @@
#include "gui/core/widget_definition.hpp"
#include "formula/string_utils.hpp"
#include "gettext.hpp"
#include "gui/core/log.hpp"
#include "gui/widgets/helper.hpp"
#include "serialization/string_utils.hpp"
#include "wml_exception.hpp"
namespace gui2
@ -98,6 +100,7 @@ resolution_definition::resolution_definition(const config& cfg)
, default_height(cfg["default_height"])
, max_width(cfg["max_width"])
, max_height(cfg["max_height"])
, linked_groups()
, text_extra_width(cfg["text_extra_width"])
, text_extra_height(cfg["text_extra_height"])
, text_font_size(cfg["text_font_size"])
@ -107,6 +110,29 @@ resolution_definition::resolution_definition(const config& cfg)
{
DBG_GUI_P << "Parsing resolution " << window_width << ", " << window_height
<< '\n';
for(const config& lg : cfg.child_range("linked_group")) {
linked_group linked_group;
linked_group.id = lg["id"].str();
linked_group.fixed_width = lg["fixed_width"].to_bool();
linked_group.fixed_height = lg["fixed_height"].to_bool();
VALIDATE(!linked_group.id.empty(),
missing_mandatory_wml_key("linked_group", "id"));
if(!(linked_group.fixed_width || linked_group.fixed_height)) {
utils::string_map symbols;
symbols["id"] = linked_group.id;
t_string msg
= vgettext("Linked '$id' group needs a 'fixed_width' or "
"'fixed_height' key.",
symbols);
FAIL(msg);
}
linked_groups.push_back(linked_group);
}
}
/*WIKI

View file

@ -19,6 +19,7 @@
#include "font/font_options.hpp"
#include "font/text.hpp"
#include "gui/core/canvas.hpp"
#include <vector>
namespace gui2
{
@ -55,6 +56,19 @@ struct resolution_definition
unsigned max_width;
unsigned max_height;
struct linked_group
{
linked_group() : id(), fixed_width(false), fixed_height(false)
{
}
std::string id;
bool fixed_width;
bool fixed_height;
};
std::vector<linked_group> linked_groups;
unsigned text_extra_width;
unsigned text_extra_height;
unsigned text_font_size;

View file

@ -17,6 +17,7 @@
#include "gui/widgets/container_base.hpp"
#include "gui/core/log.hpp"
#include "gui/widgets/window.hpp"
#include <algorithm>
@ -37,6 +38,8 @@ void container_base::layout_initialise(const bool full_initialisation)
// Inherited.
styled_widget::layout_initialise(full_initialisation);
inject_linked_groups();
grid_.layout_initialise(full_initialisation);
}
@ -264,4 +267,13 @@ point container_base::border_space() const
return point();
}
void container_base::inject_linked_groups()
{
for(const auto& lg : config()->linked_groups) {
if(!get_window()->has_linked_size_group(lg.id)) {
get_window()->init_linked_size_group(lg.id, lg.fixed_width, lg.fixed_height);
}
}
}
} // namespace gui2

View file

@ -260,6 +260,8 @@ private:
* set_active so we only need to change the state.
*/
virtual void set_self_active(const bool active) = 0;
void inject_linked_groups();
};
} // namespace gui2