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