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