The Battle for Wesnoth  1.17.0-dev
spacer.hpp
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 #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 void impl_draw_background(surface& frame_buffer,
91  int x_offset,
92  int y_offset) override;
93 
94 public:
95  /** Static type getter that does not rely on the widget being constructed. */
96  static const std::string& type();
97 
98 private:
99  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
100  virtual const std::string& get_control_type() const override;
101 };
102 
103 // }---------- DEFINITION ---------{
104 
106 {
107  explicit spacer_definition(const config& cfg);
108 
110  {
111  explicit resolution(const config& cfg);
112  };
113 };
114 
115 // }---------- BUILDER -----------{
116 
117 namespace implementation
118 {
119 
121 {
122  explicit builder_spacer(const config& cfg);
123 
125 
126  virtual widget* build() const override;
127 
128 private:
129  // We store these as strings since they could contain formulas.
130  // The widget handles the parsing.
131  const std::string width_;
132  const std::string height_;
133 };
134 
135 } // namespace implementation
136 
137 // }------------ END --------------
138 
139 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
Base class for all widgets.
Definition: widget.hpp:49
#define h
Generic file dialog.
Definition: field-fwd.hpp:23
Holds a 2D point.
Definition: point.hpp:24
typed_formula< unsigned > width_
Definition: spacer.hpp:84
int w
Base class for all visible items.
typed_formula< unsigned > height_
Definition: spacer.hpp:85
point resolution()
Definition: general.cpp:393
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
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.