The Battle for Wesnoth  1.19.0-dev
size_lock.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 
23 
24 namespace gui2
25 {
26 
27 namespace implementation
28 {
29 struct builder_size_lock;
30 }
31 
32 /**
33  * @ingroup GUIWidgetWML
34  *
35  * A fixed-size widget that wraps an arbitrary widget and forces it to the given size.
36  *
37  * A size lock contains one child widget and forces it to have the specified size.
38  * This can be used, for example, when there are two list boxes in different rows of the same grid
39  * and it's desired that only one list box changes size when its contents change.
40  *
41  * A size lock has no states.
42  * Key |Type |Default |Description
43  * -------------|----------------------------------------|---------|-----------
44  * widget | @ref guivartype_section "section" |mandatory|The widget.
45  * width | @ref guivartype_f_unsigned "f_unsigned"|mandatory|The width of the widget.
46  * height | @ref guivartype_f_unsigned "f_unsigned"|mandatory|The height of the widget.
47  */
48 class size_lock : public container_base
49 {
51 
52 public:
53  explicit size_lock(const implementation::builder_size_lock& builder);
54 
55  bool get_active() const override
56  {
57  return true;
58  }
59 
60  unsigned get_state() const override
61  {
62  return 0;
63  }
64 
65  /** See @ref widget::place. */
66  void place(const point& origin, const point& size) override;
67 
68  /** See @ref widget::layout_children. */
69  void layout_children() override;
70 
71 protected:
72  point calculate_best_size() const override;
73 
74 private:
77 
78  /**
79  * Points to the actual widget.
80  *
81  * The widget is owned by container_base (the base class).
82  */
84 
85  /**
86  * Finishes the building initialization of the widget.
87  *
88  * @param widget_builder The builder to build the contents of the
89  * widget.
90  */
91  void finalize(const builder_widget& widget_builder);
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  /** See @ref container_base::set_self_active */
102  void set_self_active(const bool) override
103  {
104  // DO NOTHING
105  }
106 };
107 
109 {
110  explicit size_lock_definition(const config& cfg);
111 
113  {
114  explicit resolution(const config& cfg);
115 
117  };
118 };
119 
120 namespace implementation
121 {
122 
124 {
125  explicit builder_size_lock(const config& cfg);
126 
128 
129  virtual std::unique_ptr<widget> build() const override;
130 
133 
134 private:
136 };
137 }
138 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
A generic container base class.
A fixed-size widget that wraps an arbitrary widget and forces it to the given size.
Definition: size_lock.hpp:49
typed_formula< unsigned > width_
Definition: size_lock.hpp:75
void place(const point &origin, const point &size) override
See widget::place.
Definition: size_lock.cpp:38
unsigned get_state() const override
Returns the id of the state.
Definition: size_lock.hpp:60
typed_formula< unsigned > height_
Definition: size_lock.hpp:76
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
bool get_active() const override
Gets the active state of the styled_widget.
Definition: size_lock.hpp:55
void finalize(const builder_widget &widget_builder)
Finishes the building initialization of the widget.
Definition: size_lock.cpp:71
void layout_children() override
See widget::layout_children.
Definition: size_lock.cpp:64
widget * widget_
Points to the actual widget.
Definition: size_lock.hpp:83
point calculate_best_size() const override
See widget::calculate_best_size.
Definition: size_lock.cpp:81
void set_self_active(const bool) override
See container_base::set_self_active.
Definition: size_lock.hpp:102
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
size_lock(const implementation::builder_size_lock &builder)
Definition: size_lock.cpp:30
Base class for all widgets.
Definition: widget.hpp:53
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
std::shared_ptr< const builder_widget > builder_widget_const_ptr
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85
Contains the info needed to instantiate a widget.
typed_formula< unsigned > height_
Definition: size_lock.hpp:132
typed_formula< unsigned > width_
Definition: size_lock.hpp:131
virtual std::unique_ptr< widget > build() const override
Definition: size_lock.cpp:127
builder_widget_const_ptr content_
Definition: size_lock.hpp:135
virtual std::unique_ptr< widget > build() const=0
Base class of a resolution, contains the common keys for a resolution.
size_lock_definition(const config &cfg)
Definition: size_lock.cpp:93
Holds a 2D point.
Definition: point.hpp:25