The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
stacked_widget.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 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
19
22
23#include <boost/dynamic_bitset.hpp>
24
25namespace gui2
26{
27
28// ------------ WIDGET -----------{
29
30namespace implementation
31{
32struct builder_stacked_widget;
33}
34
35class generator_base;
36
38{
41 friend class debug_layout_graph;
42
43public:
45
46 /***** ***** ***** inherited ***** ****** *****/
47
48 /** See @ref styled_widget::get_active. */
49 virtual bool get_active() const override;
50
51 /** See @ref styled_widget::get_state. */
52 virtual unsigned get_state() const override;
53
54 /** See @ref widget::layout_children. */
55 virtual void layout_children() override;
56
57 /**
58 * Gets the current visible layer number.
59 *
60 * The current layer number will be -1 if all layers are currently visible.
61 * In this case, only the topmost (highest-numbered) layer will receive
62 * events.
63 *
64 * If more than one but not all layers are visible, this will be the number of
65 * the last one made visible.
66 *
67 * @returns The most recently shown layer
68 */
69 int current_layer() const { return selected_layer_; }
70
71 /**
72 * Tests if the specified layer is selected (ie, visible).
73 *
74 * @param layer The layer to test
75 * @returns True if the specified layer is selected
76 */
77 bool layer_selected(const unsigned layer);
78
79 /**
80 * Selects and displays a particular layer.
81 *
82 * If layer -1 is selected, all layers will be displayed but only the
83 * topmost (highest-numbered) layer will receive events.
84 *
85 * @param layer The layer to select
86 */
87 void select_layer(const int layer);
88
89 /**
90 * Selects and displays multiple layers based on the state of the provided dynamic_bitset.
91 *
92 * @param mask A mask specifying which layers to select and deselect
93 */
94 void select_layers(const boost::dynamic_bitset<>& mask);
95
96 /**
97 * Gets the total number of layers.
98 *
99 * @returns The total number of layers
100 */
101 unsigned int get_layer_count() const;
102
103 /**
104 * Gets the grid for a specified layer.
105 * This can be used to search for widgets in a hidden layer.
106 *
107 * @param i The layer to retrieve
108 * @returns The grid for the specified layer.
109 */
110 grid* get_layer_grid(unsigned int i);
111
112 /** Const overload for @ref get_layer_grid. */
113 const grid* get_layer_grid(unsigned int i) const;
114
115 void set_find_in_all_layers(const bool do_find)
116 {
117 find_in_all_layers_ = do_find;
118 }
119
120private:
121 /**
122 * Contains a pointer to the generator.
123 *
124 * The pointer is not owned by this class, it's stored in the content_grid_
125 * of the scrollbar_container super class and freed when its grid is freed.
126 *
127 * NOTE: the generator is initialized with has_minimum (first arg) as false,
128 * which seems a little counter-intuitive at first. After all, shouldn't the
129 * stack always have at least one layer visible? However, this allows select_layer
130 * to function correctly.
131 *
132 * If has_minimum is true, the generator policy selected (one_item) can leave
133 * multiple layers selected when selecting a new one. This is most likely due to
134 * cases where the new chosen layer comes *after* the currently selected one.
135 * In that case, the generator would not allow the interim state where no layer
136 * before the new chosen layer is reached in the loop.
137 */
139
140 /**
141 * The number of the current selected layer.
142 */
144
145 /**
146 * If true, @ref find will search all layers for widgets regardless of which
147 * one is visible.
148 */
150
151 void update_selected_layer_index(const int i);
152
153 /** Internal implementation detail for selecting layers. */
154 void select_layer_impl(const std::function<bool(unsigned int i)>& display_condition);
155
156public:
157 /** Static type getter that does not rely on the widget being constructed. */
158 static const std::string& type();
159
160private:
161 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
162 virtual const std::string& get_control_type() const override;
163
164 /** See @ref container_base::set_self_active. */
165 virtual void set_self_active(const bool active) override;
166
167public:
168 /** See @ref widget::find. */
169 virtual widget* find(const std::string_view id, const bool must_be_active) override;
170
171 /** See @ref widget::find. */
172 virtual const widget* find(const std::string_view id, const bool must_be_active) const override;
173};
174
175// }---------- DEFINITION ---------{
176
178{
179 explicit stacked_widget_definition(const config& cfg);
180
182 {
183 explicit resolution(const config& cfg);
184
186 };
187};
188
189// }---------- BUILDER -----------{
190
191namespace implementation
192{
193
195{
196 explicit builder_stacked_widget(const config& cfg);
197
199
200 virtual std::unique_ptr<widget> build() const override;
201
202 /** The builders for all layers of the stack .*/
203 std::vector<builder_grid> stack;
204};
205
206} // namespace implementation
207
208// }------------ END --------------
209
210} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
A generic container base class.
Abstract base class for the generator.
Definition generator.hpp:39
Base container class.
Definition grid.hpp:32
virtual widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
generator_base * generator_
Contains a pointer to the generator.
int current_layer() const
Gets the current visible layer number.
virtual bool get_active() const override
See styled_widget::get_active.
void update_selected_layer_index(const int i)
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
void select_layer_impl(const std::function< bool(unsigned int i)> &display_condition)
Internal implementation detail for selecting layers.
grid * get_layer_grid(unsigned int i)
Gets the grid for a specified layer.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
friend class debug_layout_graph
bool layer_selected(const unsigned layer)
Tests if the specified layer is selected (ie, visible).
bool find_in_all_layers_
If true, find will search all layers for widgets regardless of which one is visible.
int selected_layer_
The number of the current selected layer.
unsigned int get_layer_count() const
Gets the total number of layers.
void set_find_in_all_layers(const bool do_find)
virtual unsigned get_state() const override
See styled_widget::get_state.
void select_layers(const boost::dynamic_bitset<> &mask)
Selects and displays multiple layers based on the state of the provided dynamic_bitset.
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
virtual void layout_children() override
See widget::layout_children.
void select_layer(const int layer)
Selects and displays a particular layer.
Base class for all widgets.
Definition widget.hpp:55
const config * cfg
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::vector< builder_grid > stack
The builders for all layers of the stack .
virtual std::unique_ptr< widget > build() const override
virtual std::unique_ptr< widget > build() const=0
#define i