The Battle for Wesnoth  1.19.0-dev
spacer.hpp
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 #pragma once
17 
19 
23 
24 namespace gui2
25 {
26 namespace implementation
27 {
28 struct builder_spacer;
29 }
30 
31 // ------------ WIDGET -----------{
32 
33 /**
34  * @ingroup GUIWidgetWML
35  *
36  * An empty widget to either fill in a widget since no empty items are allowed or to reserve a fixed space.
37  *
38  * Since every grid cell needs a widget this is a blank widget.
39  * This widget can also be used to 'force' sizes - if either the width or the height is non-zero the spacer functions as a fixed size spacer.
40  *
41  * Since we're a kind of dummy class we're always active, our drawing does nothing.
42  *
43  * Key |Type |Default |Description
44  * -------------|----------------------------------------|---------|-----------
45  * width | @ref guivartype_f_unsigned "f_unsigned"|0 |The width of the spacer.
46  * height | @ref guivartype_f_unsigned "f_unsigned"|0 |The height of the spacer.
47  * The variable available are the same as for the window resolution see @ref builder_window::window_resolution for the list of items.
48  */
49 class spacer : public styled_widget
50 {
51 public:
52  spacer(const implementation::builder_spacer& builder, const std::string& w = "0", const std::string& h = "0");
53 
54  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
55 
56  /** See @ref widget::request_reduce_width. */
57  virtual void request_reduce_width(const unsigned maximum_width) override;
58 
59  /** See @ref widget::request_reduce_height. */
60  virtual void request_reduce_height(const unsigned maximum_height) override;
61 
62 private:
63  /** See @ref widget::calculate_best_size. */
64  virtual point calculate_best_size() const override;
65 
66 public:
67  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
68 
69  /** See @ref styled_widget::set_active. */
70  virtual void set_active(const bool active) override;
71 
72  /** See @ref styled_widget::get_active. */
73  virtual bool get_active() const override;
74 
75  /** See @ref styled_widget::get_state. */
76  virtual unsigned get_state() const override;
77 
78  /** See @ref widget::disable_click_dismiss. */
79  bool disable_click_dismiss() const override;
80 
81  /***** ***** ***** setters / getters for members ***** ****** *****/
82 
83 private:
86 
87  bool fills_available_space();
88 
89  /** See @ref widget::impl_draw_background. */
90  virtual bool impl_draw_background() override;
91 
92 public:
93  /** Static type getter that does not rely on the widget being constructed. */
94  static const std::string& type();
95 
96 private:
97  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
98  virtual const std::string& get_control_type() const override;
99 };
100 
101 // }---------- DEFINITION ---------{
102 
104 {
105  explicit spacer_definition(const config& cfg);
106 
108  {
109  explicit resolution(const config& cfg);
110  };
111 };
112 
113 // }---------- BUILDER -----------{
114 
115 namespace implementation
116 {
117 
119 {
120  explicit builder_spacer(const config& cfg);
121 
123 
124  virtual std::unique_ptr<widget> build() const override;
125 
126 private:
127  // We store these as strings since they could contain formulas.
128  // The widget handles the parsing.
129  const std::string width_;
130  const std::string height_;
131 };
132 
133 } // namespace implementation
134 
135 // }------------ END --------------
136 
137 } // 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: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 bool impl_draw_background() override
See widget::impl_draw_background.
Definition: spacer.cpp:100
spacer(const implementation::builder_spacer &builder, const std::string &w="0", const std::string &h="0")
Definition: spacer.cpp:32
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
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 const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
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.
int w
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual std::unique_ptr< widget > build() const override
Definition: spacer.cpp:131
builder_spacer(const config &cfg)
Definition: spacer.cpp:126
virtual std::unique_ptr< widget > build() const=0
Base class of a resolution, contains the common keys for a resolution.
resolution(const config &cfg)
Definition: spacer.cpp:116
spacer_definition(const config &cfg)
Definition: spacer.cpp:108
Holds a 2D point.
Definition: point.hpp:25
#define h