16 #define GETTEXT_DOMAIN "wesnoth-lib"
38 , linked_group(cfg[
"linked_group"])
39 , debug_border_mode(
widget::debug_border::none)
40 , debug_border_color(
decode_color(cfg[
"debug_border_color"]))
43 switch(
const int dbm = cfg[
"debug_border_mode"].to_int(0); dbm) {
54 WRN_GUI_P <<
"Widget builder: unknown debug border mode " << dbm <<
".";
63 if(widget_key ==
"grid") {
64 return std::make_shared<builder_grid>(widget_cfg);
67 if(widget_key ==
"instance") {
68 return std::make_shared<implementation::builder_instance>(widget_cfg);
71 if(widget_key ==
"pane") {
72 return std::make_shared<implementation::builder_pane>(widget_cfg);
75 if(widget_key ==
"viewport") {
76 return std::make_shared<implementation::builder_viewport>(widget_cfg);
80 if(
type ==
"window" ||
type ==
"tooltip") {
84 if(widget_key ==
type) {
85 return builder(widget_cfg);
93 FAIL(
"Unknown widget type " + widget_key);
102 return builder(cfg)->build();
110 DBG_GUI_P <<
"Window builder: reading data for window " <<
id_ <<
".";
113 VALIDATE(!cfgs.empty(),
_(
"No resolution defined for ") +
id_);
115 for(
const auto&
i : cfgs) {
121 : window_width(cfg[
"window_width"].to_unsigned())
122 , window_height(cfg[
"window_height"].to_unsigned())
123 , automatic_placement(cfg[
"automatic_placement"].to_bool(true))
126 , width(cfg[
"width"])
127 , height(cfg[
"height"])
128 , reevaluate_best_size(cfg[
"reevaluate_best_size"])
132 , maximum_width(cfg[
"maximum_width"], 0u)
133 , maximum_height(cfg[
"maximum_height"], 0u)
134 , click_dismiss(cfg[
"click_dismiss"].to_bool())
135 , definition(cfg[
"definition"])
137 ,
tooltip(cfg.child_or_empty(
"tooltip"),
"tooltip")
138 , helptip(cfg.child_or_empty(
"helptip"),
"helptip")
141 if(!cfg[
"functions"].empty()) {
149 grid = std::make_shared<builder_grid>(*
c);
188 for(
const auto&
c : row.child_range(
"column")) {
202 {
"grid",
id}, {
"row", std::to_string(
rows)}
212 }
else if(col !=
cols) {
213 const t_string msg =
VGETTEXT(
"Grid ‘$grid’ row $row has a differing number of columns ($found found, $expected expected)", {
214 {
"grid",
id}, {
"row", std::to_string(
rows)}, {
"found", std::to_string(col)}, {
"expected", std::to_string(
cols)}
221 DBG_GUI_P <<
"Window builder: grid has " <<
rows <<
" rows and " <<
cols <<
" columns.";
226 auto result = std::make_unique<grid>();
233 auto result = std::make_unique<grid>();
234 build(*result, replacements);
246 DBG_GUI_G <<
"Window builder: grid '" <<
id <<
"' has " <<
rows <<
" rows and " <<
cols <<
" columns.";
248 for(
unsigned x = 0; x <
rows; ++x) {
251 for(
unsigned y = 0; y <
cols; ++y) {
256 DBG_GUI_G <<
"Window builder: adding child at " << x <<
',' << y <<
".";
258 const unsigned int i = x *
cols + y;
A config object defines a single node in a WML file, with access to child nodes.
const_all_children_iterator ordered_begin() const
child_itors child_range(config_key_type key)
std::size_t all_children_count() const
boost::iterator_range< const_child_iterator > const_child_itors
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
std::vector< window_resolution > resolutions
Resolution options for this window instance.
void read(const config &cfg)
void set_row_grow_factor(const unsigned row, const unsigned factor)
Sets the grow factor for a row.
void set_column_grow_factor(const unsigned column, const unsigned factor)
Sets the grow factor for a column.
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
void set_child(std::unique_ptr< widget > widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
A simple wrapper class for optional reference types.
static std::string _(const char *str)
Define the common log macros for the gui toolkit.
std::string id
Text to match against addon_info.tags()
#define log_scope2(domain, description)
unsigned get_v_align(const std::string &v_align)
Returns the vertical alignment.
unsigned get_h_align(const std::string &h_align)
Returns the horizontal alignment.
unsigned read_flags(const config &cfg)
Returns the placement/resize flags.
std::shared_ptr< builder_widget > builder_widget_ptr
color_t decode_color(const std::string &color)
Converts a color string to a color.
std::unique_ptr< widget > build_single_widget_instance_helper(const std::string &type, const config &cfg)
Implementation detail for build_single_widget_instance.
builder_widget_ptr create_widget_builder(const config &cfg)
Create a widget builder.
std::vector< linked_group_definition > parse_linked_group_definitions(const config &cfg)
std::function< builder_widget_ptr(const config &)> widget_builder_func_t
Function type alias for register_widget_builder.
lg::log_domain log_gui_general("gui/general")
lg::log_domain log_gui_parse("gui/parse")
std::map< std::string, widget_builder_func_t > & widget_builder_lookup()
Returns the list of registered widget builders.
Contains the implementation details for lexical_cast and shouldn't be used directly.
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::vector< unsigned > col_grow_factor
std::vector< unsigned > flags
The flags per grid cell.
std::vector< builder_widget_ptr > widgets
The widgets per grid cell.
builder_grid(const config &cfg)
std::vector< unsigned > row_grow_factor
The grow factor for the rows / columns.
virtual std::unique_ptr< widget > build() const override
Inherited from builder_widget.
std::vector< unsigned > border_size
The border size per grid cell.
typed_formula< unsigned > height
std::vector< linked_group_definition > linked_groups
typed_formula< unsigned > width
wfl::function_symbol_table functions
window_resolution(const config &cfg)
std::string missing_mandatory_wml_key(const std::string §ion, const std::string &key, const std::string &primary_key, const std::string &primary_value)
Returns a standard message for a missing wml key (attribute).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.