-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
pane.hpp
215 lines (160 loc) · 5.53 KB
/
pane.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
/*
Copyright (C) 2012 - 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/widget.hpp"
#include "gui/core/window_builder.hpp"
#include "gui/core/placer.hpp"
#include "utils/functional.hpp"
#include <list>
typedef std::map<std::string, t_string> string_map;
namespace gui2
{
// ------------ WIDGET -----------{
namespace implementation
{
struct builder_pane;
} // namespace implementation
class grid;
class pane : public widget
{
friend struct pane_implementation;
public:
struct item
{
unsigned id;
std::map<std::string, std::string> tags;
grid* item_grid;
};
typedef std::function<bool(const item&, const item&)> tcompare_functor;
typedef std::function<bool(const item&)> tfilter_functor;
/** @deprecated Use the second overload. */
explicit pane(const builder_grid_ptr item_builder);
private:
explicit pane(const implementation::builder_pane& builder);
public:
static pane* build(const implementation::builder_pane& builder);
/**
* Creates a new item.
*/
unsigned create_item(const std::map<std::string, string_map>& item_data,
const std::map<std::string, std::string>& tags);
/** See @ref widget::place. */
virtual void place(const point& origin, const point& size) override;
/** See @ref widget::layout_initialize. */
virtual void layout_initialize(const bool full_initialization) override;
/** See @ref widget::impl_draw_children. */
virtual void impl_draw_children(int x_offset, int y_offset) override;
/** See @ref widget::request_reduce_width. */
virtual void request_reduce_width(const unsigned maximum_width) override;
/** See @ref widget::find_at. */
virtual widget* find_at(const point& coordinate,
const bool must_be_active) override;
/** See @ref widget::find_at. */
virtual const widget* find_at(const point& coordinate,
const bool must_be_active) const override;
/**
* Sorts the contents of the pane.
*
* @param compare_functor The functor to use to sort the items.
*/
void sort(const tcompare_functor& compare_functor);
/**
* Filters the contents of the pane.
*
* if the @p filter_functor returns @c true the item shown, else it's
* hidden.
*
* @param filter_functor The functor to determine whether an item
* should be shown or hidden.
*/
void filter(const tfilter_functor& filter_functor);
private:
/** See @ref widget::calculate_best_size. */
virtual point calculate_best_size() const override;
public:
/** See @ref widget::disable_click_dismiss. */
bool disable_click_dismiss() const override;
/** See @ref widget::create_walker. */
virtual iteration::walker_base* create_walker() override;
/**
* Returns a grid in the pane.
*
* @param id The id of the item whose grid to return. The
* id is the value returned by
* @ref create_item().
*
* @returns The wanted grid.
* @retval nullptr The id isn't associated with an item.
*/
grid* get_grid(const unsigned id);
/**
* Returns a grid in the pane.
*
* @param id The id of the item whose grid to return. The
* id is the value returned by
* @ref create_item().
*
* @returns The wanted grid.
* @retval nullptr The id isn't associated with an item.
*/
const grid* get_grid(const unsigned id) const;
private:
/** The items in the pane. */
std::list<item> items_;
/** The builer for the items in the list. */
builder_grid_ptr item_builder_;
/** The id generator for the items. */
unsigned item_id_generator_;
/** Helper to do the placement. */
std::unique_ptr<placer_base> placer_;
/** Places the children on the pane. */
void place_children();
/**
* Moves the children on the pane.
*
* After certain operations, e.g. sorting the child widgets need to be
* placed again. This function does so, but avoids dirtying the widget so
* redrawing doesn't involve re-rendering the entire widget.
*/
void set_origin_children();
/**
* Places or moves the children on the pane.
*
* If the child has its best size it's move else placed.
*
* @note It would probably be possible to merge all three placement
* routines into one and using a flag for what to do: place, set_origin or
* place_or_set_origin.
*/
void place_or_set_origin_children();
/** Updates the placement for the child items. */
void prepare_placement() const;
/***** ***** ***** signal handlers ***** ****** *****/
void signal_handler_request_placement(dispatcher& dispatcher,
const event::ui_event event,
bool& handled);
};
// }---------- BUILDER -----------{
namespace implementation
{
struct builder_pane : public builder_widget
{
explicit builder_pane(const config& cfg);
widget* build() const;
widget* build(const replacements_map& replacements) const;
placer_base::tgrow_direction grow_direction;
unsigned parallel_items;
builder_grid_ptr item_definition;
};
} // namespace implementation
// }------------ END --------------
} // namespace gui2