SizePolicy.h
1/* Copyright (C) 2017 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 02110-1301 USA
27*/
28
29#ifndef PT_FORMS_SIZEPOLICY_H
30#define PT_FORMS_SIZEPOLICY_H
31
32#include <Pt/Forms/Api.h>
33#include <Pt/Gfx/Size.h>
34
35namespace Pt {
36
37namespace Forms {
38
48{
49 public:
52 enum Mode
53 {
56 Any = 0,
57
61
65
68 Fixed = 3,
69 };
70
71 public:
75 : _horizontalMode(Any)
76 , _verticalMode(Any)
77 { }
78
82 : _horizontalMode(horizontal)
83 , _verticalMode(vertical)
84 { }
85
89 {
90 return _horizontalMode;
91 }
92
96 {
97 _horizontalMode = m;
98 }
99
103 {
104 return _verticalMode;
105 }
106
110 {
111 _verticalMode = m;
112 }
113
117 {
118 _horizontalMode = horizontal;
119 _verticalMode = vertical;
120 }
121
124 const Gfx::SizeF& size() const
125 {
126 return _sizeHint;
127 }
128
131 void setSize(const Gfx::SizeF& hint)
132 {
133 _sizeHint = hint;
134 }
135
138 void setSize(double w, double h)
139 {
140 _sizeHint.set(w, h);
141 }
142
145 double width() const
146 {
147 return _sizeHint.width();
148 }
149
152 void setWidth(double w)
153 {
154 _sizeHint.setWidth(w);
155 }
156
159 double height() const
160 {
161 return _sizeHint.height();
162 }
163
166 void setHeight(double h)
167 {
168 _sizeHint.setHeight(h);
169 }
170
173 bool operator== (const SizePolicy& s) const
174 {
175 return _horizontalMode == s._horizontalMode &&
176 _verticalMode == s._verticalMode &&
177 _sizeHint.isEqual(s._sizeHint);
178 }
179
182 bool operator!= (const SizePolicy& s) const
183 {
184 return _horizontalMode != s._horizontalMode ||
185 _verticalMode != s._verticalMode ||
186 ! _sizeHint.isEqual(s._sizeHint);
187 }
188
189 private:
190 Mode _horizontalMode;
191 Mode _verticalMode;
192 Gfx::SizeF _sizeHint;
193};
194
195} // namespace
196
197} // namespace
198
199#endif // include guard
double width() const
Returns the width hint.
Definition SizePolicy.h:145
Mode horizontal() const
Returns the horizontal mode.
Definition SizePolicy.h:88
SizePolicy(Mode horizontal, Mode vertical)
Creates a policy with horizontal and vertical modes.
Definition SizePolicy.h:81
Mode vertical() const
Returns the vertical mode.
Definition SizePolicy.h:102
Mode
Constraint applied to one axis.
Definition SizePolicy.h:53
@ Preferred
The axis uses the preferred size.
Definition SizePolicy.h:60
@ Fixed
The axis uses the policy size.
Definition SizePolicy.h:68
@ Any
The axis is not constrained by this policy.
Definition SizePolicy.h:56
@ Maximum
The axis is capped by the policy size.
Definition SizePolicy.h:64
double height() const
Returns the height hint.
Definition SizePolicy.h:159
void setWidth(double w)
Sets the width hint to w.
Definition SizePolicy.h:152
void setSize(double w, double h)
Sets the size hint to w by h.
Definition SizePolicy.h:138
bool operator==(const SizePolicy &s) const
Returns true when both policies compare equal.
Definition SizePolicy.h:173
void setHorizontal(Mode m)
Sets the horizontal mode to m.
Definition SizePolicy.h:95
void setSize(const Gfx::SizeF &hint)
Sets the size hint to hint.
Definition SizePolicy.h:131
SizePolicy()
Creates a policy with unconstrained axes.
Definition SizePolicy.h:74
const Gfx::SizeF & size() const
Returns the size hint.
Definition SizePolicy.h:124
void setHeight(double h)
Sets the height hint to h.
Definition SizePolicy.h:166
bool operator!=(const SizePolicy &s) const
Returns true when the policies differ.
Definition SizePolicy.h:182
void setMode(Mode horizontal, Mode vertical)
Sets both modes to horizontal and vertical.
Definition SizePolicy.h:116
void setVertical(Mode m)
Sets the vertical mode to m.
Definition SizePolicy.h:109
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33