The Battle for Wesnoth  1.17.0-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 /**
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 widget* build() const override;
130 
133 
134 private:
136 };
137 }
138 }
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:48
typed_formula< unsigned > height_
Definition: size_lock.hpp:76
typed_formula< unsigned > width_
Definition: size_lock.hpp:131
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
Returns the id of the state.
Definition: size_lock.hpp:60
bool get_active() const override
Gets the active state of the styled_widget.
Definition: size_lock.hpp:55
typed_formula< unsigned > width_
Definition: size_lock.hpp:75
A fixed-size widget that wraps an arbitrary widget and forces it to the given size.
Definition: size_lock.hpp:48
void set_self_active(const bool) override
See container_base::set_self_active.
Definition: size_lock.hpp:102
Holds a 2D point.
Definition: point.hpp:23
A generic container base class.
builder_widget_const_ptr content_
Definition: size_lock.hpp:135
typed_formula< unsigned > height_
Definition: size_lock.hpp:132
point resolution()
Definition: general.cpp:392
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
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:83