The Battle for Wesnoth  1.15.1+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  * An empty widget.
34  *
35  * Since every grid cell needs a widget this is a blank widget. This widget can
36  * also be used to 'force' sizes.
37  *
38  * Since we're a kind of dummy class we're always active, our drawing does
39  * nothing.
40  */
41 class spacer : public styled_widget
42 {
43 public:
44  spacer(const implementation::builder_spacer& builder, const std::string& w = "0", const std::string& h = "0");
45 
46  /***** ***** ***** ***** layout functions ***** ***** ***** *****/
47 
48  /** See @ref widget::request_reduce_width. */
49  virtual void request_reduce_width(const unsigned maximum_width) override;
50 
51  /** See @ref widget::request_reduce_height. */
52  virtual void request_reduce_height(const unsigned maximum_height) override;
53 
54 private:
55  /** See @ref widget::calculate_best_size. */
56  virtual point calculate_best_size() const override;
57 
58 public:
59  /***** ***** ***** ***** Inherited ***** ***** ***** *****/
60 
61  /** See @ref styled_widget::set_active. */
62  virtual void set_active(const bool active) override;
63 
64  /** See @ref styled_widget::get_active. */
65  virtual bool get_active() const override;
66 
67  /** See @ref styled_widget::get_state. */
68  virtual unsigned get_state() const override;
69 
70  /** See @ref widget::disable_click_dismiss. */
71  bool disable_click_dismiss() const override;
72 
73  /***** ***** ***** setters / getters for members ***** ****** *****/
74 
75 private:
78 
79  bool fills_available_space();
80 
81  /** See @ref widget::impl_draw_background. */
82  virtual void impl_draw_background(surface& frame_buffer,
83  int x_offset,
84  int y_offset) override;
85 
86 public:
87  /** Static type getter that does not rely on the widget being constructed. */
88  static const std::string& type();
89 
90 private:
91  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
92  virtual const std::string& get_control_type() const override;
93 };
94 
95 // }---------- DEFINITION ---------{
96 
98 {
99  explicit spacer_definition(const config& cfg);
100 
102  {
103  explicit resolution(const config& cfg);
104  };
105 };
106 
107 // }---------- BUILDER -----------{
108 
109 namespace implementation
110 {
111 
113 {
114  explicit builder_spacer(const config& cfg);
115 
117 
118  widget* build() const;
119 
120 private:
121  // We store these as strings since they could contain formulas.
122  // The widget handles the parsing.
123  const std::string width_;
124  const std::string height_;
125 };
126 
127 } // namespace implementation
128 
129 // }------------ END --------------
130 
131 } // 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:47
#define h
Generic file dialog.
Definition: field-fwd.hpp:22
window * build(const builder_window::window_resolution *definition)
Builds a window.
Holds a 2D point.
Definition: point.hpp:23
typed_formula< unsigned > width_
Definition: spacer.hpp:76
int w
Base class for all visible items.
typed_formula< unsigned > height_
Definition: spacer.hpp:77
point resolution()
Definition: general.cpp:373
An empty widget.
Definition: spacer.hpp:41
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.