The Battle for Wesnoth  1.17.0-dev
spacer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
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 
100 void spacer::impl_draw_background(surface& /*frame_buffer*/
101  ,
102  int /*x_offset*/
103  ,
104  int /*y_offset*/)
105 {
106  /* DO NOTHING */
107 }
108 
109 // }---------- DEFINITION ---------{
110 
113 {
114  DBG_GUI_P << "Parsing spacer " << id << '\n';
115 
116  load_resolutions<resolution>(cfg);
117 }
118 
120  : resolution_definition(cfg)
121 {
122 }
123 
124 // }---------- BUILDER -----------{
125 
126 namespace implementation
127 {
128 
129 builder_spacer::builder_spacer(const config& cfg)
130  : builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
131 {
132 }
133 
135 {
136  spacer* widget = new spacer(*this, width_, height_);
137 
138  DBG_GUI_G << "Window builder: placed spacer '" << id
139  << "' with definition '" << definition << "'.\n";
140 
141  return widget;
142 }
143 
144 } // namespace implementation
145 
146 // }------------ END --------------
147 
148 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
#define DBG_GUI_P
Definition: log.hpp:66
virtual bool get_active() const override
See styled_widget::get_active.
Definition: spacer.cpp:85
Base class for all widgets.
Definition: widget.hpp:49
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: spacer.cpp:60
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: spacer.cpp:90
STL namespace.
#define h
virtual widget * build() const override
Definition: spacer.cpp:134
virtual point calculate_best_size() const override
See widget::calculate_best_size.
void get_screen_size_variables(wfl::map_formula_callable &variable)
Gets a formula object with the screen size.
Definition: helper.cpp:100
Generic file dialog.
Definition: field-fwd.hpp:23
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: spacer.cpp:44
std::string definition
Parameters for the styled_widget.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:87
This file contains the settings handling of the widget library.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
bool fills_available_space()
Definition: spacer.cpp:39
resolution(const config &cfg)
Definition: spacer.cpp:119
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: spacer.cpp:95
spacer_definition(const config &cfg)
Definition: spacer.cpp:111
Holds a 2D point.
Definition: point.hpp:24
typed_formula< unsigned > width_
Definition: spacer.hpp:84
int w
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Base class for all visible items.
virtual void request_reduce_height(const unsigned maximum_height) override
See widget::request_reduce_height.
Definition: spacer.cpp:52
typed_formula< unsigned > height_
Definition: spacer.hpp:85
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
bool has_formula() const
Determine whether the class contains a formula.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
#define DBG_GUI_G
Definition: log.hpp:41
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: spacer.cpp:80
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See widget::impl_draw_background.
Definition: spacer.cpp:100
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.