The Battle for Wesnoth  1.15.1+dev
size_lock.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 Jyrki Vesterinen <sandgtx@gmail.com>
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 
23 
24 namespace gui2
25 {
26 
27 namespace implementation
28 {
29 struct builder_size_lock;
30 }
31 
32 /* A fixed-size widget that wraps an arbitrary widget and forces it to the given size. */
33 
34 class size_lock : public container_base
35 {
37 
38 public:
39  explicit size_lock(const implementation::builder_size_lock& builder);
40 
41  /** See @ref control::get_active. */
42  bool get_active() const override
43  {
44  return true;
45  }
46 
47  /** See @ref control::get_state. */
48  unsigned get_state() const override
49  {
50  return 0;
51  }
52 
53  /** See @ref widget::place. */
54  void place(const point& origin, const point& size) override;
55 
56  /** See @ref widget::layout_children. */
57  void layout_children() override;
58 
59 protected:
60  point calculate_best_size() const override;
61 
62 private:
65 
66  /**
67  * Points to the actual widget.
68  *
69  * The widget is owned by container_base (the base class).
70  */
72 
73  /**
74  * Finishes the building initialization of the widget.
75  *
76  * @param widget_builder The builder to build the contents of the
77  * widget.
78  */
79  void finalize(builder_widget_const_ptr widget_builder);
80 
81 public:
82  /** Static type getter that does not rely on the widget being constructed. */
83  static const std::string& type();
84 
85 private:
86  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
87  virtual const std::string& get_control_type() const override;
88 
89  /** See @ref container_::set_self_active. */
90  void set_self_active(const bool) override
91  {
92  // DO NOTHING
93  }
94 };
95 
97 {
98  explicit size_lock_definition(const config& cfg);
99 
101  {
102  explicit resolution(const config& cfg);
103 
105  };
106 };
107 
108 namespace implementation
109 {
110 
112 {
113  explicit builder_size_lock(const config& cfg);
114 
116 
117  widget* build() const;
118 
121 
122 private:
124 };
125 }
126 }
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
typed_formula< unsigned > height_
Definition: size_lock.hpp:64
typed_formula< unsigned > width_
Definition: size_lock.hpp:119
Generic file dialog.
Definition: field-fwd.hpp:22
std::shared_ptr< const builder_widget > builder_widget_const_ptr
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
unsigned get_state() const override
See control::get_state.
Definition: size_lock.hpp:48
bool get_active() const override
See control::get_active.
Definition: size_lock.hpp:42
typed_formula< unsigned > width_
Definition: size_lock.hpp:63
void set_self_active(const bool) override
See container_::set_self_active.
Definition: size_lock.hpp:90
window * build(const builder_window::window_resolution *definition)
Builds a window.
Holds a 2D point.
Definition: point.hpp:23
A generic container base class.
builder_widget_const_ptr content_
Definition: size_lock.hpp:123
typed_formula< unsigned > height_
Definition: size_lock.hpp:120
point resolution()
Definition: general.cpp:373
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
widget * widget_
Points to the actual widget.
Definition: size_lock.hpp:71