/
multi_page.hpp
255 lines (209 loc) · 7.53 KB
/
multi_page.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
Copyright (C) 2008 - 2017 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "gui/widgets/container_base.hpp"
#include "gui/core/widget_definition.hpp"
#include "gui/core/window_builder.hpp"
namespace gui2
{
// ------------ WIDGET -----------{
namespace implementation
{
struct builder_multi_page;
}
class generator_base;
/** The multi page class. */
class multi_page : public container_base
{
friend struct implementation::builder_multi_page;
friend class debug_layout_graph;
public:
multi_page();
/***** ***** ***** ***** Page handling. ***** ***** ****** *****/
/**
* Adds single page to the grid.
*
* This function expect a page to one multiple widget.
*
* @param item The data to send to the set_members of the
* widget.
*
* @returns The grid of the newly added page.
*/
grid& add_page(const string_map& item);
/**
* Adds single page to the grid.
*
* This function expect a page to one multiple widget.
*
* @param item The data to send to the set_members of the
* widget.
*
* @param type the id of the [page_definition] that shoduol be used
*
* @param insert_pos the position where th new page is inserted, usually
* -1 for 'at end'
*
* @returns The grid of the newly added page.
*/
grid& add_page(const std::string& type, int insert_pos, const string_map& item);
/**
* Adds single page to the grid.
*
* This function expect a page to have multiple widgets (either multiple
* columns or one column with multiple widgets).
*
*
* @param data The data to send to the set_members of the
* widgets. If the member id is not an empty
* string it is only send to the widget that
* has the wanted id (if any). If the member
* id is an empty string, it is send to all
* members. Having both empty and non-empty
* id's gives undefined behavior.
*
* @returns The grid of the newly added page.
*/
grid& add_page(const std::map<std::string /* widget id */, string_map>& data);
/**
* Adds single page to the grid.
*
* This function expect a page to have multiple widgets (either multiple
* columns or one column with multiple widgets).
*
*
* @param data The data to send to the set_members of the
* widgets. If the member id is not an empty
* string it is only send to the widget that
* has the wanted id (if any). If the member
* id is an empty string, it is send to all
* members. Having both empty and non-empty
* id's gives undefined behavior.
*
* @param type the id of the [page_definition] that shoduol be used
*
* @param insert_pos the position where th new page is inserted, usually
* -1 for 'at end'
*
* @returns The grid of the newly added page.
*/
grid& add_page(const std::string& type, int insert_pos, const std::map<std::string /* widget id */, string_map>& data);
/**
* Removes a page in the multi page.
*
* @param page The page to remove, when not in
* range the function is ignored.
* @param count The number of pages to remove, 0 means all
* pages (starting from page).
*/
void remove_page(const unsigned page, unsigned count = 1);
/** Removes all pages in the multi page, clearing it. */
void clear();
/** Returns the number of pages. */
unsigned get_page_count() const;
/**
* Selectes a page.
*
* @param page The page to select.
* @param select Select or deselect the page.
*/
void select_page(const unsigned page, const bool select = true);
/**
* Returns the selected page.
*
* @returns The selected page.
* @retval -1 No page selected.
*/
int get_selected_page() const;
/**
* Returns the grid for the page.
*
* @param page The page to get the grid from, the caller
* has to make sure the page is a valid page.
*
* @returns The grid of the wanted page.
*/
const grid& page_grid(const unsigned page) const;
/**
* Returns the grid for the page.
*
* @param page The page to get the grid from, the caller
* has to make sure the page is a valid page.
*
* @returns The grid of the wanted page.
*/
grid& page_grid(const unsigned page);
/***** ***** ***** inherited ***** ****** *****/
/** See @ref styled_widget::get_active. */
virtual bool get_active() const override;
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_page_builders(const std::map<std::string, builder_grid_const_ptr>& page_builders)
{
assert(!page_builders.empty());
page_builders_ = page_builders;
}
private:
/**
* Finishes the building initialization of the widget.
*
* @param page_data The initial data to fill the widget with.
*/
void finalize(const std::vector<string_map>& page_data);
/**
* Contains a pointer to the generator.
*
* The pointer is not owned by this class, it's stored in the content_grid_
* of the scrollbar_container super class and freed when it's grid is
* freed.
*/
generator_base* generator_;
/** Contains the builder for the new items. */
std::map<std::string, builder_grid_const_ptr> page_builders_;
/** See @ref widget::impl_draw_background. */
virtual void impl_draw_background(int x_offset, int y_offset) override;
/** See @ref styled_widget::get_control_type. */
virtual const std::string& get_control_type() const override;
/** See @ref container_base::set_self_active. */
virtual void set_self_active(const bool active) override;
};
// }---------- DEFINITION ---------{
struct multi_page_definition : public styled_widget_definition
{
explicit multi_page_definition(const config& cfg);
struct resolution : public resolution_definition
{
explicit resolution(const config& cfg);
builder_grid_ptr grid;
};
};
// }---------- BUILDER -----------{
namespace implementation
{
struct builder_multi_page : public builder_styled_widget
{
explicit builder_multi_page(const config& cfg);
using builder_styled_widget::build;
widget* build() const;
std::map<std::string, builder_grid_const_ptr> builders;
/**
* Multi page data.
*
* Contains a vector with the data to set in every cell, it's used to
* serialize the data in the config, so the config is no longer required.
*/
std::vector<std::map<std::string, t_string> > data;
};
} // namespace implementation
// }------------ END --------------
} // namespace gui2