The Battle for Wesnoth  1.19.7+dev
multi_page.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 namespace implementation
29 {
30 struct builder_multi_page;
31 }
32 
33 class generator_base;
34 
35 class multi_page : public container_base
36 {
38  friend class debug_layout_graph;
39 
40 public:
41  explicit multi_page(const implementation::builder_multi_page& builder);
42 
43  /***** ***** ***** ***** Page handling. ***** ***** ****** *****/
44 
45  /**
46  * Adds single page to the grid.
47  *
48  * This function expect a page to one multiple widget.
49  *
50  * @param item The data to send to the set_members of the
51  * widget.
52  *
53  * @returns The grid of the newly added page.
54  */
55  grid& add_page(const widget_item& item);
56 
57  /**
58  * Adds single page to the grid.
59  *
60  * This function expect a page to one multiple widget.
61  *
62  * @param item The data to send to the set_members of the
63  * widget.
64  *
65  * @param type the id of the [page_definition] that shoduol be used
66  *
67  * @param insert_pos the position where th new page is inserted, usually
68  * -1 for 'at end'
69  *
70  * @returns The grid of the newly added page.
71  */
72  grid& add_page(const std::string& type, int insert_pos, const widget_item& item);
73 
74  /**
75  * Adds single page to the grid.
76  *
77  * This function expect a page to have multiple widgets (either multiple
78  * columns or one column with multiple widgets).
79  *
80  *
81  * @param data The data to send to the set_members of the
82  * widgets. If the member id is not an empty
83  * string it is only send to the widget that
84  * has the wanted id (if any). If the member
85  * id is an empty string, it is send to all
86  * members. Having both empty and non-empty
87  * id's gives undefined behavior.
88  *
89  * @returns The grid of the newly added page.
90  */
91  grid& add_page(const widget_data& data);
92 
93  /**
94  * Adds single page to the grid.
95  *
96  * This function expect a page to have multiple widgets (either multiple
97  * columns or one column with multiple widgets).
98  *
99  *
100  * @param data The data to send to the set_members of the
101  * widgets. If the member id is not an empty
102  * string it is only send to the widget that
103  * has the wanted id (if any). If the member
104  * id is an empty string, it is send to all
105  * members. Having both empty and non-empty
106  * id's gives undefined behavior.
107  *
108  * @param type the id of the [page_definition] that should be used
109  *
110  * @param insert_pos the position where th new page is inserted, usually
111  * -1 for 'at end'
112  *
113  * @returns The grid of the newly added page.
114  */
115  grid& add_page(const std::string& type, int insert_pos, const widget_data& data);
116 
117  /**
118  * Removes a page in the multi page.
119  *
120  * @param page The page to remove, when not in
121  * range the function is ignored.
122  * @param count The number of pages to remove, 0 means all
123  * pages (starting from page).
124  */
125  void remove_page(const unsigned page, unsigned count = 1);
126 
127  /** Removes all pages in the multi page, clearing it. */
128  void clear();
129 
130  /** Returns the number of pages. */
131  unsigned get_page_count() const;
132 
133  /**
134  * Selects a page.
135  *
136  * @param page The page to select.
137  * @param select Select or deselect the page.
138  */
139  void select_page(const unsigned page, const bool select = true);
140 
141  /**
142  * Returns the selected page.
143  *
144  * @returns The selected page.
145  * @retval -1 No page selected.
146  */
147  int get_selected_page() const;
148 
149  /**
150  * Returns the grid for the page.
151  *
152  * @param page The page to get the grid from, the caller
153  * has to make sure the page is a valid page.
154  *
155  * @returns The grid of the wanted page.
156  */
157  const grid& page_grid(const unsigned page) const;
158 
159  /**
160  * Returns the grid for the page.
161  *
162  * @param page The page to get the grid from, the caller
163  * has to make sure the page is a valid page.
164  *
165  * @returns The grid of the wanted page.
166  */
167  grid& page_grid(const unsigned page);
168 
169  /***** ***** ***** inherited ***** ****** *****/
170 
171  /** See @ref styled_widget::get_active. */
172  virtual bool get_active() const override;
173 
174  /** See @ref styled_widget::get_state. */
175  virtual unsigned get_state() const override;
176 
177 private:
178  /***** ***** ***** setters / getters for members ***** ****** *****/
179 
180  /**
181  * Contains a pointer to the generator.
182  *
183  * The pointer is not owned by this class, it's stored in the content_grid_
184  * of the scrollbar_container super class and freed when it's grid is freed.
185  */
187 
188  /** Contains the builder for the new items. */
190 
191  /** See @ref widget::impl_draw_background. */
192  virtual bool impl_draw_background() override;
193 
194 public:
195  /** Static type getter that does not rely on the widget being constructed. */
196  static const std::string& type();
197 
198 private:
199  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
200  virtual const std::string& get_control_type() const override;
201 
202  /** See @ref container_base::set_self_active. */
203  virtual void set_self_active(const bool active) override;
204 };
205 
206 // }---------- DEFINITION ---------{
207 
209 {
210  explicit multi_page_definition(const config& cfg);
211 
213  {
214  explicit resolution(const config& cfg);
215 
217  };
218 };
219 
220 // }---------- BUILDER -----------{
221 
222 namespace implementation
223 {
224 
226 {
227  explicit builder_multi_page(const config& cfg);
228 
230 
231  virtual std::unique_ptr<widget> build() const override;
232 
234 
235  /**
236  * Multi page data.
237  *
238  * Contains a vector with the data to set in every cell, it's used to
239  * serialize the data in the config, so the config is no longer required.
240  */
241  std::vector<widget_item> data;
242 };
243 
244 } // namespace implementation
245 
246 // }------------ END --------------
247 
248 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A generic container base class.
Abstract base class for the generator.
Definition: generator.hpp:39
Base container class.
Definition: grid.hpp:32
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
Definition: multi_page.cpp:134
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: multi_page.cpp:151
generator_base * generator_
Contains a pointer to the generator.
Definition: multi_page.hpp:186
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:90
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:58
builder_grid_map page_builders_
Contains the builder for the new items.
Definition: multi_page.hpp:189
friend class debug_layout_graph
Definition: multi_page.hpp:38
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: multi_page.cpp:146
unsigned get_page_count() const
Returns the number of pages.
Definition: multi_page.cpp:113
int get_selected_page() const
Returns the selected page.
Definition: multi_page.cpp:128
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
multi_page(const implementation::builder_multi_page &builder)
Definition: multi_page.cpp:36
virtual bool impl_draw_background() override
See widget::impl_draw_background.
Definition: multi_page.cpp:156
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
Definition: multi_page.cpp:162
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:119
void clear()
Removes all pages in the multi page, clearing it.
Definition: multi_page.cpp:107
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33
std::map< std::string, builder_grid_const_ptr > builder_grid_map
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string_view data
Definition: picture.cpp:178
virtual std::unique_ptr< widget > build() const override
Definition: multi_page.cpp:229
std::vector< widget_item > data
Multi page data.
Definition: multi_page.hpp:241
virtual std::unique_ptr< widget > build() const=0
multi_page_definition(const config &cfg)
Definition: multi_page.cpp:169