The Battle for Wesnoth  1.15.13+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 <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.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, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
81 
82  connect_signal<event::SHOW_HELPTIP>(std::bind(
83  &styled_widget::signal_handler_show_helptip, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5));
84 
85  connect_signal<event::NOTIFY_REMOVE_TOOLTIP>(std::bind(
86  &styled_widget::signal_handler_notify_remove_tooltip, this, std::placeholders::_2, std::placeholders::_3));
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  // FIXME: This isn't the most elegant solution. Typically, we don't rely on the text rendering
334  // cache for anything except size calculations, but since we have link awareness now we need to
335  // update its text else `get_label_link` will return old results. I'm not actually sure why the
336  // results seem to only remain one invocation of `set_label` behind the current text, but that
337  // is what testing revealed (see https://github.com/wesnoth/wesnoth/pull/5363).
338  //
339  // -- vultraz, 2020-12-17
341 }
342 
343 void styled_widget::set_use_markup(bool use_markup)
344 {
345  if(use_markup == use_markup_) {
346  return;
347  }
348 
349  use_markup_ = use_markup;
350  update_canvas();
351  set_is_dirty(true);
352 }
353 
354 void styled_widget::set_text_alignment(const PangoAlignment text_alignment)
355 {
356  if(text_alignment_ == text_alignment) {
357  return;
358  }
359 
360  text_alignment_ = text_alignment;
361  update_canvas();
362  set_is_dirty(true);
363 }
364 
365 void styled_widget::set_text_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
366 {
367  if(text_ellipse_mode_ == ellipse_mode) {
368  return;
369  }
370 
371  text_ellipse_mode_ = ellipse_mode;
372  update_canvas();
373  set_is_dirty(true);
374 }
375 
377 {
378  const int max_width = get_text_maximum_width();
379  const int max_height = get_text_maximum_height();
380 
381  // set label in canvases
382  for(auto & canvas : canvases_)
383  {
385  canvas.set_variable("text_markup", wfl::variant(use_markup_));
386  canvas.set_variable("text_link_aware", wfl::variant(get_link_aware()));
387 
388  // Possible TODO: consider making a formula_callable for colors.
389  color_t link_color = get_link_color();
390  std::vector<wfl::variant> link_color_as_list {
391  wfl::variant(link_color.r),
392  wfl::variant(link_color.g),
393  wfl::variant(link_color.b),
394  wfl::variant(link_color.a)
395  };
396 
397  canvas.set_variable("text_link_color", wfl::variant(link_color_as_list));
398  canvas.set_variable("text_alignment",
400  canvas.set_variable("text_maximum_width", wfl::variant(max_width));
401  canvas.set_variable("text_maximum_height", wfl::variant(max_height));
403  canvas.set_variable("text_characters_per_line",
405  }
406 }
407 
409 {
410  if (cached_text_font_size_ == 0) {
411  assert(config_);
412 
414  }
415  return cached_text_font_size_;
416 }
417 
419 {
420  assert(config_);
421 
423  : get_width() - config_->text_extra_width;
424 }
425 
427 {
428  assert(config_);
429 
430  return get_height() - config_->text_extra_height;
431 }
432 
434  int x_offset,
435  int y_offset)
436 {
437  DBG_GUI_D << LOG_HEADER << " label '" << debug_truncate(label_) << "' size "
438  << get_rectangle() << ".\n";
439 
440  get_canvas(get_state()).blit(frame_buffer,
441  calculate_blitting_rectangle(x_offset, y_offset));
442 }
443 
445  ,
446  int /*x_offset*/
447  ,
448  int /*y_offset*/)
449 {
450  /* DO NOTHING */
451 }
452 
453 point styled_widget::get_best_text_size(point minimum_size, point maximum_size) const
454 {
456 
457  assert(!label_.empty());
458 
459  // Try with the minimum wanted size.
460  const int maximum_width = text_maximum_width_ != 0
462  : maximum_size.x;
463 
464  /*
465  * NOTE: text rendering does *not* happen here. That happens in the text_shape
466  * canvas class. Instead, this just leverages the pango text rendering engine to
467  * calculate the area this widget will need to successfully render its text later.
468  */
469  renderer_
472  .set_family_class(config_->text_font_family)
474  .set_font_style(config_->text_font_style)
476  .set_maximum_width(maximum_width)
480 
481  if(get_characters_per_line() != 0 && !can_wrap()) {
483  << " Limited the number of characters per line, "
484  << "but wrapping is not set, output may not be as expected.\n";
485  }
486 
487  DBG_GUI_L << LOG_HEADER << "\n"
488  << std::boolalpha
489  << "Label: '" << debug_truncate(label_) << "'\n\n"
490  << "Status:\n"
491  << "minimum_size: " << minimum_size << "\n"
492  << "maximum_size: " << maximum_size << "\n"
493  << "text_maximum_width_: " << text_maximum_width_ << "\n"
494  << "can_wrap: " << can_wrap() << "\n"
495  << "characters_per_line: " << get_characters_per_line() << "\n"
496  << "truncated: " << renderer_.is_truncated() << "\n"
497  << "renderer size: " << renderer_.get_size() << "\n\n"
498  << std::noboolalpha;
499 
500  const point border(config_->text_extra_width, config_->text_extra_height);
501 
502  // If doesn't fit try the maximum.
503  if(renderer_.is_truncated() && !can_wrap()) {
504  // FIXME if maximum size is defined we should look at that
505  // but also we don't adjust for the extra text space yet!!!
506  maximum_size = point(config_->max_width, config_->max_height);
507 
508  renderer_.set_maximum_width(maximum_size.x ? maximum_size.x - border.x : -1);
509  }
510 
511  // Get the resulting size.
512  point size = renderer_.get_size() + border;
513 
514  if(size.x < minimum_size.x) {
515  size.x = minimum_size.x;
516  }
517 
518  if(size.y < minimum_size.y) {
519  size.y = minimum_size.y;
520  }
521 
522  DBG_GUI_L << LOG_HEADER << " label '" << debug_truncate(label_)
523  << "' result " << size << ".\n";
524  return size;
525 }
526 
528  bool& handled,
529  const point& location)
530 {
531  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
532 
533  if(!tooltip_.empty()) {
534  std::string tip = tooltip_;
535  if(!help_message_.empty()) {
536  utils::string_map symbols;
537  symbols["hotkey"] = hotkey::get_names(
539  hotkey::GLOBAL__HELPTIP).command);
540 
543  }
544 
546  handled = fire(event::MESSAGE_SHOW_TOOLTIP, *this, message);
547  }
548 }
549 
551  bool& handled,
552  const point& location)
553 {
554  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
555 
556  if(!help_message_.empty()) {
558  handled = fire(event::MESSAGE_SHOW_HELPTIP, *this, message);
559  }
560 }
561 
563  bool& handled)
564 {
565  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
566 
567  /*
568  * This makes the class know the tip code rather intimately. An
569  * alternative is to add a message to the window to remove the tip.
570  * Might be done later.
571  */
573 
574  handled = true;
575 }
576 
577 std::string styled_widget::get_label_token(const point & position, const char * delim) const
578 {
579  return renderer_.get_token(position, delim);
580 }
581 
582 std::string styled_widget::get_label_link(const point & position) const
583 {
584  return renderer_.get_link(position);
585 }
586 
587 // }---------- BUILDER -----------{
588 
589 namespace implementation
590 {
591 
592 builder_styled_widget::builder_styled_widget(const config& cfg)
593  : builder_widget(cfg)
594  , definition(cfg["definition"])
595  , label_string(cfg["label"].t_str())
596  , tooltip(cfg["tooltip"].t_str())
597  , help(cfg["help"].t_str())
598  , use_tooltip_on_label_overflow(true)
599  , use_markup(cfg["use_markup"].to_bool(false))
600 {
601  if(definition.empty()) {
602  definition = "default";
603  }
604 
606  help.empty() || !tooltip.empty(),
607  _("Found a widget with a helptip and without a tooltip."),
608  formatter() << "id '" << id << "' label '" << label_string
609  << "' helptip '" << help << "'.");
610 
611 
612  DBG_GUI_P << "Window builder: found styled_widget with id '" << id
613  << "' and definition '" << definition << "'.\n";
614 }
615 
616 widget* builder_styled_widget::build(const replacements_map& /*replacements*/) const
617 {
618  return build();
619 }
620 
621 } // namespace implementation
622 
623 // }------------ END --------------
624 
625 } // 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:174
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:282
void set_help_message(const t_string &help_message)
void set_variable(const std::string &key, wfl::variant &&value)
Definition: canvas.hpp:167
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.
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:447
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.
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
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:342
static std::string _(const char *str)
Definition: gettext.hpp:92
pango_text & set_ellipse_mode(const PangoEllipsizeMode ellipse_mode)
Definition: text.cpp:409
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:143
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:423
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)
Draw the canvas&#39; shapes onto another surface.
Definition: canvas.cpp:825
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: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:201
t_string tooltip_
Tooltip text.
point get_size() const
Returns the pixel size needed for the text.
Definition: text.cpp:117
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:216
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:124
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:233
pango_text & set_font_size(const unsigned font_size)
Definition: text.cpp:330
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:378
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:207
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:129
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:319
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:940
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: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:457
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:363
bool empty() const
Definition: tstring.hpp:186
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:155
int text_maximum_width_
The maximum width for the text in a styled_widget.
Class to show the tips.
Definition: tooltip.cpp:56
bool fire(const ui_event event, widget &target)
Fires an event which has no extra parameters.
Definition: dispatcher.cpp:68
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: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:59
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)