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