The Battle for Wesnoth  1.15.2+dev
styled_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
18 
19 #include "formatter.hpp"
20 #include "formula/string_utils.hpp"
21 #include "gettext.hpp"
25 #include "gui/core/log.hpp"
26 #include "gui/dialogs/tooltip.hpp"
27 #include "gui/widgets/settings.hpp"
28 #include "gui/widgets/window.hpp"
29 #include "hotkey/hotkey_item.hpp"
30 #include "sdl/rect.hpp"
31 #include "wml_exception.hpp"
32 
33 #include "utils/functional.hpp"
34 
35 #include <algorithm>
36 #include <iomanip>
37 
38 #define LOG_SCOPE_HEADER \
39  "styled_widget(" + get_control_type() + ") [" + id() + "] " + __func__
40 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
41 
42 namespace gui2
43 {
44 
45 // ------------ WIDGET -----------{
46 
48  const std::string& control_type)
49  : widget(builder)
50  , definition_(builder.definition)
51  , label_(builder.label_string)
52  , use_markup_(builder.use_markup)
53  , use_tooltip_on_label_overflow_(builder.use_tooltip_on_label_overflow)
54  , tooltip_(builder.tooltip)
55  , help_message_(builder.help)
56  , config_(get_control(control_type, definition_))
57  , canvases_(config_->state.size()) // One canvas per state
58  , renderer_()
59  , text_maximum_width_(0)
60  , text_alignment_(PANGO_ALIGN_LEFT)
61  , text_ellipse_mode_(PANGO_ELLIPSIZE_END)
62  , shrunken_(false)
63 {
64  /*
65  * Fill in each canvas from the widget state definitons.
66  *
67  * Most widgets have a single canvas. However, some widgets such as toggle_panel
68  * and toggle_button have a variable canvas count determined by their definitions.
69  */
70  for(unsigned i = 0; i < config_->state.size(); ++i) {
71  canvases_[i].set_cfg(config_->state[i].canvas_cfg_);
72  }
73 
74  // Initialize all the canvas variables.
75  update_canvas();
76 
77  // Enable hover behavior if a tooltip was provided.
79 
80  connect_signal<event::SHOW_TOOLTIP>(std::bind(
81  &styled_widget::signal_handler_show_tooltip, this, _2, _3, _5));
82 
83  connect_signal<event::SHOW_HELPTIP>(std::bind(
84  &styled_widget::signal_handler_show_helptip, this, _2, _3, _5));
85 
86  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
88 }
89 
91 {
92  /** @todo document this feature on the wiki. */
93  /** @todo do we need to add the debug colors here as well? */
94  string_map::const_iterator itor = data.find("id");
95  if(itor != data.end()) {
96  set_id(itor->second);
97  }
98 
99  itor = data.find("linked_group");
100  if(itor != data.end()) {
101  set_linked_group(itor->second);
102  }
103 
104  itor = data.find("label");
105  if(itor != data.end()) {
106  set_label(itor->second);
107  }
108 
109  itor = data.find("tooltip");
110  if(itor != data.end()) {
111  set_tooltip(itor->second);
112  }
113 
114  itor = data.find("help");
115  if(itor != data.end()) {
116  set_help_message(itor->second);
117  }
118 
119  itor = data.find("use_markup");
120  if(itor != data.end()) {
121  set_use_markup(utils::string_bool(itor->second));
122  }
123 
124  itor = data.find("text_alignment");
125  if(itor != data.end()) {
127  }
128 }
129 
131 {
133 }
134 
136 {
137  return new iteration::walker::widget(*this);
138 }
139 
141 {
142  assert(config_);
143 
144  point result(config_->min_width, config_->min_height);
145 
146  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
147  return result;
148 }
149 
151 {
152  assert(config_);
153 
154  point result(config_->default_width, config_->default_height);
155 
156  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
157  return result;
158 }
159 
161 {
162  assert(config_);
163 
164  point result(config_->max_width, config_->max_height);
165 
166  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
167  return result;
168 }
169 
171 {
172  return 0;
173 }
174 
176 {
177  return false;
178 }
179 
181 {
182  return color_t::from_hex_string("ffff00");
183 }
184 
185 void styled_widget::layout_initialize(const bool full_initialization)
186 {
187  // Inherited.
188  widget::layout_initialize(full_initialization);
189 
190  if(full_initialization) {
191  shrunken_ = false;
192  }
193 }
194 
195 void styled_widget::request_reduce_width(const unsigned maximum_width)
196 {
197  assert(config_);
198 
199  if(!label_.empty() && can_wrap()) {
200 
202  point(), point(maximum_width - config_->text_extra_width, 0));
203 
204  size.x += config_->text_extra_width;
205  size.y += config_->text_extra_height;
206 
207  set_layout_size(size);
208 
209  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
210  << "' maximum_width " << maximum_width << " result " << size
211  << ".\n";
212 
213  } else if(label_.empty() || text_can_shrink()) {
216  size.x = std::min(size.x, std::max<int>(maximum_width, min_size.x));
217  set_layout_size(size);
218 
219  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
220  << " maximum_width " << maximum_width << " result " << size
221  << ".\n";
222  } else {
223  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
224  << "' failed; either no label or wrapping not allowed.\n";
225  }
226 }
227 
228 void styled_widget::request_reduce_height(const unsigned maximum_height)
229 {
230  if(!label_.empty()) {
231  // Do nothing
232  } else {
235  size.y = std::min(size.y, std::max<int>(maximum_height, min_size.y));
236  set_layout_size(size);
237 
238  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
239  << " maximum_height " << maximum_height << " result " << size
240  << ".\n";
241  }
242 }
243 
245 {
246  assert(config_);
247  if(label_.empty()) {
248  DBG_GUI_L << LOG_HEADER << " empty label return default.\n";
249  return get_config_default_size();
250  }
251 
252  const point minimum = get_config_default_size();
253  const point maximum = get_config_maximum_size();
254 
255  /**
256  * @todo The value send should subtract the border size
257  * and read it after calculation to get the proper result.
258  */
259  point result = get_best_text_size(minimum, maximum);
260  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
261  << "' result " << result << ".\n";
262  return result;
263 }
264 
265 void styled_widget::place(const point& origin, const point& size)
266 {
267  // resize canvasses
268  for(auto & canvas : canvases_)
269  {
270  canvas.set_width(size.x);
271  canvas.set_height(size.y);
272  }
273 
274  // Note we assume that the best size has been queried but otherwise it
275  // should return false.
277  && tooltip_.empty()) {
278 
280  }
281 
282  // inherited
283  widget::place(origin, size);
284 
285  // update the state of the canvas after the sizes have been set.
286  update_canvas();
287 }
288 
289 widget* styled_widget::find_at(const point& coordinate, const bool must_be_active)
290 {
291  return (widget::find_at(coordinate, must_be_active)
292  && (!must_be_active || get_active()))
293  ? this
294  : nullptr;
295 }
296 
298  const bool must_be_active) const
299 {
300  return (widget::find_at(coordinate, must_be_active)
301  && (!must_be_active || get_active()))
302  ? this
303  : nullptr;
304 }
305 
306 widget* styled_widget::find(const std::string& id, const bool must_be_active)
307 {
308  return (widget::find(id, must_be_active)
309  && (!must_be_active || get_active()))
310  ? this
311  : nullptr;
312 }
313 
314 const widget* styled_widget::find(const std::string& id, const bool must_be_active)
315  const
316 {
317  return (widget::find(id, must_be_active)
318  && (!must_be_active || get_active()))
319  ? this
320  : nullptr;
321 }
322 
324 {
325  if(label == label_) {
326  return;
327  }
328 
329  label_ = label;
331  update_canvas();
332  set_is_dirty(true);
333 }
334 
335 void styled_widget::set_use_markup(bool use_markup)
336 {
337  if(use_markup == use_markup_) {
338  return;
339  }
340 
341  use_markup_ = use_markup;
342  update_canvas();
343  set_is_dirty(true);
344 }
345 
346 void styled_widget::set_text_alignment(const PangoAlignment text_alignment)
347 {
348  if(text_alignment_ == text_alignment) {
349  return;
350  }
351 
352  text_alignment_ = text_alignment;
353  update_canvas();
354  set_is_dirty(true);
355 }
356 
357 void styled_widget::set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
358 {
359  if(text_ellipse_mode_ == ellipse_mode) {
360  return;
361  }
362 
363  text_ellipse_mode_ = ellipse_mode;
364  update_canvas();
365  set_is_dirty(true);
366 }
367 
369 {
370  const int max_width = get_text_maximum_width();
371  const int max_height = get_text_maximum_height();
372 
373  // set label in canvases
374  for(auto & canvas : canvases_)
375  {
377  canvas.set_variable("text_markup", wfl::variant(use_markup_));
378  canvas.set_variable("text_link_aware", wfl::variant(get_link_aware()));
379 
380  // Possible TODO: consider making a formula_callable for colors.
381  color_t link_color = get_link_color();
382  std::vector<wfl::variant> link_color_as_list {
383  wfl::variant(link_color.r),
384  wfl::variant(link_color.g),
385  wfl::variant(link_color.b),
386  wfl::variant(link_color.a)
387  };
388 
389  canvas.set_variable("text_link_color", wfl::variant(link_color_as_list));
390  canvas.set_variable("text_alignment",
392  canvas.set_variable("text_maximum_width", wfl::variant(max_width));
393  canvas.set_variable("text_maximum_height", wfl::variant(max_height));
395  canvas.set_variable("text_characters_per_line",
397  }
398 }
399 
401 {
402  assert(config_);
403 
405  : get_width() - config_->text_extra_width;
406 }
407 
409 {
410  assert(config_);
411 
412  return get_height() - config_->text_extra_height;
413 }
414 
416  int x_offset,
417  int y_offset)
418 {
419  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_) << "' size "
420  << get_rectangle() << ".\n";
421 
422  get_canvas(get_state()).blit(frame_buffer,
423  calculate_blitting_rectangle(x_offset, y_offset));
424 }
425 
427  ,
428  int /*x_offset*/
429  ,
430  int /*y_offset*/)
431 {
432  /* DO NOTHING */
433 }
434 
435 point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const
436 {
438 
439  assert(!label_.empty());
440 
441  // Try with the minimum wanted size.
442  const int maximum_width = text_maximum_width_ != 0
444  : maximum_size.x;
445 
446  /*
447  * NOTE: text rendering does *not* happen here. That happens in the text_shape
448  * canvas class. Instead, this just leverages the pango text rendering engine to
449  * calculate the area this widget will need to successfully render its text later.
450  */
451  renderer_
454  .set_family_class(config_->text_font_family)
455  .set_font_size(config_->text_font_size)
456  .set_font_style(config_->text_font_style)
458  .set_maximum_width(maximum_width)
462 
463  if(get_characters_per_line() != 0 && !can_wrap()) {
465  << " Limited the number of characters per line, "
466  << "but wrapping is not set, output may not be as expected.\n";
467  }
468 
469  DBG_GUI_L << LOG_HEADER << "\n"
470  << std::boolalpha
471  << "Label: '" << debug_truncate(label_) << "'\n\n"
472  << "Status:\n"
473  << "minimum_size: " << minimum_size << "\n"
474  << "maximum_size: " << maximum_size << "\n"
475  << "text_maximum_width_: " << text_maximum_width_ << "\n"
476  << "can_wrap: " << can_wrap() << "\n"
477  << "characters_per_line: " << get_characters_per_line() << "\n"
478  << "truncated: " << renderer_.is_truncated() << "\n"
479  << "renderer size: " << renderer_.get_size() << "\n\n"
480  << std::noboolalpha;
481 
482  const point border(config_->text_extra_width, config_->text_extra_height);
483 
484  // If doesn't fit try the maximum.
485  if(renderer_.is_truncated() && !can_wrap()) {
486  // FIXME if maximum size is defined we should look at that
487  // but also we don't adjust for the extra text space yet!!!
488  maximum_size = point(config_->max_width, 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.
494  point size = renderer_.get_size() + border;
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_)
505  << "' result " << size << ".\n";
506  return size;
507 }
508 
510  bool& handled,
511  const point& location)
512 {
513  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
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(
521  hotkey::GLOBAL__HELPTIP).command);
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 << ".\n";
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 << ".\n";
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 /*WIKI
572  * @page = GUIWidgetInstanceWML
573  * @order = 1_widget
574  *
575  * = Widget =
576  * @begin{parent}{name="generic/"}
577  * @begin{tag}{name="widget_instance"}{min="0"}{max="-1"}
578  * All widgets placed in the cell have some values in common:
579  * @begin{table}{config}
580  * id & string & "" & This value is used for the engine to
581  * identify 'special' items. This means that
582  * for example a text_box can get the proper
583  * initial value. This value should be
584  * unique or empty. Those special values are
585  * documented at the window definition that
586  * uses them. NOTE items starting with an
587  * underscore are used for composed widgets
588  * and these should be unique per composed
589  * widget. $
590  *
591  * definition & string & "default" &
592  * The id of the widget definition to use.
593  * This way it's possible to select a
594  * specific version of the widget e.g. a
595  * title label when the label is used as
596  * title. $
597  *
598  * linked_group & string & "" & The linked group the styled_widget belongs
599  * to. $
600  *
601  * label & t_string & "" & Most widgets have some text associated
602  * with them, this field contain the value
603  * of that text. Some widgets use this value
604  * for other purposes, this is documented
605  * at the widget. E.g. an image uses the
606  * filename in this field. $
607  *
608  * tooltip & t_string & "" & If you hover over a widget a while (the
609  * time it takes can differ per widget) a
610  * short help can show up.This defines the
611  * text of that message. This field may not
612  * be empty when 'help' is set. $
613  *
614  * help & t_string & "" & If you hover over a widget and press F10
615  * (or the key the user defined for the help
616  * tip) a help message can show up. This
617  * help message might be the same as the
618  * tooltip but in general (if used) this
619  * message should show more help. This
620  * defines the text of that message. $
621  *
622  * use_markup & bool & false & Whether to format the text using Pango
623  * markup. Applies to Labels and
624  * other Widgets with text. $
625  *
626  * use_tooltip_on_label_overflow & bool & true &
627  * If the text on the label is truncated and
628  * the tooltip is empty the label can be
629  * used for the tooltip. If this variable is
630  * set to true this will happen. $
631  *
632  * debug_border_mode & unsigned & 0 &
633  * The mode for showing the debug border.
634  * This border shows the area reserved for
635  * a widget. This function is only meant
636  * for debugging and might not be
637  * available in all Wesnoth binaries.
638  * Available modes:
639  * @* 0 no border.
640  * @* 1 1 pixel border.
641  * @* 2 floodfill the widget area. $
642  *
643  * debug_border_color & color & "" & The color of the debug border. $
644  * @end{table}
645  * @end{tag}{name="widget_instance"}
646  * @end{parent}{name="generic/"}
647  */
648 
649 namespace implementation
650 {
651 
652 builder_styled_widget::builder_styled_widget(const config& cfg)
653  : builder_widget(cfg)
654  , definition(cfg["definition"])
655  , label_string(cfg["label"].t_str())
656  , tooltip(cfg["tooltip"].t_str())
657  , help(cfg["help"].t_str())
658  , use_tooltip_on_label_overflow(true)
659  , use_markup(cfg["use_markup"].to_bool(false))
660 {
661  if(definition.empty()) {
662  definition = "default";
663  }
664 
666  help.empty() || !tooltip.empty(),
667  _("Found a widget with a helptip and without a tooltip."),
668  formatter() << "id '" << id << "' label '" << label_string
669  << "' helptip '" << help << "'.");
670 
671 
672  DBG_GUI_P << "Window builder: found styled_widget with id '" << id
673  << "' and definition '" << definition << "'.\n";
674 }
675 
676 widget* builder_styled_widget::build(const replacements_map& /*replacements*/) const
677 {
678  return build();
679 }
680 
681 } // namespace implementation
682 
683 // }------------ END --------------
684 
685 } // namespace gui2
Define the common log macros for the gui toolkit.
std::string encode_text_alignment(const PangoAlignment alignment)
Converts a text alignment to its string representation.
Definition: helper.cpp:78
Contains the info needed to instantiate a widget.
#define DBG_GUI_P
Definition: log.hpp:68
void remove()
Removes a tip.
Definition: tooltip.cpp:189
virtual widget * build() const =0
std::string interpolate_variables_into_string(const std::string &str, const string_map *const symbols)
Function which will interpolate variables, starting with &#39;$&#39; in the string &#39;str&#39; with the equivalent ...
#define DBG_GUI_L
Definition: log.hpp:57
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:164
std::map< std::string, t_string > string_map
void set_layout_size(const point &size)
Definition: widget.cpp:332
SDL_Rect calculate_blitting_rectangle(const int x_offset, const int y_offset)
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:349
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:581
styled_widget(const implementation::builder_styled_widget &builder, const std::string &control_type)
Constructor.
virtual void place(const point &origin, const point &size) override
See widget::place.
bool set_text(const std::string &text, const bool markedup)
Sets the text to render.
Definition: text.cpp:283
void set_help_message(const t_string &help_message)
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
visibility get_visible() const
Definition: widget.cpp:500
Main class to show messages to the user.
Definition: message.hpp:34
virtual void set_members(const string_map &data)
Sets the members of the styled_widget.
virtual bool get_active() const =0
Gets the active state of the styled_widget.
void set_variable(const std::string &key, const wfl::variant &value)
Definition: canvas.hpp:171
const std::string & id() const
Definition: widget.cpp:107
void set_wants_mouse_hover(const bool hover=true)
This file contains the window object, this object is a top level container which has the event manage...
SDL_Rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:307
#define WRN_GUI_L
Definition: log.hpp:59
The message for MESSAGE_SHOW_HELPTIP.
Definition: message.hpp:76
Base class for all widgets.
Definition: widget.hpp:47
pango_text & set_link_aware(bool b)
Definition: text.cpp:448
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...
unsigned get_height() const
Definition: widget.cpp:327
lg::log_domain log_gui_layout("gui/layout")
Definition: log.hpp:56
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
virtual unsigned get_characters_per_line() const
Returns the number of characters per line.
Label showing a text.
Definition: label.hpp:32
Request to show a helptip based on the data sent.
Definition: handler.hpp:114
bool shrunken_
Is the widget smaller as it&#39;s best size?
PangoAlignment decode_text_alignment(const std::string &alignment)
Converts a text alignment string to a text alignment.
Definition: helper.cpp:63
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)
pango_text & set_font_style(const FONT_STYLE font_style)
Definition: text.cpp:343
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Definition: text.cpp:410
virtual point calculate_best_size() const override
See widget::calculate_best_size.
virtual bool text_can_shrink()
Gets whether a widget can shrink past its optimal size even if it&#39;s text-based (such as labels);...
void set_width(const unsigned width)
Definition: canvas.hpp:142
unsigned get_width() const
Definition: widget.cpp:322
int x
x coordinate.
Definition: point.hpp:44
pango_text & set_alignment(const PangoAlignment alignment)
Definition: text.cpp:424
Generic file dialog.
Definition: field-fwd.hpp:22
#define DBG_GUI_D
Definition: log.hpp:28
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
std::string get_names(const std::string &id)
Returns a comma-separated string of hotkey names.
virtual void set_label(const t_string &label)
void blit(surface &surf, SDL_Rect rect)
Blits the canvas unto another surface.
Definition: canvas.cpp:1427
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
std::string definition
Parameters for the styled_widget.
#define LOG_SCOPE_HEADER
bool use_tooltip_on_label_overflow_
If the text doesn&#39;t fit on the label should the text be used as tooltip?
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
std::map< std::string, std::shared_ptr< builder_widget > > replacements_map
The replacements type is used to define replacement types.
void set_tooltip(const t_string &tooltip)
point get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:190
std::string get_token(const point &position, const char *delimiters=" \\) const
Gets the largest collection of characters, including the token at position, and not including any cha...
Definition: text.cpp:202
t_string tooltip_
Tooltip text.
point get_size() const
Returns the pixel size needed for the text.
Definition: text.cpp:107
This file contains the settings handling of the widget library.
virtual void place(const point &origin, const point &size)
Places the widget.
Definition: widget.cpp:235
std::ostringstream wrapper.
Definition: formatter.hpp:38
t_string has_helptip_message
Definition: settings.cpp:44
void signal_handler_show_tooltip(const event::ui_event event, bool &handled, const point &location)
bool is_truncated() const
Has the text been truncated? This happens if it exceeds max width or height.
Definition: text.cpp:114
static color_t from_hex_string(const std::string &c)
Creates a new color_t object from a string variable in hex format.
Definition: color.cpp:61
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:463
The walker abstract base class.
Definition: walker.hpp:26
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
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:234
pango_text & set_font_size(const unsigned font_size)
Definition: text.cpp:331
This file contains the definitions for the gui2::event::message class.
pango_text & set_characters_per_line(const unsigned characters_per_line)
Definition: text.cpp:379
virtual void update_canvas()
Updates the canvas(ses).
uint8_t r
Red value.
Definition: color.hpp:177
uint8_t a
Alpha value.
Definition: color.hpp:186
The message for MESSAGE_SHOW_TOOLTIP.
Definition: message.hpp:58
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
#define log_scope2(domain, description)
Definition: log.hpp:187
virtual void set_text_alignment(const PangoAlignment text_alignment)
#define LOG_HEADER
virtual void set_use_markup(bool use_markup)
int get_text_maximum_width() const
Returns the maximum width available for the text.
std::string get_label_token(const point &position, const char *delimiters=" \\) const
Exposes font::pango_text::get_token, for the text label of this styled_widget.
static tooltip & tip()
Definition: tooltip.cpp:144
void set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
void signal_handler_notify_remove_tooltip(const event::ui_event event, bool &handled)
pango_text & set_family_class(font::family_class fclass)
Definition: text.cpp:320
A simple canvas which can be drawn upon.
Definition: canvas.hpp:41
virtual color_t get_link_color() const
Returns the color string to be used with links.
virtual void impl_draw_foreground(surface &frame_buffer, int x_offset, int y_offset) override
See widget::impl_draw_foreground.
virtual iteration::walker_base * create_walker() override
See widget::create_walker.
point get_config_default_size() const
Gets the default size as defined in the config.
point get_config_minimum_size() const
Gets the minimum size as defined in the config.
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See widget::impl_draw_background.
std::size_t i
Definition: function.cpp:933
std::string get_label_link(const point &position) const
#define DBG_GUI_E
Definition: log.hpp:34
font::pango_text renderer_
Text renderer object used for size calculations.
std::string debug_truncate(const std::string &text)
Returns a truncated version of the text.
Definition: helper.cpp:124
std::vector< canvas > canvases_
Holds all canvas objects for a styled_widget.
point get_best_text_size(point minimum_size, point maximum_size={0, 0}) const
Gets the best size for a text.
t_string label_
Contain the non-editable text associated with styled_widget.
t_string help_message_
Tooltip text.
std::map< std::string, t_string > string_map
Definition: widget.hpp:24
PangoEllipsizeMode text_ellipse_mode_
The ellipsize mode of the text in a styled_widget.
Holds a 2D point.
Definition: point.hpp:23
Request to show a tooltip based on the data sent.
Definition: handler.hpp:112
pango_text & set_link_color(const color_t &color)
Definition: text.cpp:458
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.
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.
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
int get_text_maximum_height() const
Returns the maximum height available for the text.
A walker for a gui2::styled_widget.
pango_text & set_maximum_width(int width)
Definition: text.cpp:364
bool empty() const
Definition: tstring.hpp:182
Contains the SDL_Rect helper code.
The user sets the widget visible, that means:
PangoAlignment text_alignment_
The alignment of the text in a styled_widget.
bool use_markup_
Use markup for the label?
PangoEllipsizeMode get_text_ellipse_mode() const
Get the text&#39;s ellipsize mode.
void set_id(const std::string &id)
Definition: widget.cpp:95
void set_height(const unsigned height)
Definition: canvas.hpp:154
int text_maximum_width_
The maximum width for the text in a styled_widget.
Class to show the tips.
Definition: tooltip.cpp:71
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:130
Definition: help.cpp:56
virtual unsigned get_state() const =0
Returns the id of the state.
virtual widget * find_at(const point &coordinate, const bool must_be_active)
Returns the widget at the wanted coordinates.
Definition: widget.cpp:570
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
virtual bool can_wrap() const
Can the widget wrap.
Definition: widget.cpp:213
uint8_t g
Green value.
Definition: color.hpp:180
uint8_t b
Blue value.
Definition: color.hpp:183
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
canvas & get_canvas(const unsigned index)
resolution_definition_ptr config_
Contains the pointer to the configuration.
int y
y coordinate.
Definition: point.hpp:47
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
ui_event
The event send to the dispatcher.
Definition: handler.hpp:55
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:342
point get_config_maximum_size() const
Gets the best size as defined in the config.
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...
void signal_handler_show_helptip(const event::ui_event event, bool &handled, const point &location)