The Battle for Wesnoth  1.17.21+dev
spacer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2023
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 #include "gui/widgets/settings.hpp"
22 
23 #include <functional>
24 
25 namespace gui2
26 {
27 
28 // ------------ WIDGET -----------{
29 
30 REGISTER_WIDGET(spacer)
31 
32 spacer::spacer(const implementation::builder_spacer& builder, const std::string& w, const std::string& h)
33  : styled_widget(builder, type())
34  , width_(w)
35  , height_(h)
36 {
37 }
38 
40 {
41  return (!width_.has_formula() && width_() == 0) && (!height_.has_formula() && height_() == 0);
42 }
43 
44 void spacer::request_reduce_width(const unsigned maximum_width)
45 {
46  // Do nothing unless this widget fills all available space (has non-size size).
47  if(fills_available_space()) {
49  }
50 }
51 
52 void spacer::request_reduce_height(const unsigned maximum_height)
53 {
54  // Do nothing unless this widget fills all available space (has non-size size).
55  if(fills_available_space()) {
57  }
58 }
59 
61 {
63 
64  unsigned width = width_(size);
65  unsigned height = height_(size);
66 
67  point best_size;
68 
69  if(width || height) {
70  best_size = point(width, height);
71  }
72 
73  if(best_size != point()) {
74  return best_size;
75  }
76 
78 }
79 
80 void spacer::set_active(const bool /*active*/)
81 {
82  /* DO NOTHING */
83 }
84 
85 bool spacer::get_active() const
86 {
87  return true;
88 }
89 
90 unsigned spacer::get_state() const
91 {
92  return 0;
93 }
94 
96 {
97  return false;
98 }
99 
101 {
102  /* DO NOTHING */
103 }
104 
105 // }---------- DEFINITION ---------{
106 
109 {
110  DBG_GUI_P << "Parsing spacer " << id;
111 
112  load_resolutions<resolution>(cfg);
113 }
114 
116  : resolution_definition(cfg)
117 {
118 }
119 
120 // }---------- BUILDER -----------{
121 
122 namespace implementation
123 {
124 
125 builder_spacer::builder_spacer(const config& cfg)
126  : builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
127 {
128 }
129 
130 std::unique_ptr<widget> builder_spacer::build() const
131 {
132  auto widget = std::make_unique<spacer>(*this, width_, height_);
133 
134  DBG_GUI_G << "Window builder: placed spacer '" << id
135  << "' with definition '" << definition << "'.";
136 
137  return widget;
138 }
139 
140 } // namespace implementation
141 
142 // }------------ END --------------
143 
144 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:161
An empty widget to either fill in a widget since no empty items are allowed or to reserve a fixed spa...
Definition: spacer.hpp:50
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
Definition: spacer.cpp:52
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: spacer.cpp:90
bool fills_available_space()
Definition: spacer.cpp:39
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: spacer.cpp:80
virtual void impl_draw_background() override
See widget::impl_draw_background.
Definition: spacer.cpp:100
typed_formula< unsigned > width_
Definition: spacer.hpp:84
virtual bool get_active() const override
See styled_widget::get_active.
Definition: spacer.cpp:85
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: spacer.cpp:95
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: spacer.cpp:60
typed_formula< unsigned > height_
Definition: spacer.hpp:85
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: spacer.cpp:44
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:54
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:193
Generic file dialog.
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:96
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:87
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
This file contains the settings handling of the widget library.
virtual std::unique_ptr< widget > build() const override
Definition: spacer.cpp:130
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:115
spacer_definition(const config &cfg)
Definition: spacer.cpp:107
Holds a 2D point.
Definition: point.hpp:25
#define h