The Battle for Wesnoth  1.15.12+dev
spacer.hpp
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 #pragma once
16 
18 
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 void impl_draw_background(surface& frame_buffer,
90  int x_offset,
91  int y_offset) override;
92 
93 public:
94  /** Static type getter that does not rely on the widget being constructed. */
95  static const std::string& type();
96 
97 private:
98  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
99  virtual const std::string& get_control_type() const override;
100 };
101 
102 // }---------- DEFINITION ---------{
103 
105 {
106  explicit spacer_definition(const config& cfg);
107 
109  {
110  explicit resolution(const config& cfg);
111  };
112 };
113 
114 // }---------- BUILDER -----------{
115 
116 namespace implementation
117 {
118 
120 {
121  explicit builder_spacer(const config& cfg);
122 
124 
125  virtual widget* build() const override;
126 
127 private:
128  // We store these as strings since they could contain formulas.
129  // The widget handles the parsing.
130  const std::string width_;
131  const std::string height_;
132 };
133 
134 } // namespace implementation
135 
136 // }------------ END --------------
137 
138 } // 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:22
Holds a 2D point.
Definition: point.hpp:23
typed_formula< unsigned > width_
Definition: spacer.hpp:83
int w
Base class for all visible items.
typed_formula< unsigned > height_
Definition: spacer.hpp:84
point resolution()
Definition: general.cpp:387
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
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:59
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.