The Battle for Wesnoth  1.19.10+dev
styled_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2025
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
20 #include "formatter.hpp"
21 #include "formula/string_utils.hpp"
22 #include "gettext.hpp"
26 #include "gui/core/log.hpp"
27 #include "gui/dialogs/tooltip.hpp"
28 #include "gui/widgets/settings.hpp"
29 #include "hotkey/hotkey_item.hpp"
30 #include "sdl/rect.hpp"
31 #include "wml_exception.hpp"
32 #include <functional>
33 
34 #include <algorithm>
35 #include <iomanip>
36 
37 #define LOG_SCOPE_HEADER \
38  "styled_widget(" + get_control_type() + ") [" + id() + "] " + __func__
39 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
40 
41 namespace gui2
42 {
43 
44 // ------------ WIDGET -----------{
45 
47  const std::string& control_type)
48  : widget(builder)
49  , definition_(builder.definition)
50  , label_(builder.label_string)
51  , use_markup_(builder.use_markup)
52  , use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
53  , tooltip_(builder.tooltip)
54  , help_message_(builder.help)
55  , config_(get_control(control_type, definition_))
56  , canvases_(config_->state.begin(), config_->state.end())
57  , renderer_()
58  , text_alignment_(PANGO_ALIGN_LEFT)
59  , text_ellipse_mode_(PANGO_ELLIPSIZE_END)
60  , shrunken_(false)
61 {
62  // Initialize all the canvas variables.
63  update_canvas();
64 
65  // Enable hover behavior if a tooltip was provided.
67 
68  connect_signal<event::SHOW_TOOLTIP>(std::bind(
69  &styled_widget::signal_handler_show_tooltip, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
70 
71  connect_signal<event::SHOW_HELPTIP>(std::bind(
72  &styled_widget::signal_handler_show_helptip, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
73 
74  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
75  &styled_widget::signal_handler_notify_remove_tooltip, this, std::placeholders::_2, std::placeholders::_3));
76 }
77 
79 {
80  /** @todo document this feature on the wiki. */
81  /** @todo do we need to add the debug colors here as well? */
82  widget_item::const_iterator itor = data.find("id");
83  if(itor != data.end()) {
84  set_id(itor->second);
85  }
86 
87  itor = data.find("linked_group");
88  if(itor != data.end()) {
89  set_linked_group(itor->second);
90  }
91 
92  itor = data.find("label");
93  if(itor != data.end()) {
94  set_label(itor->second);
95  }
96 
97  itor = data.find("tooltip");
98  if(itor != data.end()) {
99  set_tooltip(itor->second);
100  }
101 
102  itor = data.find("help");
103  if(itor != data.end()) {
104  set_help_message(itor->second);
105  }
106 
107  itor = data.find("use_markup");
108  if(itor != data.end()) {
109  set_use_markup(utils::string_bool(itor->second));
110  }
111 
112  itor = data.find("text_alignment");
113  if(itor != data.end()) {
115  }
116 }
117 
119 {
121 }
122 
124 {
125  return std::make_unique<iteration::walker::widget>(*this);
126 }
127 
129 {
130  assert(config_);
131 
132  point result(config_->min_width, config_->min_height);
133 
134  DBG_GUI_L << LOG_HEADER << " result " << result << ".";
135  return result;
136 }
137 
139 {
140  assert(config_);
141 
142  point result(config_->default_width, config_->default_height);
143 
144  DBG_GUI_L << LOG_HEADER << " result " << result << ".";
145  return result;
146 }
147 
149 {
150  assert(config_);
151 
152  point result(config_->max_width, config_->max_height);
153 
154  DBG_GUI_L << LOG_HEADER << " result " << result << ".";
155  return result;
156 }
157 
159 {
160  return 0;
161 }
162 
164 {
165  return false;
166 }
167 
169 {
170  return color_t::from_hex_string("ffff00");
171 }
172 
173 void styled_widget::layout_initialize(const bool full_initialization)
174 {
175  // Inherited.
176  widget::layout_initialize(full_initialization);
177 
178  if(full_initialization) {
179  shrunken_ = false;
180  }
181 }
182 
183 void styled_widget::request_reduce_width(const unsigned maximum_width)
184 {
185  assert(config_);
186 
187  if(!label_.empty() && can_wrap()) {
188 
190  point(), point(maximum_width - config_->text_extra_width, 0));
191 
192  size.x += config_->text_extra_width;
193  size.y += config_->text_extra_height;
194 
196 
197  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_.str())
198  << "' maximum_width " << maximum_width << " result " << size
199  << ".";
200 
201  } else if(label_.empty() || text_can_shrink()) {
204  size.x = std::min(size.x, std::max<int>(maximum_width, min_size.x));
206 
207  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
208  << " maximum_width " << maximum_width << " result " << size
209  << ".";
210  } else {
211  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_.str())
212  << "' failed; either no label or wrapping not allowed.";
213  }
214 }
215 
216 void styled_widget::request_reduce_height(const unsigned maximum_height)
217 {
218  if(label_.empty()) {
221  size.y = std::min(size.y, std::max<int>(maximum_height, min_size.y));
223 
224  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
225  << " maximum_height " << maximum_height << " result " << size
226  << ".";
227  }
228 }
229 
231 {
232  assert(config_);
233  if(label_.empty()) {
234  DBG_GUI_L << LOG_HEADER << " empty label return default.";
235  return get_config_default_size();
236  }
237 
238  const point minimum = get_config_default_size();
239  const point maximum = get_config_maximum_size();
240 
241  /**
242  * @todo The value send should subtract the border size
243  * and read it after calculation to get the proper result.
244  */
245  point result = get_best_text_size(minimum, maximum);
246  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_.str())
247  << "' result " << result << ".";
248  return result;
249 }
250 
251 void styled_widget::place(const point& origin, const point& size)
252 {
253  // resize canvasses
254  for(auto & canvas : canvases_)
255  {
257  }
258 
259  // Note we assume that the best size has been queried but otherwise it
260  // should return false.
262  && tooltip_.empty()) {
263 
265  }
266 
267  // inherited
268  widget::place(origin, size);
269 
270  // update the state of the canvas after the sizes have been set.
271  update_canvas();
272 }
273 
274 widget* styled_widget::find_at(const point& coordinate, const bool must_be_active)
275 {
276  return (widget::find_at(coordinate, must_be_active)
277  && (!must_be_active || get_active()))
278  ? this
279  : nullptr;
280 }
281 
283  const bool must_be_active) const
284 {
285  return (widget::find_at(coordinate, must_be_active)
286  && (!must_be_active || get_active()))
287  ? this
288  : nullptr;
289 }
290 
291 widget* styled_widget::find(const std::string_view id, const bool must_be_active)
292 {
293  return (widget::find(id, must_be_active)
294  && (!must_be_active || get_active()))
295  ? this
296  : nullptr;
297 }
298 
299 const widget* styled_widget::find(const std::string_view id, const bool must_be_active)
300  const
301 {
302  return (widget::find(id, must_be_active)
303  && (!must_be_active || get_active()))
304  ? this
305  : nullptr;
306 }
307 
309 {
310  if(label == label_) {
311  return;
312  }
313 
314  label_ = label;
316  update_canvas();
317  queue_redraw();
318 
319  // FIXME: This isn't the most elegant solution. Typically, we don't rely on the text rendering
320  // cache for anything except size calculations, but since we have link awareness now we need to
321  // update its text else `get_label_link` will return old results. I'm not actually sure why the
322  // results seem to only remain one invocation of `set_label` behind the current text, but that
323  // is what testing revealed (see https://github.com/wesnoth/wesnoth/pull/5363).
324  //
325  // -- vultraz, 2020-12-17
327 }
328 
329 void styled_widget::set_use_markup(bool use_markup)
330 {
331  if(use_markup == use_markup_) {
332  return;
333  }
334 
335  use_markup_ = use_markup;
336  update_canvas();
337  queue_redraw();
338 }
339 
340 void styled_widget::set_text_alignment(const PangoAlignment text_alignment)
341 {
342  if(text_alignment_ == text_alignment) {
343  return;
344  }
345 
346  text_alignment_ = text_alignment;
347  update_canvas();
348  queue_redraw();
349 }
350 
351 void styled_widget::set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
352 {
353  if(text_ellipse_mode_ == ellipse_mode) {
354  return;
355  }
356 
357  text_ellipse_mode_ = ellipse_mode;
358  update_canvas();
359  queue_redraw();
360 }
361 
363 {
364  const int max_width = get_text_maximum_width();
365  const int max_height = get_text_maximum_height();
366 
367  // set label in canvases
368  for(auto & canvas : canvases_)
369  {
371  canvas.set_variable("text_markup", wfl::variant(use_markup_));
372  canvas.set_variable("text_link_aware", wfl::variant(get_link_aware()));
373 
374  // Possible TODO: consider making a formula_callable for colors.
375  color_t link_color = get_link_color();
376  std::vector<wfl::variant> link_color_as_list {
377  wfl::variant(link_color.r),
378  wfl::variant(link_color.g),
379  wfl::variant(link_color.b),
380  wfl::variant(link_color.a)
381  };
382 
383  canvas.set_variable("text_link_color", wfl::variant(link_color_as_list));
384  canvas.set_variable("text_alignment",
386  canvas.set_variable("text_maximum_width", wfl::variant(max_width));
387  canvas.set_variable("text_maximum_height", wfl::variant(max_height));
389  canvas.set_variable("text_characters_per_line",
391  }
392 }
393 
395 {
396  if (cached_text_font_size_ == 0) {
397  assert(config_);
398 
400  }
401  return cached_text_font_size_;
402 }
403 
405 {
406  assert(config_);
407 
408  return get_width() - config_->text_extra_width;
409 }
410 
412 {
413  assert(config_);
414 
415  return get_height() - config_->text_extra_height;
416 }
417 
419 {
420  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_.str()) << "' size "
421  << get_rectangle() << ".";
422 
423  if(!get_canvas(get_state()).update_blur(get_rectangle())) {
424  return false;
425  }
427  return true;
428 }
429 
431 {
432  /* DO NOTHING */
433  return true;
434 }
435 
436 point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const
437 {
439 
440  assert(!label_.empty());
441 
442  // Try with the minimum wanted size.
443  const int maximum_width = maximum_size.x;
444 
445  /*
446  * NOTE: text rendering does *not* happen here. That happens in the text_shape
447  * canvas class. Instead, this just leverages the pango text rendering engine to
448  * calculate the area this widget will need to successfully render its text later.
449  */
450  renderer_
453  .set_family_class(config_->text_font_family)
455  .set_font_style(config_->text_font_style)
457  .set_maximum_width(maximum_width)
461 
462  if(get_characters_per_line() != 0 && !can_wrap()) {
464  << " Limited the number of characters per line, "
465  << "but wrapping is not set, output may not be as expected.";
466  }
467 
468  DBG_GUI_L << LOG_HEADER << "\n"
469  << std::boolalpha
470  << "Label: '" << debug_truncate(label_.str()) << "'\n\n"
471  << "Status:\n"
472  << "minimum_size: " << minimum_size << "\n"
473  << "maximum_size: " << maximum_size << "\n"
474  << "can_wrap: " << can_wrap() << "\n"
475  << "characters_per_line: " << get_characters_per_line() << "\n"
476  << "truncated: " << renderer_.is_truncated() << "\n"
477  << "renderer size: " << renderer_.get_size() << "\n"
478  << std::noboolalpha;
479 
480  const point border(config_->text_extra_width,
481  config_->text_extra_height);
482 
483  // If doesn't fit try the maximum.
484  if(renderer_.is_truncated() && !can_wrap()) {
485  // FIXME if maximum size is defined we should look at that
486  // but also we don't adjust for the extra text space yet!!!
487  maximum_size = point(config_->max_width,
488  config_->max_height);
489 
490  renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x : -1);
491  }
492 
493  // Get the resulting size.
495 
496  if(size.x < minimum_size.x) {
497  size.x = minimum_size.x;
498  }
499 
500  if(size.y < minimum_size.y) {
501  size.y = minimum_size.y;
502  }
503 
504  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_.str())
505  << "' result " << size << ".";
506  return size;
507 }
508 
510  bool& handled,
511  const point& location)
512 {
513  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
514 
515  if(!tooltip_.empty()) {
516  std::string tip = tooltip_;
517  if(!help_message_.empty()) {
518  utils::string_map symbols;
519  symbols["hotkey"] = hotkey::get_names(
522 
525  }
526 
528  handled = fire(event::MESSAGE_SHOW_TOOLTIP, *this, message);
529  }
530 }
531 
533  bool& handled,
534  const point& location)
535 {
536  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
537 
538  if(!help_message_.empty()) {
540  handled = fire(event::MESSAGE_SHOW_HELPTIP, *this, message);
541  }
542 }
543 
545  bool& handled)
546 {
547  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
548 
549  /*
550  * This makes the class know the tip code rather intimately. An
551  * alternative is to add a message to the window to remove the tip.
552  * Might be done later.
553  */
555 
556  handled = true;
557 }
558 
559 std::string styled_widget::get_label_token(const point & position, const char * delim) const
560 {
561  return renderer_.get_token(position, delim);
562 }
563 
564 std::string styled_widget::get_label_link(const point & position) const
565 {
566  return renderer_.get_link(position);
567 }
568 
569 // }---------- BUILDER -----------{
570 
571 namespace implementation
572 {
573 
575  : builder_widget(cfg)
576  , definition(cfg["definition"])
577  , label_string(cfg["label"].t_str())
578  , tooltip(cfg["tooltip"].t_str())
579  , help(cfg["help"].t_str())
580  , use_tooltip_on_label_overflow(true)
581  , use_markup(cfg["use_markup"].to_bool(false))
582 {
583  if(definition.empty()) {
584  definition = "default";
585  }
586 
588  help.empty() || !tooltip.empty(),
589  _("Found a widget with a helptip and without a tooltip."),
590  formatter() << "id '" << id << "' label '" << label_string
591  << "' helptip '" << help << "'.");
592 
593 
594  DBG_GUI_P << "Window builder: found styled_widget with id '" << id
595  << "' and definition '" << definition << "'.";
596 }
597 
598 std::unique_ptr<widget> builder_styled_widget::build(const replacements_map& /*replacements*/) const
599 {
600  return build();
601 }
602 
603 } // namespace implementation
604 
605 // }------------ END --------------
606 
607 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
pango_text & set_font_style(const FONT_STYLE font_style)
Definition: text.cpp:370
point get_size()
Returns the size of the text, in drawing coordinates.
Definition: text.cpp:124
pango_text & set_characters_per_line(const unsigned characters_per_line)
Definition: text.cpp:405
pango_text & set_family_class(font::family_class fclass)
Definition: text.cpp:348
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Definition: text.cpp:441
pango_text & set_alignment(const PangoAlignment alignment)
Definition: text.cpp:461
pango_text & set_font_size(unsigned font_size)
Definition: text.cpp:358
pango_text & set_link_aware(bool b)
Definition: text.cpp:484
std::string get_token(const point &position, const char *delimiters=" \n\r\t") const
Gets the largest collection of characters, including the token at position, and not including any cha...
Definition: text.cpp:215
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition: text.cpp:322
bool is_truncated() const
Has the text been truncated? This happens if it exceeds max width or height.
Definition: text.cpp:132
pango_text & set_maximum_width(int width)
Definition: text.cpp:389
pango_text & set_link_color(const color_t &color)
Definition: text.cpp:493
std::string get_link(const point &position) const
Checks if position points to a character in a link in the text, returns it if so, empty string otherw...
Definition: text.cpp:247
std::ostringstream wrapper.
Definition: formatter.hpp:40
A simple canvas which can be drawn upon.
Definition: canvas.hpp:45
void set_variable(const std::string &key, wfl::variant &&value)
Definition: canvas.hpp:157
void draw()
Draw the canvas' shapes onto the screen.
Definition: canvas.cpp:636
void set_size(const point &size)
Definition: canvas.cpp:711
Main class to show messages to the user.
Definition: message.hpp:36
At the moment two kinds of tips are known:
Definition: tooltip.cpp:41
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:74
void set_wants_mouse_hover(const bool hover=true)
t_string help_message_
Tooltip text.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
void set_tooltip(const t_string &tooltip)
bool use_markup_
Use markup for the label?
PangoEllipsizeMode text_ellipse_mode_
The ellipsize mode of the text in a styled_widget.
font::pango_text renderer_
Text renderer object used for size calculations.
virtual unsigned get_state() const =0
Returns the id of the state.
point get_config_maximum_size() const
Gets the best size as defined in the config.
t_string tooltip_
Tooltip text.
bool use_tooltip_on_label_overflow_
If the text doesn't fit on the label should the text be used as tooltip?
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
int get_text_maximum_width() const
Returns the maximum width available for the text.
virtual unsigned get_characters_per_line() const
Returns the number of characters per line.
point get_config_minimum_size() const
Gets the minimum size as defined in the config.
std::string get_label_link(const point &position) const
int get_text_maximum_height() const
Returns the maximum height available for the text.
void signal_handler_show_helptip(const event::ui_event event, bool &handled, const point &location)
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
virtual void update_canvas()
Updates the canvas(ses).
virtual bool get_link_aware() const
Returns whether the label should be link_aware, in in rendering and in searching for links with get_l...
void set_help_message(const t_string &help_message)
point get_config_default_size() const
Gets the default size as defined in the config.
std::vector< canvas > canvases_
Holds all canvas objects for a styled_widget.
PangoEllipsizeMode get_text_ellipse_mode() const
Get the text's ellipsize mode.
virtual color_t get_link_color() const
Returns the color string to be used with links.
void signal_handler_notify_remove_tooltip(const event::ui_event event, bool &handled)
bool shrunken_
Is the widget smaller as it's best size?
PangoAlignment text_alignment_
The alignment of the text in a styled_widget.
virtual void set_members(const widget_item &data)
Sets the members of the styled_widget.
virtual bool impl_draw_background() override
See widget::impl_draw_background.
point get_best_text_size(point minimum_size, point maximum_size={0, 0}) const
Gets the best size for a text.
virtual void place(const point &origin, const point &size) override
See widget::place.
virtual void set_text_alignment(const PangoAlignment text_alignment)
virtual bool get_active() const =0
Gets the active state of the styled_widget.
resolution_definition_ptr config_
Contains the pointer to the configuration.
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
virtual bool impl_draw_foreground() override
See widget::impl_draw_foreground.
std::string get_label_token(const point &position, const char *delimiters=" \n\r\t") const
Exposes font::pango_text::get_token, for the text label of this styled_widget.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
virtual void set_label(const t_string &text)
virtual bool text_can_shrink()
Gets whether a widget can shrink past its optimal size even if it's text-based (such as labels);.
void set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
canvas & get_canvas(const unsigned index)
void signal_handler_show_tooltip(const event::ui_event event, bool &handled, const point &location)
styled_widget(const implementation::builder_styled_widget &builder, const std::string &control_type)
Constructor.
virtual void set_use_markup(bool use_markup)
t_string label_
Contain the non-editable text associated with styled_widget.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
unsigned int get_text_font_size() const
Resolves and returns the text_font_size.
unsigned int cached_text_font_size_
Contains the evaluated text_font_size from the configuration.
Base class for all widgets.
Definition: widget.hpp:55
void set_layout_size(const point &size)
Definition: widget.cpp:346
point get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:203
virtual void place(const point &origin, const point &size)
Places the widget.
Definition: widget.cpp:248
void set_id(const std::string &id)
Definition: widget.cpp:98
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:177
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:356
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:464
visibility get_visible() const
Definition: widget.cpp:506
virtual widget * find(const std::string_view id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:560
unsigned get_width() const
Definition: widget.cpp:336
unsigned get_height() const
Definition: widget.cpp:341
const std::string & id() const
Definition: widget.cpp:110
@ visible
The user sets the widget visible, that means:
rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:321
virtual widget * find_at(const point &coordinate, const bool must_be_active)
Returns the widget at the wanted coordinates.
Definition: widget.cpp:549
virtual bool can_wrap() const
Can the widget wrap.
Definition: widget.cpp:225
bool empty() const
Definition: tstring.hpp:195
const std::string & str() const
Definition: tstring.hpp:199
This file contains the definitions for the gui2::event::message class.
@ border
The border of the map.
static std::string _(const char *str)
Definition: gettext.hpp:97
Define the common log macros for the gui toolkit.
#define DBG_GUI_L
Definition: log.hpp:55
#define DBG_GUI_P
Definition: log.hpp:66
#define WRN_GUI_L
Definition: log.hpp:57
#define DBG_GUI_E
Definition: log.hpp:35
#define DBG_GUI_D
Definition: log.hpp:29
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:201
#define log_scope2(domain, description)
Definition: log.hpp:276
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:212
void remove()
Removes a tip.
Definition: tooltip.cpp:94
static std::unique_ptr< tooltip > tip
Definition: tooltip.cpp:62
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
@ MESSAGE_SHOW_TOOLTIP
Definition: handler.hpp:164
@ MESSAGE_SHOW_HELPTIP
Definition: handler.hpp:165
std::unique_ptr< class walker_base > walker_ptr
Definition: widget.hpp:44
t_string has_helptip_message
Definition: settings.cpp:45
Generic file dialog.
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:156
std::string_view debug_truncate(std::string_view text)
Returns a truncated version of the text.
Definition: helper.cpp:178
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:89
lg::log_domain log_gui_layout("gui/layout")
Definition: log.hpp:54
resolution_definition_ptr get_control(const std::string &control_type, const std::string &definition)
Returns the appropriate config data for a widget instance fom the active GUI definition.
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a PangoAlignment to its string representation.
Definition: helper.cpp:135
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
Contains the implementation details for lexical_cast and shouldn't be used directly.
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.
Definition: unicode.cpp:85
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with '$' in the string 'str' with the equivalent ...
bool string_bool(const std::string &str, bool def)
Convert no, false, off, 0, 0.0 to false, empty to def, and others to true.
std::map< std::string, t_string > string_map
std::string_view data
Definition: picture.cpp:178
Contains the SDL_Rect helper code.
This file contains the settings handling of the widget library.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
static color_t from_hex_string(std::string_view c)
Creates a new color_t object from a string variable in hex format.
Definition: color.cpp:64
Contains the info needed to instantiate a widget.
std::map< std::string, std::shared_ptr< builder_widget > > replacements_map
The replacements type is used to define replacement types.
The message for MESSAGE_SHOW_HELPTIP.
Definition: message.hpp:77
The message for MESSAGE_SHOW_TOOLTIP.
Definition: message.hpp:59
std::string definition
Parameters for the styled_widget.
virtual std::unique_ptr< widget > build() const=0
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
Holds a 2D point.
Definition: point.hpp:25
#define LOG_HEADER
#define LOG_SCOPE_HEADER
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)