-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
size_fixater.hpp
136 lines (107 loc) · 3 KB
/
size_fixater.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Copyright (C) 2016 Jyrki Vesterinen <sandgtx@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_WIDGETS_SIZE_FIXATER_HPP_INCLUDED
#define GUI_WIDGETS_SIZE_FIXATER_HPP_INCLUDED
#include <gui/widgets/container.hpp>
#include <gui/auxiliary/formula.hpp>
#include <gui/core/widget_definition.hpp>
#include <gui/core/window_builder.hpp>
#include <gui/widgets/generator.hpp>
namespace gui2
{
namespace implementation
{
struct tbuilder_size_fixater;
}
/* A fixed-size widget that wraps an arbitrary widget and forces it to the given size. */
class tsize_fixater : public tcontainer_
{
friend struct implementation::tbuilder_size_fixater;
public:
tsize_fixater() :
tcontainer_(1),
generator_(
tgenerator_::build(false, false, tgenerator_::independent, false))
{}
/** See @ref tcontrol::get_active. */
bool get_active() const override
{
return true;
}
/** See @ref tcontrol::get_state. */
unsigned get_state() const override
{
return 0;
}
/** See @ref twidget::layout_children. */
void layout_children() override;
void set_size(const tpoint& size)
{
size_ = size;
}
protected:
tpoint calculate_best_size() const override
{
return size_;
}
private:
tpoint size_;
/**
* Contains a pointer to the generator.
*
* The pointer is not owned by this class, it's stored in the content_grid_
* of the tcontainer_ base class and freed when its grid is freed.
*/
tgenerator_* generator_;
/**
* Finishes the building initialization of the widget.
*
* @param widget_builder The builder to build the contents of the
* widget.
*/
void finalize(tbuilder_grid_const_ptr widget_builder);
/** See @ref tcontrol::get_control_type. */
const std::string& get_control_type() const override
{
static const std::string control_type = "size_fixater";
return control_type;
}
/** See @ref tcontainer_::set_self_active. */
void set_self_active(const bool) override
{
// DO NOTHING
}
};
struct tsize_fixater_definition : public tcontrol_definition
{
explicit tsize_fixater_definition(const config& cfg);
struct tresolution : public tresolution_definition_
{
explicit tresolution(const config& cfg);
tbuilder_grid_ptr grid;
};
};
namespace implementation
{
struct tbuilder_size_fixater : public tbuilder_control
{
explicit tbuilder_size_fixater(const config& cfg);
using tbuilder_control::build;
twidget* build() const;
private:
tbuilder_grid_const_ptr content_;
tformula<unsigned> width_;
tformula<unsigned> height_;
};
}
}
#endif