The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
matrix.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2012 - 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#pragma once
16
18#include "gui/widgets/pane.hpp"
20
23
24namespace gui2
25{
26
27// ------------ WIDGET -----------{
28
29namespace implementation
30{
31struct builder_matrix;
32}
33
35{
36public:
38
39 void set_active(const bool active);
40
41 bool get_active() const;
42
43 unsigned get_state() const;
44
45protected:
46 /**
47 * Possible states of the widget.
48 *
49 * Note the order of the states must be the same as defined in settings.hpp.
50 */
55
56private:
57 /**
58 * Current state of the widget.
59 *
60 * The state of the widget determines what to render and how the widget
61 * reacts to certain 'events'.
62 */
64};
65
66template <class STATE>
67class control_NEW : public styled_widget, public STATE
68{
69public:
71 const std::string& control_type)
72 : styled_widget(builder, control_type)
73
74 {
75 }
76
77 /** See @ref styled_widget::set_active. */
78 virtual void set_active(const bool active) override
79 {
80 STATE::set_active(active);
81 }
82
83 /** See @ref styled_widget::get_active. */
84 virtual bool get_active() const override
85 {
86 return STATE::get_active();
87 }
88
89 /** See @ref styled_widget::get_state. */
90 virtual unsigned get_state() const override
91 {
92 return STATE::get_state();
93 }
94};
95
97
98class matrix : public tbase
99{
100 friend class debug_layout_graph;
101
102public:
103 explicit matrix(const implementation::builder_matrix& builder);
104
105 /***** ***** ***** ***** Item handling. ***** ***** ****** *****/
106
107 unsigned create_item(const widget_data& item_data,
108 const std::map<std::string, std::string>& tags);
109
110
111 /***** ***** ***** ***** Inherited operations. ***** ***** ****** *****/
112
113 /** See @ref widget::place. */
114 virtual void place(const point& origin, const point& size) override;
115
116 /** See @ref widget::layout_initialize. */
117 virtual void layout_initialize(const bool full_initialization) override;
118
119 /** See @ref widget::impl_draw_children. */
120 virtual void impl_draw_children() override;
121
122 /** See @ref widget::layout_children. */
123 virtual void layout_children() override;
124
125 /** See @ref widget::request_reduce_width. */
126 virtual void request_reduce_width(const unsigned maximum_width) override;
127
128 /** See @ref widget::find_at. */
129 virtual widget* find_at(const point& coordinate,
130 const bool must_be_active) override;
131
132 /** See @ref widget::find_at. */
133 virtual const widget* find_at(const point& coordinate,
134 const bool must_be_active) const override;
135
136 /** See @ref widget::find. */
137 widget* find(const std::string_view id, const bool must_be_active) override;
138
139 /** See @ref widget::find. */
140 const widget* find(const std::string_view id, const bool must_be_active) const override;
141
142 /***** ***** ***** ***** Forwarded to pane_. ***** ***** ****** *****/
143 /**
144 * Sorts the contents of the pane.
145 *
146 * @param compare_functor The functor to use to sort the items.
147 */
148 void sort(const pane::compare_functor_t& compare_functor)
149 {
150 /********************** OUTLINE *******************/
151 pane_->sort(compare_functor);
152 }
153
154 /**
155 * Filters the contents of the pane.
156 *
157 * if the @p filter_functor returns @c true the item shown, else it's
158 * hidden.
159 *
160 * @param filter_functor The functor to determine whether an item
161 * should be shown or hidden.
162 */
163 void filter(const pane::filter_functor_t& filter_functor)
164 {
165 /********************** OUTLINE *******************/
166 pane_->filter(filter_functor);
167 }
168
169private:
170 /** See @ref widget::calculate_best_size. */
171 virtual point calculate_best_size() const override;
172
173public:
174 /** See @ref widget::disable_click_dismiss. */
175 bool disable_click_dismiss() const override;
176
177 /** See @ref widget::create_walker. */
178 virtual iteration::walker_ptr create_walker() override;
179
180 /**
181 * Returns a grid in the pane.
182 *
183 * @param id The id of the item whose grid to return. The
184 * id is the value returned by
185 * @ref create_item().
186 *
187 * @returns The wanted grid.
188 * @retval nullptr The id isn't associated with an item.
189 */
190 grid* get_grid(const unsigned id);
191
192 /**
193 * Returns a grid in the pane.
194 *
195 * @param id The id of the item whose grid to return. The
196 * id is the value returned by
197 * @ref create_item().
198 *
199 * @returns The wanted grid.
200 * @retval nullptr The id isn't associated with an item.
201 */
202 const grid* get_grid(const unsigned id) const;
203
204private:
205 /** The grid containing our children. */
207
208 /**
209 * Contains the pane used for adding new items to the matrix.
210 *
211 * The pane is owned by a grid in the content layer.
212 */
214
215public:
216 /** Static type getter that does not rely on the widget being constructed. */
217 static const std::string& type();
218
219private:
220 /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
221 virtual const std::string& get_control_type() const override;
222};
223
224// }---------- DEFINITION ---------{
225
227{
228
229 explicit matrix_definition(const config& cfg);
230
232 {
233 explicit resolution(const config& cfg);
234
236 };
237};
238
239// }---------- BUILDER -----------{
240
241namespace implementation
242{
243
263
264} // namespace implementation
265
266// }------------ END --------------
267
268} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition matrix.hpp:78
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition matrix.hpp:90
virtual bool get_active() const override
See styled_widget::get_active.
Definition matrix.hpp:84
control_NEW(const implementation::builder_styled_widget &builder, const std::string &control_type)
Definition matrix.hpp:70
Base container class.
Definition grid.hpp:32
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual void impl_draw_children() override
See widget::impl_draw_children.
Definition matrix.cpp:109
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition matrix.cpp:119
void sort(const pane::compare_functor_t &compare_functor)
Sorts the contents of the pane.
Definition matrix.hpp:148
virtual void layout_children() override
See widget::layout_children.
Definition matrix.cpp:114
const grid * get_grid(const unsigned id) const
Returns a grid in the pane.
grid * get_grid(const unsigned id)
Returns a grid in the pane.
virtual widget * find_at(const point &coordinate, const bool must_be_active) override
See widget::find_at.
Definition matrix.cpp:123
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition matrix.cpp:153
virtual void place(const point &origin, const point &size) override
See widget::place.
Definition matrix.cpp:97
pane * pane_
Contains the pane used for adding new items to the matrix.
Definition matrix.hpp:213
friend class debug_layout_graph
Definition matrix.hpp:100
void filter(const pane::filter_functor_t &filter_functor)
Filters the contents of the pane.
Definition matrix.hpp:163
virtual void layout_initialize(const bool full_initialization) override
See widget::layout_initialize.
Definition matrix.cpp:104
virtual iteration::walker_ptr create_walker() override
See widget::create_walker.
Definition matrix.cpp:168
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition matrix.cpp:160
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
Definition matrix.cpp:134
grid content_
The grid containing our children.
Definition matrix.hpp:206
unsigned create_item(const widget_data &item_data, const std::map< std::string, std::string > &tags)
Definition matrix.cpp:91
A pane is a container where new members can be added and removed during run-time.
Definition pane.hpp:41
std::function< bool(const item &, const item &)> compare_functor_t
Definition pane.hpp:53
std::function< bool(const item &)> filter_functor_t
Definition pane.hpp:55
void sort(const compare_functor_t &compare_functor)
Sorts the contents of the pane.
Definition pane.cpp:179
void filter(const filter_functor_t &filter_functor)
Filters the contents of the pane.
Definition pane.cpp:186
scrollbar_mode
The way to handle the showing or hiding of the scrollbar.
state_t
Possible states of the widget.
Definition matrix.hpp:51
unsigned get_state() const
Definition matrix.cpp:55
bool get_active() const
Definition matrix.cpp:50
void set_active(const bool active)
Definition matrix.cpp:43
state_t state_
Current state of the widget.
Definition matrix.hpp:63
Base class for all widgets.
Definition widget.hpp:55
const config * cfg
std::unique_ptr< class walker_base > walker_ptr
Definition widget.hpp:44
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::shared_ptr< builder_widget > builder_widget_ptr
std::map< std::string, widget_item > widget_data
Definition widget.hpp:36
control_NEW< state_default > tbase
Definition matrix.hpp:96
Contains the implementation details for lexical_cast and shouldn't be used directly.
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode
Definition matrix.hpp:253
scrollbar_container::scrollbar_mode vertical_scrollbar_mode
Definition matrix.hpp:252
virtual std::unique_ptr< widget > build() const override
Definition matrix.cpp:226
virtual std::unique_ptr< widget > build() const=0
Holds a 2D point.
Definition point.hpp:25