The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
toggle_panel.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 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 "gui/widgets/panel.hpp"
20
21namespace gui2
22{
23
24namespace implementation
25{
26struct builder_toggle_panel;
27}
28
29// ------------ WIDGET -----------{
30
31class toggle_panel : public panel, public selectable_item
32{
33public:
35
36 /**
37 * Sets the members of the child controls.
38 *
39 * Sets the members for all controls which have the proper member id. See
40 * styled_widget::set_members for more info.
41 *
42 * @param data Map with the key value pairs to set the
43 * members.
44 */
46
47 /***** ***** ***** ***** Inherited ***** ***** ***** *****/
48
49 /** See @ref widget::find_at. */
50 virtual widget* find_at(const point& coordinate,
51 const bool must_be_active) override;
52
53 /** See @ref widget::find_at. */
54 virtual const widget* find_at(const point& coordinate,
55 const bool must_be_active) const override;
56
57 /** See @ref styled_widget::set_active. */
58 virtual void set_active(const bool active) override;
59
60 /** See @ref styled_widget::get_active. */
61 virtual bool get_active() const override;
62
63 /** See @ref styled_widget::get_state. */
64 virtual unsigned get_state() const override;
65
66 /**
67 * See @ref container_base::get_client_rect.
68 *
69 * @todo only due to the fact our definition is slightly different from
70 * panel_definition we need to override this function and do about the
71 * same, look at a way to 'fix' that.
72 */
73 virtual rect get_client_rect() const override;
74
75 /**
76 * See @ref container_base::border_space.
77 *
78 * @todo only due to the fact our definition is slightly different from
79 * panel_definition we need to override this function and do about the
80 * same, look at a way to 'fix' that.
81 */
82 virtual point border_space() const override;
83
84 /** Inherited from selectable_item */
85 virtual unsigned get_value() const override
86 {
87 return state_num_;
88 }
89
90 /** Inherited from selectable_item */
91 virtual void set_value(unsigned selected, bool fire_event = false) override;
92
93 /** Inherited from selectable_item */
94 virtual unsigned num_states() const override;
95
96 /***** ***** ***** setters / getters for members ***** ****** *****/
97
98 void set_retval(const int retval);
99
100private:
101 /**
102 * Possible states of the widget.
103 *
104 * Note the order of the states must be the same as defined in settings.hpp.
105 * Also note the internals do assume the order for 'up' and 'down' to be the
106 * same and also that 'up' is before 'down'. 'up' has no suffix, 'down' has
107 * the SELECTED suffix.
108 */
115
116 void set_state(const state_t state);
117
118 /**
119 * Current state of the widget.
120 *
121 * The state of the widget determines what to render and how the widget
122 * reacts to certain 'events'.
123 */
125
126 /**
127 * Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons.
128 */
129 unsigned state_num_;
130
131 /**
132 * The return value of the button.
133 *
134 * If this value is not 0 and the button is double clicked it sets the
135 * retval of the window and the window closes itself.
136 */
138
139 /** Mouse left double click callback */
141
142 /** See @ref widget::impl_draw_background. */
143 virtual bool impl_draw_background() override;
144
145 /** See @ref widget::impl_draw_foreground. */
146 virtual bool impl_draw_foreground() override;
147
148public:
149 /** Static type getter that does not rely on the widget being constructed. */
150 static const std::string& type();
151
152private:
153 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
154 virtual const std::string& get_control_type() const override;
155
156 /***** ***** ***** signal handlers ***** ****** *****/
157
158 void signal_handler_mouse_enter(const event::ui_event event, bool& handled);
159
160 void signal_handler_mouse_leave(const event::ui_event event, bool& handled);
161
163
165 bool& handled);
166
168 bool& handled);
169};
170
171// }---------- DEFINITION ---------{
172
174{
175 explicit toggle_panel_definition(const config& cfg);
176
178 {
179 explicit resolution(const config& cfg);
180
181 unsigned top_border;
183
184 unsigned left_border;
185 unsigned right_border;
186 };
187};
188
189// }---------- BUILDER -----------{
190
191namespace implementation
192{
193
195{
196 explicit builder_toggle_panel(const config& cfg);
197
199
200 virtual std::unique_ptr<widget> build() const override;
201
203
204private:
205 std::string retval_id_;
207};
208
209} // namespace implementation
210
211// }------------ END --------------
212
213} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
Small abstract helper class.
void signal_handler_left_button_double_click(const event::ui_event event, bool &handled)
unsigned state_num_
Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons.
virtual bool impl_draw_foreground() override
See widget::impl_draw_foreground.
virtual bool impl_draw_background() override
See widget::impl_draw_background.
void signal_handler_mouse_enter(const event::ui_event event, bool &handled)
void set_state(const state_t state)
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
void set_child_members(const widget_data &data)
Sets the members of the child controls.
virtual unsigned get_state() const override
See styled_widget::get_state.
virtual void set_active(const bool active) override
See styled_widget::set_active.
int retval_
The return value of the button.
void set_retval(const int retval)
virtual unsigned get_value() const override
Inherited from selectable_item.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void signal_handler_left_button_click(const event::ui_event event, bool &handled)
virtual point border_space() const override
See container_base::border_space.
virtual rect get_client_rect() const override
See container_base::get_client_rect.
virtual bool get_active() const override
See styled_widget::get_active.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
virtual void set_value(unsigned selected, bool fire_event=false) override
Inherited from selectable_item.
void signal_handler_mouse_leave(const event::ui_event event, bool &handled)
state_t state_
Current state of the widget.
virtual unsigned num_states() const override
Inherited from selectable_item.
void signal_handler_pre_left_button_click(const event::ui_event event)
state_t
Possible states of the widget.
std::function< void(widget &)> callback_mouse_left_double_click_
Mouse left double click callback.
Base class for all widgets.
Definition widget.hpp:55
const config * cfg
ui_event
The event sent to the dispatcher.
Definition handler.hpp:115
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::map< std::string, widget_item > widget_data
Definition widget.hpp:36
retval
Default window/dialog return values.
Definition retval.hpp:30
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string_view data
Definition picture.cpp:188
virtual std::unique_ptr< widget > build() const=0
virtual std::unique_ptr< widget > build() const override
Holds a 2D point.
Definition point.hpp:25
An abstract description of a rectangle with integer coordinates.
Definition rect.hpp:49