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 class spacer : public styled_widget
33 {
34 public:
35  spacer(const implementation::builder_spacer& builder, const std::string& w = "0", const std::string& h = "0");
36 
37  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
38 
39  /** See @ref widget::request_reduce_width. */
40  virtual void request_reduce_width(const unsigned maximum_width) override;
41 
42  /** See @ref widget::request_reduce_height. */
43  virtual void request_reduce_height(const unsigned maximum_height) override;
44 
45 private:
46  /** See @ref widget::calculate_best_size. */
47  virtual point calculate_best_size() const override;
48 
49 public:
50  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
51 
52  /** See @ref styled_widget::set_active. */
53  virtual void set_active(const bool active) override;
54 
55  /** See @ref styled_widget::get_active. */
56  virtual bool get_active() const override;
57 
58  /** See @ref styled_widget::get_state. */
59  virtual unsigned get_state() const override;
60 
61  /** See @ref widget::disable_click_dismiss. */
62  bool disable_click_dismiss() const override;
63 
64  /***** ***** ***** setters / getters for members ***** ****** *****/
65 
66 private:
69 
70  bool fills_available_space();
71 
72  /** See @ref widget::impl_draw_background. */
73  virtual bool impl_draw_background() override;
74 
75 public:
76  /** Static type getter that does not rely on the widget being constructed. */
77  static const std::string& type();
78 
79 private:
80  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
81  virtual const std::string& get_control_type() const override;
82 };
83 
84 // }---------- DEFINITION ---------{
85 
87 {
88  explicit spacer_definition(const config& cfg);
89 
91  {
92  explicit resolution(const config& cfg);
93  };
94 };
95 
96 // }---------- BUILDER -----------{
97 
98 namespace implementation
99 {
100 
102 {
103  explicit builder_spacer(const config& cfg);
104 
106 
107  virtual std::unique_ptr<widget> build() const override;
108 
109 private:
110  // We store these as strings since they could contain formulas.
111  // The widget handles the parsing.
112  const std::string width_;
113  const std::string height_;
114 };
115 
116 } // namespace implementation
117 
118 // }------------ END --------------
119 
120 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
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:67
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:68
virtual void request_reduce_width(const unsigned maximum_width) override
See widget::request_reduce_width.
Definition: spacer.cpp:42
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
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