The Battle for Wesnoth  1.15.11+dev
spacer.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gui/widgets/spacer.hpp"
18 
20 #include "gui/widgets/settings.hpp"
21 
22 #include <functional>
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 REGISTER_WIDGET(spacer)
30 
31 spacer::spacer(const implementation::builder_spacer& builder, const std::string& w, const std::string& h)
32  : styled_widget(builder, type())
33  , width_(w)
34  , height_(h)
35 {
36 }
37 
39 {
40  return (!width_.has_formula() && width_() == 0) && (!height_.has_formula() && height_() == 0);
41 }
42 
43 void spacer::request_reduce_width(const unsigned maximum_width)
44 {
45  // Do nothing unless this widget fills all available space (has non-size size).
46  if(fills_available_space()) {
48  }
49 }
50 
51 void spacer::request_reduce_height(const unsigned maximum_height)
52 {
53  // Do nothing unless this widget fills all available space (has non-size size).
54  if(fills_available_space()) {
56  }
57 }
58 
60 {
62 
63  unsigned width = width_(size);
64  unsigned height = height_(size);
65 
66  point best_size;
67 
68  if(width || height) {
69  best_size = point(width, height);
70  }
71 
72  if(best_size != point()) {
73  return best_size;
74  }
75 
77 }
78 
79 void spacer::set_active(const bool /*active*/)
80 {
81  /* DO NOTHING */
82 }
83 
84 bool spacer::get_active() const
85 {
86  return true;
87 }
88 
89 unsigned spacer::get_state() const
90 {
91  return 0;
92 }
93 
95 {
96  return false;
97 }
98 
99 void spacer::impl_draw_background(surface& /*frame_buffer*/
100  ,
101  int /*x_offset*/
102  ,
103  int /*y_offset*/)
104 {
105  /* DO NOTHING */
106 }
107 
108 // }---------- DEFINITION ---------{
109 
112 {
113  DBG_GUI_P << "Parsing spacer " << id << '\n';
114 
115  load_resolutions<resolution>(cfg);
116 }
117 
119  : resolution_definition(cfg)
120 {
121 }
122 
123 // }---------- BUILDER -----------{
124 
125 namespace implementation
126 {
127 
128 builder_spacer::builder_spacer(const config& cfg)
129  : builder_styled_widget(cfg), width_(cfg["width"]), height_(cfg["height"])
130 {
131 }
132 
134 {
135  spacer* widget = new spacer(*this, width_, height_);
136 
137  DBG_GUI_G << "Window builder: placed spacer '" << id
138  << "' with definition '" << definition << "'.\n";
139 
140  return widget;
141 }
142 
143 } // namespace implementation
144 
145 // }------------ END --------------
146 
147 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
#define DBG_GUI_P
Definition: log.hpp:65
virtual bool get_active() const override
See styled_widget::get_active.
Definition: spacer.cpp:84
Base class for all widgets.
Definition: widget.hpp:49
virtual point calculate_best_size() const override
See widget::calculate_best_size.
Definition: spacer.cpp:59
virtual unsigned get_state() const override
See styled_widget::get_state.
Definition: spacer.cpp:89
STL namespace.
#define h
virtual widget * build() const override
Definition: spacer.cpp:133
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:99
Generic file dialog.
Definition: field-fwd.hpp:22
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: spacer.cpp:43
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:86
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:38
resolution(const config &cfg)
Definition: spacer.cpp:118
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
Definition: spacer.cpp:94
spacer_definition(const config &cfg)
Definition: spacer.cpp:110
Holds a 2D point.
Definition: point.hpp:23
typed_formula< unsigned > width_
Definition: spacer.hpp:83
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:51
typed_formula< unsigned > height_
Definition: spacer.hpp:84
An empty widget to either fill in a widget since no empty items are allowed or to reserve a fixed spa...
Definition: spacer.hpp:48
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:59
#define DBG_GUI_G
Definition: log.hpp:40
virtual void set_active(const bool active) override
See styled_widget::set_active.
Definition: spacer.cpp:79
virtual void impl_draw_background(surface &frame_buffer, int x_offset, int y_offset) override
See widget::impl_draw_background.
Definition: spacer.cpp:99
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.