The Battle for Wesnoth  1.15.6+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 #include "utils/functional.hpp"
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.size()) // One canvas per state
57  , renderer_()
58  , text_maximum_width_(0)
59  , text_alignment_(PANGO_ALIGN_LEFT)
60  , text_ellipse_mode_(PANGO_ELLIPSIZE_END)
61  , shrunken_(false)
62 {
63  /*
64  * Fill in each canvas from the widget state definitons.
65  *
66  * Most widgets have a single canvas. However, some widgets such as toggle_panel
67  * and toggle_button have a variable canvas count determined by their definitions.
68  */
69  for(unsigned i = 0; i < config_->state.size(); ++i) {
70  canvases_[i].set_cfg(config_->state[i].canvas_cfg_);
71  }
72 
73  // Initialize all the canvas variables.
74  update_canvas();
75 
76  // Enable hover behavior if a tooltip was provided.
78 
79  connect_signal<event::SHOW_TOOLTIP>(std::bind(
80  &styled_widget::signal_handler_show_tooltip, this, _2, _3, _5));
81 
82  connect_signal<event::SHOW_HELPTIP>(std::bind(
83  &styled_widget::signal_handler_show_helptip, this, _2, _3, _5));
84 
85  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
87 }
88 
90 {
91  /** @todo document this feature on the wiki. */
92  /** @todo do we need to add the debug colors here as well? */
93  string_map::const_iterator itor = data.find("id");
94  if(itor != data.end()) {
95  set_id(itor->second);
96  }
97 
98  itor = data.find("linked_group");
99  if(itor != data.end()) {
100  set_linked_group(itor->second);
101  }
102 
103  itor = data.find("label");
104  if(itor != data.end()) {
105  set_label(itor->second);
106  }
107 
108  itor = data.find("tooltip");
109  if(itor != data.end()) {
110  set_tooltip(itor->second);
111  }
112 
113  itor = data.find("help");
114  if(itor != data.end()) {
115  set_help_message(itor->second);
116  }
117 
118  itor = data.find("use_markup");
119  if(itor != data.end()) {
120  set_use_markup(utils::string_bool(itor->second));
121  }
122 
123  itor = data.find("text_alignment");
124  if(itor != data.end()) {
126  }
127 }
128 
130 {
132 }
133 
135 {
136  return new iteration::walker::widget(*this);
137 }
138 
140 {
141  assert(config_);
142 
143  point result(config_->min_width, config_->min_height);
144 
145  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
146  return result;
147 }
148 
150 {
151  assert(config_);
152 
153  point result(config_->default_width, config_->default_height);
154 
155  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
156  return result;
157 }
158 
160 {
161  assert(config_);
162 
163  point result(config_->max_width, config_->max_height);
164 
165  DBG_GUI_L << LOG_HEADER << " result " << result << ".\n";
166  return result;
167 }
168 
170 {
171  return 0;
172 }
173 
175 {
176  return false;
177 }
178 
180 {
181  return color_t::from_hex_string("ffff00");
182 }
183 
184 void styled_widget::layout_initialize(const bool full_initialization)
185 {
186  // Inherited.
187  widget::layout_initialize(full_initialization);
188 
189  if(full_initialization) {
190  shrunken_ = false;
191  }
192 }
193 
194 void styled_widget::request_reduce_width(const unsigned maximum_width)
195 {
196  assert(config_);
197 
198  if(!label_.empty() && can_wrap()) {
199 
201  point(), point(maximum_width - config_->text_extra_width, 0));
202 
203  size.x += config_->text_extra_width;
204  size.y += config_->text_extra_height;
205 
206  set_layout_size(size);
207 
208  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
209  << "' maximum_width " << maximum_width << " result " << size
210  << ".\n";
211 
212  } else if(label_.empty() || text_can_shrink()) {
215  size.x = std::min(size.x, std::max<int>(maximum_width, min_size.x));
216  set_layout_size(size);
217 
218  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
219  << " maximum_width " << maximum_width << " result " << size
220  << ".\n";
221  } else {
222  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
223  << "' failed; either no label or wrapping not allowed.\n";
224  }
225 }
226 
227 void styled_widget::request_reduce_height(const unsigned maximum_height)
228 {
229  if(!label_.empty()) {
230  // Do nothing
231  } else {
234  size.y = std::min(size.y, std::max<int>(maximum_height, min_size.y));
235  set_layout_size(size);
236 
237  DBG_GUI_L << LOG_HEADER << " styled_widget " << id()
238  << " maximum_height " << maximum_height << " result " << size
239  << ".\n";
240  }
241 }
242 
244 {
245  assert(config_);
246  if(label_.empty()) {
247  DBG_GUI_L << LOG_HEADER << " empty label return default.\n";
248  return get_config_default_size();
249  }
250 
251  const point minimum = get_config_default_size();
252  const point maximum = get_config_maximum_size();
253 
254  /**
255  * @todo The value send should subtract the border size
256  * and read it after calculation to get the proper result.
257  */
258  point result = get_best_text_size(minimum, maximum);
259  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
260  << "' result " << result << ".\n";
261  return result;
262 }
263 
264 void styled_widget::place(const point& origin, const point& size)
265 {
266  // resize canvasses
267  for(auto & canvas : canvases_)
268  {
269  canvas.set_width(size.x);
270  canvas.set_height(size.y);
271  }
272 
273  // Note we assume that the best size has been queried but otherwise it
274  // should return false.
276  && tooltip_.empty()) {
277 
279  }
280 
281  // inherited
282  widget::place(origin, size);
283 
284  // update the state of the canvas after the sizes have been set.
285  update_canvas();
286 }
287 
288 widget* styled_widget::find_at(const point& coordinate, const bool must_be_active)
289 {
290  return (widget::find_at(coordinate, must_be_active)
291  && (!must_be_active || get_active()))
292  ? this
293  : nullptr;
294 }
295 
297  const bool must_be_active) const
298 {
299  return (widget::find_at(coordinate, must_be_active)
300  && (!must_be_active || get_active()))
301  ? this
302  : nullptr;
303 }
304 
305 widget* styled_widget::find(const std::string& id, const bool must_be_active)
306 {
307  return (widget::find(id, must_be_active)
308  && (!must_be_active || get_active()))
309  ? this
310  : nullptr;
311 }
312 
313 const widget* styled_widget::find(const std::string& id, const bool must_be_active)
314  const
315 {
316  return (widget::find(id, must_be_active)
317  && (!must_be_active || get_active()))
318  ? this
319  : nullptr;
320 }
321 
323 {
324  if(label == label_) {
325  return;
326  }
327 
328  label_ = label;
330  update_canvas();
331  set_is_dirty(true);
332 }
333 
334 void styled_widget::set_use_markup(bool use_markup)
335 {
336  if(use_markup == use_markup_) {
337  return;
338  }
339 
340  use_markup_ = use_markup;
341  update_canvas();
342  set_is_dirty(true);
343 }
344 
345 void styled_widget::set_text_alignment(const PangoAlignment text_alignment)
346 {
347  if(text_alignment_ == text_alignment) {
348  return;
349  }
350 
351  text_alignment_ = text_alignment;
352  update_canvas();
353  set_is_dirty(true);
354 }
355 
356 void styled_widget::set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
357 {
358  if(text_ellipse_mode_ == ellipse_mode) {
359  return;
360  }
361 
362  text_ellipse_mode_ = ellipse_mode;
363  update_canvas();
364  set_is_dirty(true);
365 }
366 
368 {
369  const int max_width = get_text_maximum_width();
370  const int max_height = get_text_maximum_height();
371 
372  // set label in canvases
373  for(auto & canvas : canvases_)
374  {
376  canvas.set_variable("text_markup", wfl::variant(use_markup_));
377  canvas.set_variable("text_link_aware", wfl::variant(get_link_aware()));
378 
379  // Possible TODO: consider making a formula_callable for colors.
380  color_t link_color = get_link_color();
381  std::vector<wfl::variant> link_color_as_list {
382  wfl::variant(link_color.r),
383  wfl::variant(link_color.g),
384  wfl::variant(link_color.b),
385  wfl::variant(link_color.a)
386  };
387 
388  canvas.set_variable("text_link_color", wfl::variant(link_color_as_list));
389  canvas.set_variable("text_alignment",
391  canvas.set_variable("text_maximum_width", wfl::variant(max_width));
392  canvas.set_variable("text_maximum_height", wfl::variant(max_height));
394  canvas.set_variable("text_characters_per_line",
396  }
397 }
398 
400 {
401  if (cached_text_font_size_ == 0) {
402  assert(config_);
403 
405  }
406  return cached_text_font_size_;
407 }
408 
410 {
411  assert(config_);
412 
414  : get_width() - config_->text_extra_width;
415 }
416 
418 {
419  assert(config_);
420 
421  return get_height() - config_->text_extra_height;
422 }
423 
425  int x_offset,
426  int y_offset)
427 {
428  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_) << "' size "
429  << get_rectangle() << ".\n";
430 
431  get_canvas(get_state()).blit(frame_buffer,
432  calculate_blitting_rectangle(x_offset, y_offset));
433 }
434 
436  ,
437  int /*x_offset*/
438  ,
439  int /*y_offset*/)
440 {
441  /* DO NOTHING */
442 }
443 
444 point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const
445 {
447 
448  assert(!label_.empty());
449 
450  // Try with the minimum wanted size.
451  const int maximum_width = text_maximum_width_ != 0
453  : maximum_size.x;
454 
455  /*
456  * NOTE: text rendering does *not* happen here. That happens in the text_shape
457  * canvas class. Instead, this just leverages the pango text rendering engine to
458  * calculate the area this widget will need to successfully render its text later.
459  */
460  renderer_
463  .set_family_class(config_->text_font_family)
465  .set_font_style(config_->text_font_style)
467  .set_maximum_width(maximum_width)
471 
472  if(get_characters_per_line() != 0 && !can_wrap()) {
474  << " Limited the number of characters per line, "
475  << "but wrapping is not set, output may not be as expected.\n";
476  }
477 
478  DBG_GUI_L << LOG_HEADER << "\n"
479  << std::boolalpha
480  << "Label: '" << debug_truncate(label_) << "'\n\n"
481  << "Status:\n"
482  << "minimum_size: " << minimum_size << "\n"
483  << "maximum_size: " << maximum_size << "\n"
484  << "text_maximum_width_: " << text_maximum_width_ << "\n"
485  << "can_wrap: " << can_wrap() << "\n"
486  << "characters_per_line: " << get_characters_per_line() << "\n"
487  << "truncated: " << renderer_.is_truncated() << "\n"
488  << "renderer size: " << renderer_.get_size() << "\n\n"
489  << std::noboolalpha;
490 
491  const point border(config_->text_extra_width, config_->text_extra_height);
492 
493  // If doesn't fit try the maximum.
494  if(renderer_.is_truncated() && !can_wrap()) {
495  // FIXME if maximum size is defined we should look at that
496  // but also we don't adjust for the extra text space yet!!!
497  maximum_size = point(config_->max_width, config_->max_height);
498 
499  renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x : -1);
500  }
501 
502  // Get the resulting size.
503  point size = renderer_.get_size() + border;
504 
505  if(size.x < minimum_size.x) {
506  size.x = minimum_size.x;
507  }
508 
509  if(size.y < minimum_size.y) {
510  size.y = minimum_size.y;
511  }
512 
513  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
514  << "' result " << size << ".\n";
515  return size;
516 }
517 
519  bool& handled,
520  const point& location)
521 {
522  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
523 
524  if(!tooltip_.empty()) {
526  if(!help_message_.empty()) {
527  utils::string_map symbols;
528  symbols["hotkey"] = hotkey::get_names(
530  hotkey::GLOBAL__HELPTIP).command);
531 
534  }
535 
537  handled = fire(event::MESSAGE_SHOW_TOOLTIP, *this, message);
538  }
539 }
540 
542  bool& handled,
543  const point& location)
544 {
545  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
546 
547  if(!help_message_.empty()) {
549  handled = fire(event::MESSAGE_SHOW_HELPTIP, *this, message);
550  }
551 }
552 
554  bool& handled)
555 {
556  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
557 
558  /*
559  * This makes the class know the tip code rather intimately. An
560  * alternative is to add a message to the window to remove the tip.
561  * Might be done later.
562  */
564 
565  handled = true;
566 }
567 
568 std::string styled_widget::get_label_token(const point & position, const char * delim) const
569 {
570  return renderer_.get_token(position, delim);
571 }
572 
574 {
575  return renderer_.get_link(position);
576 }
577 
578 // }---------- BUILDER -----------{
579 
580 /*WIKI
581  * @page = GUIWidgetInstanceWML
582  * @order = 1_widget
583  *
584  * = Widget =
585  * @begin{parent}{name="generic/"}
586  * @begin{tag}{name="widget_instance"}{min="0"}{max="-1"}
587  * All widgets placed in the cell have some values in common:
588  * @begin{table}{config}
589  * id & string & "" & This value is used for the engine to
590  * identify 'special' items. This means that
591  * for example a text_box can get the proper
592  * initial value. This value should be
593  * unique or empty. Those special values are
594  * documented at the window definition that
595  * uses them. NOTE items starting with an
596  * underscore are used for composed widgets
597  * and these should be unique per composed
598  * widget. $
599  *
600  * definition & string & "default" &
601  * The id of the widget definition to use.
602  * This way it's possible to select a
603  * specific version of the widget e.g. a
604  * title label when the label is used as
605  * title. $
606  *
607  * linked_group & string & "" & The linked group the styled_widget belongs
608  * to. $
609  *
610  * label & t_string & "" & Most widgets have some text associated
611  * with them, this field contain the value
612  * of that text. Some widgets use this value
613  * for other purposes, this is documented
614  * at the widget. E.g. an image uses the
615  * filename in this field. $
616  *
617  * tooltip & t_string & "" & If you hover over a widget a while (the
618  * time it takes can differ per widget) a
619  * short help can show up.This defines the
620  * text of that message. This field may not
621  * be empty when 'help' is set. $
622  *
623  * help & t_string & "" & If you hover over a widget and press F10
624  * (or the key the user defined for the help
625  * tip) a help message can show up. This
626  * help message might be the same as the
627  * tooltip but in general (if used) this
628  * message should show more help. This
629  * defines the text of that message. $
630  *
631  * use_markup & bool & false & Whether to format the text using Pango
632  * markup. Applies to Labels and
633  * other Widgets with text. $
634  *
635  * use_tooltip_on_label_overflow & bool & true &
636  * If the text on the label is truncated and
637  * the tooltip is empty the label can be
638  * used for the tooltip. If this variable is
639  * set to true this will happen. $
640  *
641  * debug_border_mode & unsigned & 0 &
642  * The mode for showing the debug border.
643  * This border shows the area reserved for
644  * a widget. This function is only meant
645  * for debugging and might not be
646  * available in all Wesnoth binaries.
647  * Available modes:
648  * @* 0 no border.
649  * @* 1 1 pixel border.
650  * @* 2 floodfill the widget area. $
651  *
652  * debug_border_color & color & "" & The color of the debug border. $
653  * @end{table}
654  * @end{tag}{name="widget_instance"}
655  * @end{parent}{name="generic/"}
656  */
657 
658 namespace implementation
659 {
660 
661 builder_styled_widget::builder_styled_widget(const config& cfg)
662  : builder_widget(cfg)
663  , definition(cfg["definition"])
664  , label_string(cfg["label"].t_str())
665  , tooltip(cfg["tooltip"].t_str())
666  , help(cfg["help"].t_str())
667  , use_tooltip_on_label_overflow(true)
668  , use_markup(cfg["use_markup"].to_bool(false))
669 {
670  if(definition.empty()) {
671  definition = "default";
672  }
673 
675  help.empty() || !tooltip.empty(),
676  _("Found a widget with a helptip and without a tooltip."),
677  formatter() << "id '" << id << "' label '" << label_string
678  << "' helptip '" << help << "'.");
679 
680 
681  DBG_GUI_P << "Window builder: found styled_widget with id '" << id
682  << "' and definition '" << definition << "'.\n";
683 }
684 
685 widget* builder_styled_widget::build(const replacements_map& /*replacements*/) const
686 {
687  return build();
688 }
689 
690 } // namespace implementation
691 
692 // }------------ END --------------
693 
694 } // 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:65
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:54
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:166
std::map< std::string, t_string > string_map
void set_layout_size(const point &size)
Definition: widget.cpp:334
SDL_Rect calculate_blitting_rectangle(const int x_offset, const int y_offset)
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:351
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:583
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:502
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:109
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:309
#define WRN_GUI_L
Definition: log.hpp:56
The message for MESSAGE_SHOW_HELPTIP.
Definition: message.hpp:76
Base class for all widgets.
Definition: widget.hpp:49
pango_text & set_link_aware(bool b)
Definition: text.cpp:448
unsigned int get_text_font_size() const
Resolves and returns the text_font_size.
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:329
unsigned int cached_text_font_size_
Contains the evaluated text_font_size from the configuration.
lg::log_domain log_gui_layout("gui/layout")
Definition: log.hpp:53
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:106
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:324
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:99
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:1429
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:100
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::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:192
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:237
std::ostringstream wrapper.
Definition: formatter.hpp:38
t_string has_helptip_message
Definition: settings.cpp:47
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:465
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:205
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
u64 size
Definition: statement.cpp:80
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:125
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:26
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:104
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:97
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:68
Definition: help.cpp:55
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:572
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:215
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:47
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:344
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)