-
-
Notifications
You must be signed in to change notification settings - Fork 994
/
spacer.cpp
191 lines (150 loc) · 4.3 KB
/
spacer.cpp
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
/*
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.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/widgets/spacer.hpp"
#include "gui/core/register_widget.hpp"
#include "gui/widgets/settings.hpp"
#include "utils/functional.hpp"
namespace gui2
{
// ------------ WIDGET -----------{
REGISTER_WIDGET(spacer)
bool spacer::fills_available_space()
{
return (!width_.has_formula() && width_() == 0) && (!height_.has_formula() && height_() == 0);
}
void spacer::request_reduce_width(const unsigned maximum_width)
{
// Do nothing unless this widget fills all available space (has non-size size).
if(fills_available_space()) {
styled_widget::request_reduce_width(maximum_width);
}
}
void spacer::request_reduce_height(const unsigned maximum_height)
{
// Do nothing unless this widget fills all available space (has non-size size).
if(fills_available_space()) {
styled_widget::request_reduce_height(maximum_height);
}
}
point spacer::calculate_best_size() const
{
const wfl::map_formula_callable& size = get_screen_size_variables();
unsigned width = width_(size);
unsigned height = height_(size);
point best_size;
if(width || height) {
best_size = point(width, height);
}
if(best_size != point()) {
return best_size;
}
return styled_widget::calculate_best_size();
}
void spacer::set_active(const bool /*active*/)
{
/* DO NOTHING */
}
bool spacer::get_active() const
{
return true;
}
unsigned spacer::get_state() const
{
return 0;
}
bool spacer::disable_click_dismiss() const
{
return false;
}
void spacer::impl_draw_background(int /*x_offset*/, int /*y_offset*/)
{
/* DO NOTHING */
}
const std::string& spacer::get_control_type() const
{
static const std::string type = "spacer";
return type;
}
// }---------- DEFINITION ---------{
spacer_definition::spacer_definition(const config& cfg)
: styled_widget_definition(cfg)
{
DBG_GUI_P << "Parsing spacer " << id << '\n';
load_resolutions<resolution>(cfg);
}
/*WIKI
* @page = GUIWidgetDefinitionWML
* @order = 1_spacer
*
* == Spacer ==
*
* @macro = spacer_description
*
* A spacer has no states so nothing to load.
* @begin{parent}{name="gui/"}
* @begin{tag}{name="spacer_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
* @end{tag}{name="spacer_definition"}
* @end{parent}{name="gui/"}
*/
spacer_definition::resolution::resolution(const config& cfg)
: resolution_definition(cfg)
{
}
// }---------- BUILDER -----------{
/*WIKI_MACRO
* @begin{macro}{spacer_description}
*
* A spacer is a dummy item to either fill in a widget since no empty
* items are allowed or to reserve a fixed space.
* @end{macro}
*/
/*WIKI
* @page = GUIWidgetInstanceWML
* @order = 2_spacer
* @begin{parent}{name="gui/window/resolution/grid/row/column/"}
* @begin{tag}{name="spacer"}{min=0}{max=-1}{super="generic/widget_instance"}
* == Spacer ==
*
* @macro = spacer_description
*
* If either the width or the height is non-zero the spacer functions as a
* fixed size spacer.
*
* @begin{table}{config}
* width & f_unsigned & 0 & The width of the spacer. $
* height & f_unsigned & 0 & The height of the spacer. $
* @end{table}
*
* The variable available are the same as for the window resolution see
* http://www.wesnoth.org/wiki/GUIToolkitWML#Resolution_2 for the list of
* items.
* @end{tag}{name="spacer"}
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
*/
namespace implementation
{
builder_spacer::builder_spacer(const config& cfg)
: builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
{
}
widget* builder_spacer::build() const
{
spacer* widget = new spacer(width_, height_);
init_control(widget);
DBG_GUI_G << "Window builder: placed spacer '" << id
<< "' with definition '" << definition << "'.\n";
return widget;
}
} // namespace implementation
// }------------ END --------------
} // namespace gui2