The Battle for Wesnoth  1.19.0-dev
widget.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
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 #pragma once
17 
18 #include "color.hpp"
21 #include "scripting/lua_ptr.hpp"
22 #include "sdl/point.hpp"
23 #include "sdl/rect.hpp"
24 
25 #include <string>
26 
27 
28 namespace gui2
29 {
30 /* Data format used by styled_widget::set_members to set settings for a single widget. */
31 using widget_item = std::map<std::string, t_string>;
32 
33 /* Indexes multiple @ref widget_item maps by widget ID. */
34 using widget_data = std::map<std::string, widget_item>;
35 
36 struct builder_widget;
37 class window;
38 class grid;
39 
40 namespace iteration
41 {
42 using walker_ptr = std::unique_ptr<class walker_base>;
43 } // namespace iteration
44 
45 /**
46  * Base class for all widgets.
47  *
48  * From this abstract all other widgets should derive. It contains the minimal
49  * info needed for a real widget and some pure abstract functions which need to
50  * be implemented by classes deriving from this class.
51  */
52 class widget : public event_executor, public event::dispatcher, public enable_lua_ptr<widget>
53 {
54  friend class debug_layout_graph;
55  friend class window; // needed for modifying the layout_size.
56 
57 
58  /***** ***** ***** ***** ***** Types. ***** ***** ***** ***** *****/
59 
60 public:
61  /** Visibility settings done by the user. */
62  enum class visibility
63  {
64  /**
65  * The user sets the widget visible, that means:
66  * * The widget is visible.
67  * * @ref find_at always 'sees' the widget (the active flag is
68  * tested later).
69  * * The widget (if active) handles events (and sends events to
70  * its children).
71  * * The widget is drawn.
72  */
73  visible,
74 
75  /**
76  * The user sets the widget hidden, that means:
77  * * The widget is invisible but keeps its size.
78  * * @ref find_at 'sees' the widget if active is @c false.
79  * * The widget doesn't handle events (and doesn't send events to
80  * its children).
81  */
82  hidden,
83 
84  /**
85  * The user set the widget invisible, that means:
86  * * The widget is invisible and its grid cell has size 0,0.
87  * * @ref find_at never 'sees' the widget.
88  * * The widget doesn't handle events (and doesn't send events to
89  * its children).
90  */
91  invisible
92  };
93 
94  /**
95  * Visibility set by the engine.
96  *
97  * This state only will be used if @ref visible_ is @ref visibility::visible
98  * depending on this state the widget might not be visible after all.
99  */
100  enum class redraw_action
101  {
102  // TODO: draw_manager/hwaccel - are these still useful?
103  /**
104  * The widget is fully visible.
105  *
106  * The widget should be drawn. The entire widget's rectangle
107  * should be redrawn.
108  */
109  full,
110 
111  /**
112  * The widget is partly visible.
113  *
114  * The should be drawn. The rectangle to redraw in determined
115  * by @ref clipping_rectangle_
116  */
117  partly,
118 
119  /**
120  * The widget is not visible.
121  *
122  * The widget should not be drawn.
123  */
124  none
125  };
126 
127  enum class debug_border {
128  /** No border. */
129  none,
130  /** Single-pixel outline. */
131  outline,
132  /** Flood-filled rectangle. */
133  fill,
134  };
135 
136  /***** ***** ***** Constructor and destructor. ***** ***** *****/
137 
138 public:
139  widget(const widget&) = delete;
140  widget& operator=(const widget&) = delete;
141 
142  /** @deprecated use the second overload. */
143  widget();
144 
145  /**
146  * Constructor.
147  *
148  * @param builder The builder object with the settings for the
149  * object.
150  */
151  explicit widget(const builder_widget& builder);
152 
153  virtual ~widget() override;
154 
155 
156  /***** ***** ***** ***** ID functions. ***** ***** ***** *****/
157 
158 public:
159  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
160 
161  void set_id(const std::string& id);
162  const std::string& id() const;
163 
164  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
165 
166 private:
167  /**
168  * The id is the unique name of the widget in a certain context.
169  *
170  * This is needed for certain widgets so the engine knows which widget is
171  * which. E.g. it knows which button is pressed and thus which engine action
172  * is connected to the button. This doesn't mean that the id is unique in a
173  * window, e.g. a listbox can have the same id for every row.
174  */
175  std::string id_;
176 
177 
178  /***** ***** ***** ***** Parent functions ***** ***** ***** *****/
179 
180 public:
181  /**
182  * Get the parent window.
183  *
184  * @returns Pointer to parent window.
185  * @retval nullptr No parent window found.
186  */
187  window* get_window();
188 
189  /** The constant version of @ref get_window. */
190  const window* get_window() const;
191 
192  /**
193  * Get the parent grid.
194  *
195  * @returns Pointer to parent grid.
196  * @retval nullptr No parent grid found.
197  */
199 
200  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
201 
202  void set_parent(widget* parent);
203  widget* parent();
204 
205  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
206 
207 private:
208  /**
209  * The parent widget.
210  *
211  * If the widget has a parent it contains a pointer to the parent, else it
212  * is set to @c nullptr.
213  */
215 
216 
217  /***** ***** ***** ***** Size and layout functions. ***** ***** ***** *****/
218 
219 public:
220  /**
221  * How the layout engine works.
222  *
223  * Every widget has a member @ref layout_size_ which holds the best size in
224  * the current layout phase. When the windows starts the layout phase it
225  * calls @ref layout_initialize which resets this value.
226  *
227  * Every widget has two function to get the best size. @ref get_best_size
228  * tests whether layout_size_ is set and if so returns that value otherwise
229  * it calls @ref calculate_best_size so the size can be updated.
230  *
231  * During the layout phase some functions can modify layout_size_ so the
232  * next call to @ref get_best_size returns the currently best size. This
233  * means that after the layout phase @ref get_best_size still returns this
234  * value.
235  */
236 
237  /**
238  * Initialises the layout phase.
239  *
240  * Clears the initial best size for the widgets.
241  *
242  * See @ref layout_algorithm for more information.
243  *
244  * @param full_initialization For widgets with scrollbars it hides them
245  * unless the mode is
246  * scrollbar_mode::ALWAYS_VISIBLE. For
247  * other widgets this flag is a @em NOP.
248  */
249  virtual void layout_initialize(const bool full_initialization);
250 
251  /**
252  * Tries to reduce the width of a widget.
253  *
254  * This function tries to do it 'friendly' and only use scrollbars or
255  * tries to wrap the widget.
256  *
257  * See @ref layout_algorithm for more information.
258  *
259  * @param maximum_width The wanted maximum width.
260  */
261  virtual void request_reduce_width(const unsigned maximum_width) = 0;
262 
263  /**
264  * Tries to reduce the width of a widget.
265  *
266  * This function does it more aggressively and should only be used when
267  * using scrollbars and wrapping failed.
268  *
269  * @todo Make pure virtual.
270  *
271  * See @ref layout_algorithm for more information.
272  *
273  * @param maximum_width The wanted maximum width.
274  */
275  virtual void demand_reduce_width(const unsigned maximum_width);
276 
277  /**
278  * Tries to reduce the height of a widget.
279  *
280  * This function tries to do it 'friendly' and only use scrollbars.
281  *
282  * @todo Make pure virtual.
283  *
284  * See @ref layout_algorithm for more information.
285  *
286  * @param maximum_height The wanted maximum height.
287  */
288  virtual void request_reduce_height(const unsigned maximum_height);
289 
290  /**
291  * Tries to reduce the height of a widget.
292  *
293  * This function does it more aggressively and should only be used when
294  * using scrollbars failed.
295  *
296  * @todo Make pure virtual.
297  *
298  * See @ref layout_algorithm for more information.
299  *
300  * @param maximum_height The wanted maximum height.
301  */
302  virtual void demand_reduce_height(const unsigned maximum_height);
303 
304  /**
305  * Gets the best size for the widget.
306  *
307  * During the layout phase a best size will be determined, several stages
308  * might change the best size. This function will return the currently best
309  * size as determined during the layout phase.
310  *
311  * @returns The best size for the widget.
312  */
313  point get_best_size() const;
314 
315 private:
316  /**
317  * Calculates the best size.
318  *
319  * This function calculates the best size and ignores the current values in
320  * the layout phase. Note containers can call the @ref get_best_size() of
321  * their children since it is meant to update itself.
322  *
323  * @returns The best size for the widget.
324  */
325  virtual point calculate_best_size() const = 0;
326 
327 public:
328  /**
329  * Whether the mouse move/click event go 'through' this widget.
330  */
331  virtual bool can_mouse_focus() const { return true; }
332  /**
333  * Can the widget wrap.
334  *
335  * When a widget can wrap it can reduce its width by increasing its
336  * height. When a layout is too wide it should first try to wrap and if
337  * that fails it should check the vertical scrollbar status. After wrapping
338  * the height might (probably will) change so the layout engine needs to
339  * recalculate the height after wrapping.
340  */
341  virtual bool can_wrap() const;
342 
343  /**
344  * Sets the origin of the widget.
345  *
346  * This function can be used to move the widget without triggering a
347  * redraw. The location is an absolute position, if a relative move is
348  * required use @ref move.
349  *
350  * @param origin The new origin.
351  */
352  virtual void set_origin(const point& origin);
353 
354  /**
355  * Sets the size of the widget.
356  *
357  * This version is meant to resize a widget, since the origin isn't
358  * modified. This can be used if a widget needs to change its size and the
359  * layout will be fixed later.
360  *
361  * @param size The size of the widget.
362  */
363  virtual void set_size(const point& size);
364 
365  /**
366  * Places the widget.
367  *
368  * This function is normally called by a layout function to do the
369  * placement of a widget.
370  *
371  * @param origin The position of top left of the widget.
372  * @param size The size of the widget.
373  */
374  virtual void place(const point& origin, const point& size);
375 
376  /**
377  * Moves a widget.
378  *
379  * This function can be used to move the widget without queueing a redraw.
380  *
381  * @todo Implement the function to all derived classes.
382  *
383  * @param x_offset The amount of pixels to move the widget in
384  * the x-direction.
385  * @param y_offset The amount of pixels to move the widget in
386  * the y-direction.
387  */
388  virtual void move(const int x_offset, const int y_offset);
389 
390  /**
391  * Sets the horizontal alignment of the widget within its parent grid.
392  *
393  * @param alignment The new alignment.
394  */
395  virtual void set_horizontal_alignment(const std::string& alignment);
396 
397  /**
398  * Sets the horizontal alignment of the widget within its parent grid.
399  *
400  * @param alignment The new alignment.
401  */
402  virtual void set_vertical_alignment(const std::string& alignment);
403 
404  /**
405  * Allows a widget to update its children.
406  *
407  * Before the window is populating the dirty list the widgets can update
408  * their content, which allows delayed initialization. This delayed
409  * initialization is only allowed if the widget resizes itself, not when
410  * being placed.
411  */
412  virtual void layout_children();
413 
414  /**
415  * Returns the screen origin of the widget.
416  *
417  * @returns The origin of the widget.
418  */
419  point get_origin() const;
420 
421  /**
422  * Returns the size of the widget.
423  *
424  * @returns The size of the widget.
425  */
426  point get_size() const;
427 
428  /**
429  * Gets the bounding rectangle of the widget on the screen.
430  *
431  * @returns The bounding rectangle of the widget.
432  */
433  rect get_rectangle() const;
434 
435  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
436 
437  int get_x() const;
438 
439  int get_y() const;
440 
441  unsigned get_width() const;
442 
443  unsigned get_height() const;
444 
445 protected:
446  void set_layout_size(const point& size);
447  const point& layout_size() const;
448 
449  /**
450  * Throws away @ref layout_size_.
451  *
452  * Use with care: this function does not recurse to child widgets.
453  *
454  * See @ref layout_algorithm for more information.
455  */
457 
458 public:
459  void set_linked_group(const std::string& linked_group);
460 
461  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
462 
463 private:
464  /** The x-coordinate of the widget on the screen. */
465  int x_;
466 
467  /** The y-coordinate of the widget on the screen. */
468  int y_;
469 
470  /** The width of the widget. */
471  unsigned width_;
472 
473  /** The height of the widget. */
474  unsigned height_;
475 
476  /**
477  * The best size for the widget.
478  *
479  * When 0,0 the real best size is returned, but in the layout phase a
480  * wrapping or a scrollbar might change the best size for that widget.
481  * This variable holds that best value.
482  *
483  * If the widget size hasn't been changed from the default that
484  * calculate_best_size() returns, layout_size_ is (0,0).
485  */
487 
488 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
489 
490  /**
491  * Debug helper to store last value of get_best_size().
492  *
493  * We're mutable so calls can stay const and this is disabled in
494  * production code.
495  */
496  mutable point last_best_size_;
497 
498 #endif
499 
500  /**
501  * The linked group the widget belongs to.
502  *
503  * @todo For now the linked group is initialized when the layout of the
504  * widget is initialized. The best time to set it would be upon adding the
505  * widget in the window. Need to look whether it is possible in a clean way.
506  * Maybe a signal just prior to showing a window where the widget can do
507  * some of it's on things, would also be nice for widgets that need a
508  * finalizer function.
509  */
510  std::string linked_group_;
511 
512 
513  /***** ***** ***** ***** Drawing functions. ***** ***** ***** *****/
514 
515 public:
516  /**
517  * Calculates the blitting rectangle of the widget.
518  *
519  * The blitting rectangle is the entire widget rectangle.
520  *
521  * @returns The drawing rectangle.
522  */
523  SDL_Rect calculate_blitting_rectangle() const;
524 
525  /**
526  * Calculates the clipping rectangle of the widget.
527  *
528  * The clipping rectangle is used then the @ref redraw_action_ is
529  * @ref redraw_action::partly.
530  *
531  * @returns The clipping rectangle.
532  */
533  SDL_Rect calculate_clipping_rectangle() const;
534 
535  /**
536  * Draws the background of a widget.
537  *
538  * Derived should override @ref impl_draw_background instead of changing
539  * this function.
540  *
541  * @returns False if drawing should be deferred.
542  */
543  bool draw_background();
544 
545  /**
546  * Draws the children of a widget.
547  *
548  * Containers should draw their children when they get this request.
549  *
550  * Derived should override @ref impl_draw_children instead of changing
551  * this function.
552  */
553  void draw_children();
554 
555  /**
556  * Draws the foreground of the widget.
557  *
558  * Some widgets e.g. panel and window have a back and foreground layer this
559  * function requests the drawing of the foreground.
560  *
561  * Derived should override @ref impl_draw_foreground instead of changing
562  * this function.
563  *
564  * @returns False if drawing should be deferred.
565  */
566  bool draw_foreground();
567 
568 private:
569  /** See @ref draw_background. */
570  virtual bool impl_draw_background()
571  {
572  return true;
573  }
574 
575  /** See @ref draw_children. */
576  virtual void impl_draw_children()
577  {
578  }
579 
580  /** See @ref draw_foreground. */
581  virtual bool impl_draw_foreground()
582  {
583  return true;
584  }
585 
586 public:
587  /**
588  * Gets the dirty rectangle of the widget.
589  *
590  * Depending on the @ref redraw_action_ it returns the rectangle this
591  * widget dirties while redrawing.
592  *
593  * @returns The dirty rectangle.
594  */
595  SDL_Rect get_dirty_rectangle() const;
596 
597  /**
598  * Sets the visible rectangle for a widget.
599  *
600  * This function sets the @ref redraw_action_ and the
601  * @ref clipping_rectangle_.
602  *
603  * @param rectangle The visible rectangle in screen coordinates.
604  */
605  virtual void set_visible_rectangle(const SDL_Rect& rectangle);
606 
607  /**
608  * Indicates that this widget should be redrawn.
609  *
610  * This function should be called by widgets whenever their visible
611  * state changes.
612  */
613  void queue_redraw();
614 
615  /**
616  * Indicate that specific region of the screen should be redrawn.
617  *
618  * This is in absolute drawing-space coordinates, and not constrained
619  * to the current widget.
620  */
621  void queue_redraw(const rect& region);
622 
623  /*** *** *** *** *** *** Setters and getters. *** *** *** *** *** ***/
624 
625  void set_visible(const visibility visible);
626  visibility get_visible() const;
627 
629 
630  void set_debug_border_mode(const debug_border debug_border_mode);
631 
632  void set_debug_border_color(const color_t debug_border_color);
633 
634  /*** *** *** *** *** *** *** *** Members. *** *** *** *** *** *** *** ***/
635 
636 private:
637  /** Field for the status of the visibility. */
639 
640  /** Field for the action to do on a drawing request. */
642 
643  /** The clipping rectangle if a widget is partly visible. */
645 
646  /**
647  * Mode for drawing the debug border.
648  *
649  * The debug border is a helper border to determine where a widget is
650  * placed. It is only intended for debugging purposes.
651  */
653 
654  /** The color for the debug border. */
656 
657  void draw_debug_border();
658 
659  /***** ***** ***** ***** Query functions ***** ***** ***** *****/
660 
661 public:
662  /**
663  * Returns the widget at the wanted coordinates.
664  *
665  * @param coordinate The coordinate which should be inside the
666  * widget.
667  * @param must_be_active The widget should be active, not all widgets
668  * have an active flag, those who don't ignore
669  * flag.
670  *
671  * @returns The widget with the id.
672  * @retval nullptr No widget at the wanted coordinate found (or
673  * not active if must_be_active was set).
674  */
675  virtual widget* find_at(const point& coordinate,
676  const bool must_be_active);
677 
678  /** The constant version of @ref find_at. */
679  virtual const widget* find_at(const point& coordinate,
680  const bool must_be_active) const;
681 
682  /**
683  * Returns @em a widget with the wanted id.
684  *
685  * @note Since the id might not be unique inside a container there is no
686  * guarantee which widget is returned.
687  *
688  * @param id The id of the widget to find.
689  * @param must_be_active The widget should be active, not all widgets
690  * have an active flag, those who don't ignore
691  * flag.
692  *
693  * @returns The widget with the id.
694  * @retval nullptr No widget with the id found (or not active if
695  * must_be_active was set).
696  */
697  virtual widget* find(const std::string& id, const bool must_be_active);
698 
699  /** The constant version of @ref find. */
700  virtual const widget* find(const std::string& id,
701  const bool must_be_active) const;
702 
703  /**
704  * Does the widget contain the widget.
705  *
706  * Widgets can be containers which have more widgets inside them, this
707  * function will traverse in those child widgets and tries to find the
708  * wanted widget.
709  *
710  * @param widget Pointer to the widget to find.
711  *
712  * @returns Whether or not the @p widget was found.
713  */
714  virtual bool has_widget(const widget& widget) const;
715 
716 private:
717  /** See @ref event::dispatcher::is_at. */
718  virtual bool is_at(const point& coordinate) const override;
719 
720  /**
721  * Is the coordinate inside our area.
722  *
723  * Helper for find_at so also looks at our visibility.
724  *
725  * @param coordinate The coordinate which should be inside the
726  * widget.
727  * @param must_be_active The widget should be active, not all widgets
728  * have an active flag, those who don't ignore
729  * flag.
730  *
731  * @returns Status.
732  */
733  bool is_at(const point& coordinate, const bool must_be_active) const;
734 
735  /**
736  * Is the widget and every single one of its parents visible?
737  *
738  * @param widget Widget where to start the check.
739  * @param must_be_active The widget should be active, not all widgets
740  * have an active flag, those who don't ignore
741  * flag.
742  *
743  * @returns Status.
744  */
745  bool recursive_is_visible(const widget* widget, const bool must_be_active) const;
746 
747  /***** ***** ***** ***** Miscellaneous ***** ***** ****** *****/
748 
749 public:
750  /** Does the widget disable easy close? */
751  virtual bool disable_click_dismiss() const = 0;
752 
753  /** Creates a new walker object on the heap. */
755 };
756 
757 } // namespace gui2
Base class for event handling.
Definition: dispatcher.hpp:150
Event execution calls.
Base container class.
Definition: grid.hpp:32
Base class for all widgets.
Definition: widget.hpp:53
virtual iteration::walker_ptr create_walker()=0
Creates a new walker object on the heap.
const point & layout_size() const
Definition: widget.cpp:342
virtual void demand_reduce_width(const unsigned maximum_width)
Tries to reduce the width of a widget.
Definition: widget.cpp:178
void set_layout_size(const point &size)
Definition: widget.cpp:337
grid * get_parent_grid()
Get the parent grid.
Definition: widget.cpp:145
redraw_action redraw_action_
Field for the action to do on a drawing request.
Definition: widget.hpp:641
bool draw_foreground()
Draws the foreground of the widget.
Definition: widget.cpp:415
point get_best_size() const
Gets the best size for the widget.
Definition: widget.cpp:193
void clear_layout_size()
Throws away layout_size_.
Definition: widget.hpp:456
virtual void place(const point &origin, const point &size)
Places the widget.
Definition: widget.cpp:239
debug_border debug_border_mode_
Mode for drawing the debug border.
Definition: widget.hpp:652
void set_visible(const visibility visible)
Definition: widget.cpp:470
virtual bool disable_click_dismiss() const =0
Does the widget disable easy close?
void set_id(const std::string &id)
Definition: widget.cpp:98
int x_
The x-coordinate of the widget on the screen.
Definition: widget.hpp:465
virtual void demand_reduce_height(const unsigned maximum_height)
Tries to reduce the height of a widget.
Definition: widget.cpp:188
virtual void layout_children()
Allows a widget to update its children.
Definition: widget.cpp:297
visibility visible_
Field for the status of the visibility.
Definition: widget.hpp:638
virtual ~widget() override
Definition: widget.cpp:77
rect clipping_rectangle_
The clipping rectangle if a widget is partly visible.
Definition: widget.hpp:644
virtual void layout_initialize(const bool full_initialization)
How the layout engine works.
Definition: widget.cpp:167
SDL_Rect get_dirty_rectangle() const
Gets the dirty rectangle of the widget.
Definition: widget.cpp:436
void set_linked_group(const std::string &linked_group)
Definition: widget.cpp:347
void queue_redraw()
Indicates that this widget should be redrawn.
Definition: widget.cpp:455
widget * parent_
The parent widget.
Definition: widget.hpp:214
visibility get_visible() const
Definition: widget.cpp:497
point get_origin() const
Returns the screen origin of the widget.
Definition: widget.cpp:302
color_t debug_border_color_
The color for the debug border.
Definition: widget.hpp:655
int get_x() const
Definition: widget.cpp:317
virtual bool impl_draw_foreground()
See draw_foreground.
Definition: widget.hpp:581
virtual widget * find(const std::string &id, const bool must_be_active)
Returns a widget with the wanted id.
Definition: widget.cpp:555
virtual bool can_mouse_focus() const
Whether the mouse move/click event go 'through' this widget.
Definition: widget.hpp:331
unsigned width_
The width of the widget.
Definition: widget.hpp:471
unsigned get_width() const
Definition: widget.cpp:327
int get_y() const
Definition: widget.cpp:322
void set_parent(widget *parent)
Definition: widget.cpp:155
virtual point calculate_best_size() const =0
Calculates the best size.
point get_size() const
Returns the size of the widget.
Definition: widget.cpp:307
void draw_children()
Draws the children of a widget.
Definition: widget.cpp:394
virtual void move(const int x_offset, const int y_offset)
Moves a widget.
Definition: widget.cpp:265
bool draw_background()
Draws the background of a widget.
Definition: widget.cpp:372
virtual bool has_widget(const widget &widget) const
Does the widget contain the widget.
Definition: widget.cpp:566
friend class debug_layout_graph
Definition: widget.hpp:54
virtual void set_origin(const point &origin)
Sets the origin of the widget.
Definition: widget.cpp:221
unsigned get_height() const
Definition: widget.cpp:332
const std::string & id() const
Definition: widget.cpp:110
window * get_window()
Get the parent window.
Definition: widget.cpp:117
bool recursive_is_visible(const widget *widget, const bool must_be_active) const
Is the widget and every single one of its parents visible?
Definition: widget.cpp:576
virtual bool impl_draw_background()
See draw_background.
Definition: widget.hpp:570
int y_
The y-coordinate of the widget on the screen.
Definition: widget.hpp:468
virtual void set_horizontal_alignment(const std::string &alignment)
Sets the horizontal alignment of the widget within its parent grid.
Definition: widget.cpp:271
std::string id_
The id is the unique name of the widget in a certain context.
Definition: widget.hpp:175
visibility
Visibility settings done by the user.
Definition: widget.hpp:63
@ visible
The user sets the widget visible, that means:
@ invisible
The user set the widget invisible, that means:
@ hidden
The user sets the widget hidden, that means:
virtual void request_reduce_width(const unsigned maximum_width)=0
Tries to reduce the width of a widget.
SDL_Rect calculate_blitting_rectangle() const
Calculates the blitting rectangle of the widget.
Definition: widget.cpp:354
SDL_Rect calculate_clipping_rectangle() const
Calculates the clipping rectangle of the widget.
Definition: widget.cpp:359
std::string linked_group_
The linked group the widget belongs to.
Definition: widget.hpp:510
widget(const widget &)=delete
void set_debug_border_mode(const debug_border debug_border_mode)
Definition: widget.cpp:508
redraw_action get_drawing_action() const
Definition: widget.cpp:502
rect get_rectangle() const
Gets the bounding rectangle of the widget on the screen.
Definition: widget.cpp:312
virtual void impl_draw_children()
See draw_children.
Definition: widget.hpp:576
void draw_debug_border()
Definition: widget.cpp:518
point layout_size_
The best size for the widget.
Definition: widget.hpp:486
widget & operator=(const widget &)=delete
@ outline
Single-pixel outline.
@ fill
Flood-filled rectangle.
virtual widget * find_at(const point &coordinate, const bool must_be_active)
Returns the widget at the wanted coordinates.
Definition: widget.cpp:544
void set_debug_border_color(const color_t debug_border_color)
Definition: widget.cpp:513
unsigned height_
The height of the widget.
Definition: widget.hpp:474
virtual void set_size(const point &size)
Sets the size of the widget.
Definition: widget.cpp:227
virtual void request_reduce_height(const unsigned maximum_height)
Tries to reduce the height of a widget.
Definition: widget.cpp:183
virtual bool can_wrap() const
Can the widget wrap.
Definition: widget.cpp:216
virtual bool is_at(const point &coordinate) const override
See event::dispatcher::is_at.
Definition: widget.cpp:571
redraw_action
Visibility set by the engine.
Definition: widget.hpp:101
@ none
The widget is not visible.
@ partly
The widget is partly visible.
@ full
The widget is fully visible.
virtual void set_visible_rectangle(const SDL_Rect &rectangle)
Sets the visible rectangle for a widget.
Definition: widget.cpp:442
widget * parent()
Definition: widget.cpp:160
virtual void set_vertical_alignment(const std::string &alignment)
Sets the horizontal alignment of the widget within its parent grid.
Definition: widget.cpp:284
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:202
std::unique_ptr< class walker_base > walker_ptr
Definition: widget.hpp:42
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:34
std::map< std::string, t_string > widget_item
Definition: widget.hpp:31
map_location coordinate
Contains an x and y coordinate used for starting positions in maps.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
Contains the SDL_Rect helper code.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
Contains the info needed to instantiate a widget.
Holds a 2D point.
Definition: point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition: rect.hpp:47