The Battle for Wesnoth  1.17.0-dev
size_lock.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
3  by Jyrki Vesterinen <sandgtx@gmail.com>
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 
24 
25 namespace gui2
26 {
27 
28 namespace implementation
29 {
30 struct builder_size_lock;
31 }
32 
33 /**
34  * @ingroup GUIWidgetWML
35  *
36  * A fixed-size widget that wraps an arbitrary widget and forces it to the given size.
37  *
38  * A size lock contains one child widget and forces it to have the specified size.
39  * This can be used, for example, when there are two list boxes in different rows of the same grid
40  * and it's desired that only one list box changes size when its contents change.
41  *
42  * A size lock has no states.
43  * Key |Type |Default |Description
44  * -------------|----------------------------------------|---------|-----------
45  * widget | @ref guivartype_section "section" |mandatory|The widget.
46  * width | @ref guivartype_f_unsigned "f_unsigned"|mandatory|The width of the widget.
47  * height | @ref guivartype_f_unsigned "f_unsigned"|mandatory|The height of the widget.
48  */
49 class size_lock : public container_base
50 {
52 
53 public:
54  explicit size_lock(const implementation::builder_size_lock& builder);
55 
56  bool get_active() const override
57  {
58  return true;
59  }
60 
61  unsigned get_state() const override
62  {
63  return 0;
64  }
65 
66  /** See @ref widget::place. */
67  void place(const point& origin, const point& size) override;
68 
69  /** See @ref widget::layout_children. */
70  void layout_children() override;
71 
72 protected:
73  point calculate_best_size() const override;
74 
75 private:
78 
79  /**
80  * Points to the actual widget.
81  *
82  * The widget is owned by container_base (the base class).
83  */
85 
86  /**
87  * Finishes the building initialization of the widget.
88  *
89  * @param widget_builder The builder to build the contents of the
90  * widget.
91  */
92  void finalize(const builder_widget& widget_builder);
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  /** See @ref container_base::set_self_active */
103  void set_self_active(const bool) override
104  {
105  // DO NOTHING
106  }
107 };
108 
110 {
111  explicit size_lock_definition(const config& cfg);
112 
114  {
115  explicit resolution(const config& cfg);
116 
118  };
119 };
120 
121 namespace implementation
122 {
123 
125 {
126  explicit builder_size_lock(const config& cfg);
127 
129 
130  virtual widget* build() const override;
131 
134 
135 private:
137 };
138 }
139 }
Contains the info needed to instantiate a widget.
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
typed_formula< unsigned > height_
Definition: size_lock.hpp:77
typed_formula< unsigned > width_
Definition: size_lock.hpp:132
Generic file dialog.
Definition: field-fwd.hpp:23
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:87
unsigned get_state() const override
Returns the id of the state.
Definition: size_lock.hpp:61
bool get_active() const override
Gets the active state of the styled_widget.
Definition: size_lock.hpp:56
typed_formula< unsigned > width_
Definition: size_lock.hpp:76
A fixed-size widget that wraps an arbitrary widget and forces it to the given size.
Definition: size_lock.hpp:49
void set_self_active(const bool) override
See container_base::set_self_active.
Definition: size_lock.hpp:103
Holds a 2D point.
Definition: point.hpp:24
A generic container base class.
builder_widget_const_ptr content_
Definition: size_lock.hpp:136
typed_formula< unsigned > height_
Definition: size_lock.hpp:133
point resolution()
Definition: general.cpp:393
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
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:84