The Battle for Wesnoth  1.17.0-dev
styled_widget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 "gui/widgets/window.hpp"
30 #include "hotkey/hotkey_item.hpp"
31 #include "sdl/rect.hpp"
32 #include "wml_exception.hpp"
33 #include <functional>
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, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
82 
83  connect_signal<event::SHOW_HELPTIP>(std::bind(
84  &styled_widget::signal_handler_show_helptip, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
85 
86  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
87  &styled_widget::signal_handler_notify_remove_tooltip, this, std::placeholders::_2, std::placeholders::_3));
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  // FIXME: This isn't the most elegant solution. Typically, we don't rely on the text rendering
335  // cache for anything except size calculations, but since we have link awareness now we need to
336  // update its text else `get_label_link` will return old results. I'm not actually sure why the
337  // results seem to only remain one invocation of `set_label` behind the current text, but that
338  // is what testing revealed (see https://github.com/wesnoth/wesnoth/pull/5363).
339  //
340  // -- vultraz, 2020-12-17
342 }
343 
344 void styled_widget::set_use_markup(bool use_markup)
345 {
346  if(use_markup == use_markup_) {
347  return;
348  }
349 
350  use_markup_ = use_markup;
351  update_canvas();
352  set_is_dirty(true);
353 }
354 
355 void styled_widget::set_text_alignment(const PangoAlignment text_alignment)
356 {
357  if(text_alignment_ == text_alignment) {
358  return;
359  }
360 
361  text_alignment_ = text_alignment;
362  update_canvas();
363  set_is_dirty(true);
364 }
365 
366 void styled_widget::set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
367 {
368  if(text_ellipse_mode_ == ellipse_mode) {
369  return;
370  }
371 
372  text_ellipse_mode_ = ellipse_mode;
373  update_canvas();
374  set_is_dirty(true);
375 }
376 
378 {
379  const int max_width = get_text_maximum_width();
380  const int max_height = get_text_maximum_height();
381 
382  // set label in canvases
383  for(auto & canvas : canvases_)
384  {
386  canvas.set_variable("text_markup", wfl::variant(use_markup_));
387  canvas.set_variable("text_link_aware", wfl::variant(get_link_aware()));
388 
389  // Possible TODO: consider making a formula_callable for colors.
390  color_t link_color = get_link_color();
391  std::vector<wfl::variant> link_color_as_list {
392  wfl::variant(link_color.r),
393  wfl::variant(link_color.g),
394  wfl::variant(link_color.b),
395  wfl::variant(link_color.a)
396  };
397 
398  canvas.set_variable("text_link_color", wfl::variant(link_color_as_list));
399  canvas.set_variable("text_alignment",
401  canvas.set_variable("text_maximum_width", wfl::variant(max_width));
402  canvas.set_variable("text_maximum_height", wfl::variant(max_height));
404  canvas.set_variable("text_characters_per_line",
406  }
407 }
408 
410 {
411  if (cached_text_font_size_ == 0) {
412  assert(config_);
413 
415  }
416  return cached_text_font_size_;
417 }
418 
420 {
421  assert(config_);
422 
424  : get_width() - config_->text_extra_width;
425 }
426 
428 {
429  assert(config_);
430 
431  return get_height() - config_->text_extra_height;
432 }
433 
435  int x_offset,
436  int y_offset)
437 {
438  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_) << "' size "
439  << get_rectangle() << ".\n";
440 
441  get_canvas(get_state()).blit(frame_buffer,
442  calculate_blitting_rectangle(x_offset, y_offset));
443 }
444 
446  ,
447  int /*x_offset*/
448  ,
449  int /*y_offset*/)
450 {
451  /* DO NOTHING */
452 }
453 
454 point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const
455 {
457 
458  assert(!label_.empty());
459 
460  // Try with the minimum wanted size.
461  const int maximum_width = text_maximum_width_ != 0
463  : maximum_size.x;
464 
465  /*
466  * NOTE: text rendering does *not* happen here. That happens in the text_shape
467  * canvas class. Instead, this just leverages the pango text rendering engine to
468  * calculate the area this widget will need to successfully render its text later.
469  */
470  renderer_
473  .set_family_class(config_->text_font_family)
475  .set_font_style(config_->text_font_style)
477  .set_maximum_width(maximum_width)
481 
482  if(get_characters_per_line() != 0 && !can_wrap()) {
484  << " Limited the number of characters per line, "
485  << "but wrapping is not set, output may not be as expected.\n";
486  }
487 
488  DBG_GUI_L << LOG_HEADER << "\n"
489  << std::boolalpha
490  << "Label: '" << debug_truncate(label_) << "'\n\n"
491  << "Status:\n"
492  << "minimum_size: " << minimum_size << "\n"
493  << "maximum_size: " << maximum_size << "\n"
494  << "text_maximum_width_: " << text_maximum_width_ << "\n"
495  << "can_wrap: " << can_wrap() << "\n"
496  << "characters_per_line: " << get_characters_per_line() << "\n"
497  << "truncated: " << renderer_.is_truncated() << "\n"
498  << "renderer size: " << renderer_.get_size() << "\n\n"
499  << std::noboolalpha;
500 
501  const point border(config_->text_extra_width, config_->text_extra_height);
502 
503  // If doesn't fit try the maximum.
504  if(renderer_.is_truncated() && !can_wrap()) {
505  // FIXME if maximum size is defined we should look at that
506  // but also we don't adjust for the extra text space yet!!!
507  maximum_size = point(config_->max_width, config_->max_height);
508 
509  renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x : -1);
510  }
511 
512  // Get the resulting size.
513  point size = renderer_.get_size() + border;
514 
515  if(size.x < minimum_size.x) {
516  size.x = minimum_size.x;
517  }
518 
519  if(size.y < minimum_size.y) {
520  size.y = minimum_size.y;
521  }
522 
523  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
524  << "' result " << size << ".\n";
525  return size;
526 }
527 
529  bool& handled,
530  const point& location)
531 {
532  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
533 
534  if(!tooltip_.empty()) {
535  std::string tip = tooltip_;
536  if(!help_message_.empty()) {
537  utils::string_map symbols;
538  symbols["hotkey"] = hotkey::get_names(
540  hotkey::GLOBAL__HELPTIP).command);
541 
544  }
545 
547  handled = fire(event::MESSAGE_SHOW_TOOLTIP, *this, message);
548  }
549 }
550 
552  bool& handled,
553  const point& location)
554 {
555  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
556 
557  if(!help_message_.empty()) {
559  handled = fire(event::MESSAGE_SHOW_HELPTIP, *this, message);
560  }
561 }
562 
564  bool& handled)
565 {
566  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
567 
568  /*
569  * This makes the class know the tip code rather intimately. An
570  * alternative is to add a message to the window to remove the tip.
571  * Might be done later.
572  */
574 
575  handled = true;
576 }
577 
578 std::string styled_widget::get_label_token(const point & position, const char * delim) const
579 {
580  return renderer_.get_token(position, delim);
581 }
582 
583 std::string styled_widget::get_label_link(const point & position) const
584 {
585  return renderer_.get_link(position);
586 }
587 
588 // }---------- BUILDER -----------{
589 
590 namespace implementation
591 {
592 
593 builder_styled_widget::builder_styled_widget(const config& cfg)
594  : builder_widget(cfg)
595  , definition(cfg["definition"])
596  , label_string(cfg["label"].t_str())
597  , tooltip(cfg["tooltip"].t_str())
598  , help(cfg["help"].t_str())
599  , use_tooltip_on_label_overflow(true)
600  , use_markup(cfg["use_markup"].to_bool(false))
601 {
602  if(definition.empty()) {
603  definition = "default";
604  }
605 
607  help.empty() || !tooltip.empty(),
608  _("Found a widget with a helptip and without a tooltip."),
609  formatter() << "id '" << id << "' label '" << label_string
610  << "' helptip '" << help << "'.");
611 
612 
613  DBG_GUI_P << "Window builder: found styled_widget with id '" << id
614  << "' and definition '" << definition << "'.\n";
615 }
616 
617 widget* builder_styled_widget::build(const replacements_map& /*replacements*/) const
618 {
619  return build();
620 }
621 
622 } // namespace implementation
623 
624 // }------------ END --------------
625 
626 } // 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:79
Contains the info needed to instantiate a widget.
#define DBG_GUI_P
Definition: log.hpp:66
void remove()
Removes a tip.
Definition: tooltip.cpp:175
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:55
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:167
std::map< std::string, t_string > string_map
void set_layout_size(const point &size)
Definition: widget.cpp:335
SDL_Rect calculate_blitting_rectangle(const int x_offset, const int y_offset)
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:352
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:584
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)
void set_variable(const std::string &key, wfl::variant &&value)
Definition: canvas.hpp:168
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:503
Main class to show messages to the user.
Definition: message.hpp:35
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.
const std::string & id() const
Definition: widget.cpp:110
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:310
#define WRN_GUI_L
Definition: log.hpp:57
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:330
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:54
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.
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
Request to show a helptip based on the data sent.
Definition: handler.hpp:107
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:64
#define VALIDATE_WITH_DEV_MESSAGE(cond, message, dev_message)
pango_text & set_font_style(const FONT_STYLE font_style)
Definition: text.cpp:343
static std::string _(const char *str)
Definition: gettext.hpp:93
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:144
unsigned get_width() const
Definition: widget.cpp:325
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:100
int x
x coordinate.
Definition: point.hpp:45
pango_text & set_alignment(const PangoAlignment alignment)
Definition: text.cpp:424
Generic file dialog.
Definition: field-fwd.hpp:23
#define DBG_GUI_D
Definition: log.hpp:29
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)
Draw the canvas&#39; shapes onto another surface.
Definition: canvas.cpp:832
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:87
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:193
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:118
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:217
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:238
std::ostringstream wrapper.
Definition: formatter.hpp:39
t_string has_helptip_message
Definition: settings.cpp:48
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:125
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:62
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:466
The walker abstract base class.
Definition: walker.hpp:27
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:178
uint8_t a
Alpha value.
Definition: color.hpp:187
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:219
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:130
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:42
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:967
std::string get_label_link(const point &position) const
#define DBG_GUI_E
Definition: log.hpp:35
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:126
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:24
Request to show a tooltip based on the data sent.
Definition: handler.hpp:105
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:187
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:98
void set_height(const unsigned height)
Definition: canvas.hpp:156
int text_maximum_width_
The maximum width for the text in a styled_widget.
Class to show the tips.
Definition: tooltip.cpp:57
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:69
Definition: help.cpp:57
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:573
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:216
uint8_t g
Green value.
Definition: color.hpp:181
uint8_t b
Blue value.
Definition: color.hpp:184
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
canvas & get_canvas(const unsigned index)
resolution_definition_ptr config_
Contains the pointer to the configuration.
int y
y coordinate.
Definition: point.hpp:48
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:48
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:345
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)