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