The Battle for Wesnoth  1.19.0-dev
spacer.cpp
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 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
18 #include "gui/widgets/spacer.hpp"
19 
21 
22 
23 namespace gui2
24 {
25 
26 // ------------ WIDGET -----------{
27 
28 REGISTER_WIDGET(spacer)
29 
30 spacer::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 
42 void spacer::request_reduce_width(const unsigned maximum_width)
43 {
44  // Do nothing unless this widget fills all available space (has non-size size).
45  if(fills_available_space()) {
47  }
48 }
49 
50 void spacer::request_reduce_height(const unsigned maximum_height)
51 {
52  // Do nothing unless this widget fills all available space (has non-size size).
53  if(fills_available_space()) {
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 
78 void spacer::set_active(const bool /*active*/)
79 {
80  /* DO NOTHING */
81 }
82 
83 bool spacer::get_active() const
84 {
85  return true;
86 }
87 
88 unsigned 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 
115  : resolution_definition(cfg)
116 {
117 }
118 
119 // }---------- BUILDER -----------{
120 
121 namespace implementation
122 {
123 
124 builder_spacer::builder_spacer(const config& cfg)
125  : builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
126 {
127 }
128 
129 std::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:159
An empty widget to either fill in a widget since no empty items are allowed or to reserve a fixed spa...
Definition: spacer.hpp:49
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:83
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:84
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: spacer.cpp:42
Base class for all visible items.
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:53
int w
#define DBG_GUI_G
Definition: log.hpp:41
#define DBG_GUI_P
Definition: log.hpp:66
void point(int x, int y)
Draw a single point.
Definition: draw.cpp:202
Generic file dialog.
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:94
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
#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.
Base class of a resolution, contains the common keys for a resolution.
resolution(const config &cfg)
Definition: spacer.cpp:114
spacer_definition(const config &cfg)
Definition: spacer.cpp:106
Holds a 2D point.
Definition: point.hpp:25
#define h