The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
spacer.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 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
16#define GETTEXT_DOMAIN "wesnoth-lib"
17
19
21
22
23namespace gui2
24{
25
26// ------------ WIDGET -----------{
27
28REGISTER_WIDGET(spacer)
29
30spacer::spacer(const implementation::builder_spacer& builder, const std::string& w, const std::string& h)
31 : styled_widget(builder, type())
32 , width_(w)
33 , height_(h)
34{
35}
36
38{
39 return (!width_.has_formula() && width_() == 0) && (!height_.has_formula() && height_() == 0);
40}
41
42void spacer::request_reduce_width(const unsigned maximum_width)
43{
44 // Do nothing unless this widget fills all available space (has non-size size).
47 }
48}
49
50void spacer::request_reduce_height(const unsigned maximum_height)
51{
52 // Do nothing unless this widget fills all available space (has non-size size).
55 }
56}
57
59{
61
62 unsigned width = width_(size);
63 unsigned height = height_(size);
64
65 point best_size;
66
67 if(width || height) {
68 best_size = point(width, height);
69 }
70
71 if(best_size != point()) {
72 return best_size;
73 }
74
76}
77
78void spacer::set_active(const bool /*active*/)
79{
80 /* DO NOTHING */
81}
82
84{
85 return true;
86}
87
88unsigned spacer::get_state() const
89{
90 return 0;
91}
92
94{
95 return false;
96}
97
99{
100 /* DO NOTHING */
101 return true;
102}
103
104// }---------- DEFINITION ---------{
105
108{
109 DBG_GUI_P << "Parsing spacer " << id;
110
111 load_resolutions<resolution>(cfg);
112}
113
118
119// }---------- BUILDER -----------{
120
121namespace implementation
122{
123
124builder_spacer::builder_spacer(const config& cfg)
125 : builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
126{
127}
128
129std::unique_ptr<widget> builder_spacer::build() const
130{
131 auto widget = std::make_unique<spacer>(*this, width_, height_);
132
133 DBG_GUI_G << "Window builder: placed spacer '" << id
134 << "' with definition '" << definition << "'.";
135
136 return widget;
137}
138
139} // namespace implementation
140
141// }------------ END --------------
142
143} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
Definition spacer.cpp:50
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition spacer.cpp:88
bool fills_available_space()
Definition spacer.cpp:37
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition spacer.cpp:78
virtual bool impl_draw_background() override
See widget::impl_draw_background.
Definition spacer.cpp:98
typed_formula< unsigned > width_
Definition spacer.hpp:67
virtual bool get_active() const override
See styled_widget::get_active.
Definition spacer.cpp:83
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition spacer.cpp:93
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition spacer.cpp:58
typed_formula< unsigned > height_
Definition spacer.hpp:68
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition spacer.cpp:42
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
virtual point calculate_best_size() const override
See widget::calculate_best_size.
bool has_formula() const
Determine whether the class contains a formula.
Base class for all widgets.
Definition widget.hpp:55
const config * cfg
#define DBG_GUI_G
Definition log.hpp:41
#define DBG_GUI_P
Definition log.hpp:66
Generic file dialog.
wfl::map_formula_callable get_screen_size_variables()
Gets a formula object with the screen size.
Definition helper.cpp:159
Contains the implementation details for lexical_cast and shouldn't be used directly.
STL namespace.
int w
Definition pathfind.cpp:188
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
virtual std::unique_ptr< widget > build() const override
Definition spacer.cpp:129
std::string definition
Parameters for the styled_widget.
spacer_definition(const config &cfg)
Definition spacer.cpp:106
Holds a 2D point.
Definition point.hpp:25
#define h