The Battle for Wesnoth  1.19.0-dev
widget_definition.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
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 
18 #include "config.hpp"
19 #include "font/font_options.hpp"
20 #include "font/text.hpp"
23 
24 #include <vector>
25 
26 namespace gui2
27 {
28 
29 /**
30  * Contains the state info for a resolution.
31  *
32  * At the moment all states are the same so there is no need to use
33  * inheritance. If that is needed at some point the containers should contain
34  * pointers
35  */
37 {
38  explicit state_definition(const config& cfg);
39 
41 };
42 
43 /**
44  * Base class of a resolution, contains the common keys for a resolution.
45  *
46  * Depending on the resolution a widget can look different. Resolutions are evaluated in order of appearance.
47  * The window_width and window_height are the upper limit this resolution is valid for.
48  * When one of the sizes gets above the limit, the next resolution is selected.
49  * There's one special case where both values are 0. This resolution always matches.
50  * (Resolution definitions behind that one will never be picked.)
51  * This resolution can be used as upper limit or if there's only one resolution.
52  *
53  * The default (and also minimum) size of a button is determined by two items, the wanted default size and the size needed for the text.
54  * The size of the text differs per used widget so needs to be determined per button.
55  *
56  * Container widgets like panels and windows have other rules for their sizes.
57  * Their sizes are based on the size of their children (and the border they need themselves).
58  * It's wise to set all sizes to 0 for these kind of widgets.
59  *
60  * Key |Type |Default |Description
61  * -----------------|------------------------------------|---------|-------------
62  * window_width | @ref guivartype_unsigned "unsigned"|0 |Width of the application window.
63  * window_height | @ref guivartype_unsigned "unsigned"|0 |Height of the application window.
64  * min_width | @ref guivartype_unsigned "unsigned"|0 |The minimum width of the widget.
65  * min_height | @ref guivartype_unsigned "unsigned"|0 |The minimum height of the widget.
66  * default_width | @ref guivartype_unsigned "unsigned"|0 |The default width of the widget.
67  * default_height | @ref guivartype_unsigned "unsigned"|0 |The default height of the widget.
68  * max_width | @ref guivartype_unsigned "unsigned"|0 |TThe maximum width of the widget.
69  * max_height | @ref guivartype_unsigned "unsigned"|0 |The maximum height of the widget.
70  * text_extra_width | @ref guivartype_unsigned "unsigned"|0 |The extra width needed to determine the minimal size for the text.
71  * text_extra_height| @ref guivartype_unsigned "unsigned"|0 |The extra height needed to determine the minimal size for the text.
72  * text_font_family | font_family |"" |The font family, needed to determine the minimal size for the text.
73  * text_font_size | @ref guivartype_unsigned "unsigned"|0 |The font size, which needs to be used to determine the minimal size for the text.
74  * text_font_style | font_style |"" |The font style, which needs to be used to determine the minimal size for the text.
75  * state | @ref guivartype_section "section" |mandatory|Every widget has one or more state sections. Note they aren't called state but state_xxx the exact names are listed per widget.
76  */
78 {
79  explicit resolution_definition(const config& cfg);
80 
81  unsigned window_width;
82  unsigned window_height;
83 
84  unsigned min_width;
85  unsigned min_height;
86 
87  unsigned default_width;
88  unsigned default_height;
89 
90  unsigned max_width;
91  unsigned max_height;
92 
93  std::vector<linked_group_definition> linked_groups;
94 
95  unsigned text_extra_width;
98 
101 
102  std::vector<state_definition> state;
103 };
104 
105 typedef std::shared_ptr<resolution_definition>
107 
108 typedef std::shared_ptr<const resolution_definition>
110 
112 {
113  explicit styled_widget_definition(const config& cfg);
114 
115  template<class T>
116  void load_resolutions(const config& cfg)
117  {
118  for(const config& resolution : cfg.child_range("resolution")) {
119  resolutions.emplace_back(std::make_shared<T>(resolution));
120  }
121  }
122 
123  std::string id;
125 
126  std::vector<resolution_definition_ptr> resolutions;
127 };
128 
129 typedef std::shared_ptr<styled_widget_definition> styled_widget_definition_ptr;
130 
131 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
child_itors child_range(config_key_type key)
Definition: config.cpp:273
family_class
Font classes for get_font_families().
Generic file dialog.
std::shared_ptr< styled_widget_definition > styled_widget_definition_ptr
std::shared_ptr< resolution_definition > resolution_definition_ptr
std::shared_ptr< const resolution_definition > resolution_definition_const_ptr
point resolution()
Definition: general.cpp:392
Base class of a resolution, contains the common keys for a resolution.
std::vector< state_definition > state
typed_formula< unsigned > text_font_size
std::vector< linked_group_definition > linked_groups
font::pango_text::FONT_STYLE text_font_style
resolution_definition(const config &cfg)
font::family_class text_font_family
Contains the state info for a resolution.
state_definition(const config &cfg)
void load_resolutions(const config &cfg)
styled_widget_definition(const config &cfg)
std::vector< resolution_definition_ptr > resolutions