The Battle for Wesnoth  1.19.0-dev
panel.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 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 
19 
22 
23 namespace gui2
24 {
25 
26 // ------------ WIDGET -----------{
27 
28 /**
29  * @ingroup GUIWidgetWML
30  *
31  * A panel is a visible container to hold multiple widgets.
32  * The difference between a grid and a panel is that it's possible to define how a panel looks.
33  * A grid in an invisible container to just hold the items.
34  * A panel is always enabled and can't be disabled.
35  * Instead it uses the states as layers to draw on and can draw items beyond the widgets it holds and in front of them.
36  * A panel is always active so some functions return dummy values.
37  *
38  * The widget instance has the following:
39  * Key |Type |Default |Description
40  * -------------|----------------------------|---------|-----------
41  * grid | @ref guivartype_grid "grid"|mandatory|Defines the grid with the widgets to place on the panel.
42  *
43  * The resolution for a panel also contains the following keys:
44  * Key |Type |Default|Description
45  * -------------|------------------------------------|-------|-------------
46  * top_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
47  * bottom_border| @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
48  * left_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
49  * right_border | @ref guivartype_unsigned "unsigned"|0 |The size which isn't used for the client area.
50  * The following layers exist:
51  * * background - the background of the panel.
52  * * foreground - the foreground of the panel.
53  */
54 class panel : public container_base
55 {
56 public:
57  /**
58  * Constructor.
59  */
60  panel(const implementation::builder_styled_widget& builder, const std::string& control_type = "");
61 
62  /** See @ref container_base::get_client_rect. */
63  virtual SDL_Rect get_client_rect() const override;
64 
65  /** See @ref styled_widget::get_active. */
66  virtual bool get_active() const override;
67 
68  /** See @ref styled_widget::get_state. */
69  virtual unsigned get_state() const override;
70 
71 private:
72  /** See @ref widget::impl_draw_background. */
73  virtual bool impl_draw_background() override;
74 
75  /** See @ref widget::impl_draw_foreground. */
76  virtual bool impl_draw_foreground() override;
77 
78 public:
79  /** Static type getter that does not rely on the widget being constructed. */
80  static const std::string& type();
81 
82 private:
83  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
84  virtual const std::string& get_control_type() const override;
85 
86  /** See @ref container_base::border_space. */
87  virtual point border_space() const override;
88 
89  /** See @ref container_base::set_self_active. */
90  virtual void set_self_active(const bool active) override;
91 };
92 
93 // }---------- DEFINITION ---------{
94 
96 {
97  explicit panel_definition(const config& cfg);
98 
100  {
101  explicit resolution(const config& cfg);
102 
103  unsigned top_border;
104  unsigned bottom_border;
105 
106  unsigned left_border;
107  unsigned right_border;
108  };
109 };
110 
111 // }---------- BUILDER -----------{
112 
113 namespace implementation
114 {
115 
117 {
118  explicit builder_panel(const config& cfg);
119 
121 
122  virtual std::unique_ptr<widget> build() const override;
123 
125 };
126 
127 } // namespace implementation
128 
129 // }------------ END --------------
130 
131 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A generic container base class.
A panel is a visible container to hold multiple widgets.
Definition: panel.hpp:55
virtual bool impl_draw_foreground() override
See widget::impl_draw_foreground.
Definition: panel.cpp:76
virtual bool impl_draw_background() override
See widget::impl_draw_background.
Definition: panel.cpp:66
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
virtual bool get_active() const override
See styled_widget::get_active.
Definition: panel.cpp:56
panel(const implementation::builder_styled_widget &builder, const std::string &control_type="")
Constructor.
Definition: panel.cpp:37
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: panel.cpp:61
virtual SDL_Rect get_client_rect() const override
See container_base::get_client_rect.
Definition: panel.cpp:42
virtual point border_space() const override
See container_base::border_space.
Definition: panel.cpp:86
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
Definition: panel.cpp:94
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn't be used directly.
builder_panel(const config &cfg)
Definition: panel.cpp:126
virtual std::unique_ptr< widget > build() const override
Definition: panel.cpp:136
virtual std::unique_ptr< widget > build() const=0
resolution(const config &cfg)
Definition: panel.cpp:109
panel_definition(const config &cfg)
Definition: panel.cpp:101
Base class of a resolution, contains the common keys for a resolution.
Holds a 2D point.
Definition: point.hpp:25