1 /*
2  * DQt - D bindings for the Qt Toolkit
3  *
4  * GNU Lesser General Public License Usage
5  * This file may be used under the terms of the GNU Lesser
6  * General Public License version 3 as published by the Free Software
7  * Foundation and appearing in the file LICENSE.LGPL3 included in the
8  * packaging of this file. Please review the following information to
9  * ensure the GNU Lesser General Public License version 3 requirements
10  * will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
11  */
12 module qt.core.size;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.global;
17 import qt.core.margins;
18 import qt.core.namespace;
19 import qt.core.typeinfo;
20 import qt.helpers;
21 
22 /+ #if defined(Q_OS_DARWIN) || defined(Q_QDOC)
23 struct CGSize;
24 #endif +/
25 
26 
27 
28 /// Binding for C++ class [QSize](https://doc.qt.io/qt-6/qsize.html).
29 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QSize
30 {
31 public:
32     /+pragma(inline, true) this()/+ noexcept+/
33     {
34         this.wd = -1;
35         this.ht = -1;
36     }+/
37     pragma(inline, true) this(int w, int h)/+ noexcept+/
38     {
39         this.wd = w;
40         this.ht = h;
41     }
42 
43     pragma(inline, true) bool isNull() const/+ noexcept+/
44     { return wd == 0 && ht == 0; }
45     pragma(inline, true) bool isEmpty() const/+ noexcept+/
46     { return wd < 1 || ht < 1; }
47     pragma(inline, true) bool isValid() const/+ noexcept+/
48     { return wd >= 0 && ht >= 0; }
49 
50     pragma(inline, true) int width() const/+ noexcept+/
51     { return wd; }
52     pragma(inline, true) int height() const/+ noexcept+/
53     { return ht; }
54     pragma(inline, true) void setWidth(int w)/+ noexcept+/
55     { wd = w; }
56     pragma(inline, true) void setHeight(int h)/+ noexcept+/
57     { ht = h; }
58     void transpose()/+ noexcept+/;
59     /+ [[nodiscard]] +/ pragma(inline, true) QSize transposed() const/+ noexcept+/
60     { return QSize(ht, wd); }
61 
62     pragma(inline, true) void scale(int w, int h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
63     { auto tmp = QSize(w, h); scale(tmp, mode); }
64     pragma(inline, true) void scale(ref const(QSize) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
65     { this = scaled(s, mode); }
66     /+ [[nodiscard]] +/ pragma(inline, true) QSize scaled(int w, int h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/
67     { auto tmp = QSize(w, h); return scaled(tmp, mode); }
68     /+ [[nodiscard]] +/ QSize scaled(ref const(QSize) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/;
69 
70     /+ [[nodiscard]] +/ pragma(inline, true) QSize expandedTo(ref const(QSize) otherSize) const/+ noexcept+/
71     {
72         return QSize(qMax(wd,otherSize.wd), qMax(ht,otherSize.ht));
73     }
74     /+ [[nodiscard]] +/ pragma(inline, true) QSize boundedTo(ref const(QSize) otherSize) const/+ noexcept+/
75     {
76         return QSize(qMin(wd,otherSize.wd), qMin(ht,otherSize.ht));
77     }
78 
79     /+ [[nodiscard]] +/ QSize grownBy(QMargins m) const/+ noexcept+/
80     { return QSize(width() + m.left() + m.right(), height() + m.top() + m.bottom()); }
81     /+ [[nodiscard]] +/ QSize shrunkBy(QMargins m) const/+ noexcept+/
82     { return QSize(width() - m.left() - m.right(), height() - m.top() - m.bottom()); }
83 
84     pragma(inline, true) ref int rwidth()/+ noexcept+/ return
85     { return wd; }
86     pragma(inline, true) ref int rheight()/+ noexcept+/ return
87     { return ht; }
88 
89     pragma(inline, true) ref QSize opOpAssign(string op)(ref const(QSize) s)/+ noexcept+/ if(op == "+")
90     {
91         wd += s.wd;
92         ht += s.ht;
93         return this;
94     }
95     pragma(inline, true) ref QSize opOpAssign(string op)(ref const(QSize) s)/+ noexcept+/ if(op == "-")
96     {
97         wd -= s.wd;
98         ht -= s.ht;
99         return this;
100     }
101     /+pragma(inline, true) ref QSize operator *=(qreal c)/+ noexcept+/
102     {
103         wd = qRound(wd * c);
104         ht = qRound(ht * c);
105         return this;
106     }+/
107     /+pragma(inline, true) ref QSize operator /=(qreal c)
108     {
109         (mixin(Q_ASSERT(q{!qFuzzyIsNull(c)})));
110         wd = qRound(wd / c);
111         ht = qRound(ht / c);
112         return this;
113     }+/
114 
115     /+ friend inline constexpr bool operator==(const QSize &s1, const QSize &s2) noexcept
116     { return s1.wd == s2.wd && s1.ht == s2.ht; } +/
117     /+ friend inline constexpr bool operator!=(const QSize &s1, const QSize &s2) noexcept
118     { return s1.wd != s2.wd || s1.ht != s2.ht; } +/
119     /+ friend inline constexpr QSize operator+(const QSize &s1, const QSize &s2) noexcept
120     { return QSize(s1.wd + s2.wd, s1.ht + s2.ht); } +/
121     /+ friend inline constexpr QSize operator-(const QSize &s1, const QSize &s2) noexcept
122     { return QSize(s1.wd - s2.wd, s1.ht - s2.ht); } +/
123     /+ friend inline constexpr QSize operator*(const QSize &s, qreal c) noexcept
124     { return QSize(qRound(s.wd * c), qRound(s.ht * c)); } +/
125     /+ friend inline constexpr QSize operator*(qreal c, const QSize &s) noexcept
126     { return s * c; } +/
127     /+ friend inline QSize operator/(const QSize &s, qreal c)
128     { Q_ASSERT(!qFuzzyIsNull(c)); return QSize(qRound(s.wd / c), qRound(s.ht / c)); } +/
129     /+ friend inline constexpr size_t qHash(const QSize &, size_t) noexcept; +/
130 
131     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
132     {
133         /+ [[nodiscard]] CGSize toCGSize() const noexcept; +/
134     }
135 
136 private:
137     int wd = -1;
138     int ht = -1;
139 
140     /+ template <std::size_t I,
141               typename S,
142               std::enable_if_t<(I < 2), bool> = true,
143               std::enable_if_t<std::is_same_v<std::decay_t<S>, QSize>, bool> = true> +/
144     /+ friend constexpr decltype(auto) get(S &&s) noexcept
145     {
146         static if (I == 0)
147             return (std::forward<S>(s).wd);
148         else static if (I == 1)
149             return (std::forward<S>(s).ht);
150     } +/
151     mixin(CREATE_CONVENIENCE_WRAPPERS);
152 }
153 /+ Q_DECLARE_TYPEINFO(QSize, Q_RELOCATABLE_TYPE);
154 
155 /*****************************************************************************
156   QSize stream functions
157  *****************************************************************************/
158 
159 #ifndef QT_NO_DATASTREAM
160 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSize &);
161 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSize &);
162 #endif
163 
164 
165 /*****************************************************************************
166   QSize inline functions
167  *****************************************************************************/
168 
169 constexpr inline size_t qHash(const QSize &s, size_t seed = 0) noexcept
170 { return qHashMulti(seed, s.wd, s.ht); }
171 
172 #ifndef QT_NO_DEBUG_STREAM
173 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSize &);
174 #endif +/
175 
176 
177 /// Binding for C++ class [QSizeF](https://doc.qt.io/qt-6/qsizef.html).
178 @Q_RELOCATABLE_TYPE extern(C++, class) struct /+ Q_CORE_EXPORT +/ QSizeF
179 {
180 public:
181     @disable this();
182     /+pragma(inline, true) this()/+ noexcept+/
183     {
184         this.wd = -1.;
185         this.ht = -1.;
186     }+/
187     pragma(inline, true) this(ref const(QSize) sz)/+ noexcept+/
188     {
189         this.wd = sz.width();
190         this.ht = sz.height();
191     }
192     pragma(inline, true) this(qreal w, qreal h)/+ noexcept+/
193     {
194         this.wd = w;
195         this.ht = h;
196     }
197 
198     pragma(inline, true) bool isNull() const/+ noexcept+/
199     { return qIsNull(wd) && qIsNull(ht); }
200     pragma(inline, true) bool isEmpty() const/+ noexcept+/
201     { return wd <= 0. || ht <= 0.; }
202     pragma(inline, true) bool isValid() const/+ noexcept+/
203     { return wd >= 0. && ht >= 0.; }
204 
205     pragma(inline, true) qreal width() const/+ noexcept+/
206     { return wd; }
207     pragma(inline, true) qreal height() const/+ noexcept+/
208     { return ht; }
209     pragma(inline, true) void setWidth(qreal w)/+ noexcept+/
210     { wd = w; }
211     pragma(inline, true) void setHeight(qreal h)/+ noexcept+/
212     { ht = h; }
213     void transpose()/+ noexcept+/;
214     /+ [[nodiscard]] +/ pragma(inline, true) QSizeF transposed() const/+ noexcept+/
215     { return QSizeF(ht, wd); }
216 
217     pragma(inline, true) void scale(qreal w, qreal h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
218     { auto tmp = QSizeF(w, h); scale(tmp, mode); }
219     pragma(inline, true) void scale(ref const(QSizeF) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode)/+ noexcept+/
220     { this = scaled(s, mode); }
221     /+ [[nodiscard]] +/ pragma(inline, true) QSizeF scaled(qreal w, qreal h, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/
222     { auto tmp = QSizeF(w, h); return scaled(tmp, mode); }
223     /+ [[nodiscard]] +/ QSizeF scaled(ref const(QSizeF) s, /+ Qt:: +/qt.core.namespace.AspectRatioMode mode) const/+ noexcept+/;
224 
225     /+ [[nodiscard]] +/ pragma(inline, true) QSizeF expandedTo(ref const(QSizeF) otherSize) const/+ noexcept+/
226     {
227         return QSizeF(qMax(wd, otherSize.wd), qMax(ht, otherSize.ht));
228     }
229     /+ [[nodiscard]] +/ pragma(inline, true) QSizeF boundedTo(ref const(QSizeF) otherSize) const/+ noexcept+/
230     {
231         return QSizeF(qMin(wd, otherSize.wd), qMin(ht, otherSize.ht));
232     }
233 
234     /+ [[nodiscard]] +/ QSizeF grownBy(QMarginsF m) const/+ noexcept+/
235     { return QSizeF(width() + m.left() + m.right(), height() + m.top() + m.bottom()); }
236     /+ [[nodiscard]] +/ QSizeF shrunkBy(QMarginsF m) const/+ noexcept+/
237     { return QSizeF(width() - m.left() - m.right(), height() - m.top() - m.bottom()); }
238 
239     pragma(inline, true) ref qreal rwidth()/+ noexcept+/ return
240     { return wd; }
241     pragma(inline, true) ref qreal rheight()/+ noexcept+/ return
242     { return ht; }
243 
244     pragma(inline, true) ref QSizeF opOpAssign(string op)(ref const(QSizeF) s)/+ noexcept+/ if(op == "+")
245     {
246         wd += s.wd;
247         ht += s.ht;
248         return this;
249     }
250     pragma(inline, true) ref QSizeF opOpAssign(string op)(ref const(QSizeF) s)/+ noexcept+/ if(op == "-")
251     {
252         wd -= s.wd;
253         ht -= s.ht;
254         return this;
255     }
256     /+pragma(inline, true) ref QSizeF operator *=(qreal c)/+ noexcept+/
257     {
258         wd *= c;
259         ht *= c;
260         return this;
261     }+/
262     /+pragma(inline, true) ref QSizeF operator /=(qreal c)
263     {
264         (mixin(Q_ASSERT(q{!qFuzzyIsNull(c) && qIsFinite(c)})));
265         wd = wd / c;
266         ht = ht / c;
267         return this;
268     }+/
269 
270     /+ QT_WARNING_PUSH
271     QT_WARNING_DISABLE_FLOAT_COMPARE +/
272     /+ friend constexpr inline bool operator==(const QSizeF &s1, const QSizeF &s2)
273     {
274         return ((!s1.wd || !s2.wd) ? qFuzzyIsNull(s1.wd - s2.wd) : qFuzzyCompare(s1.wd, s2.wd))
275             && ((!s1.ht || !s2.ht) ? qFuzzyIsNull(s1.ht - s2.ht) : qFuzzyCompare(s1.ht, s2.ht));
276     } +/
277     /+ QT_WARNING_POP +/
278     /+ friend constexpr inline bool operator!=(const QSizeF &s1, const QSizeF &s2)
279     { return !(s1 == s2); } +/
280     /+ friend constexpr inline QSizeF operator+(const QSizeF &s1, const QSizeF &s2) noexcept
281     { return QSizeF(s1.wd + s2.wd, s1.ht + s2.ht); } +/
282     /+ friend constexpr inline QSizeF operator-(const QSizeF &s1, const QSizeF &s2) noexcept
283     { return QSizeF(s1.wd - s2.wd, s1.ht - s2.ht); } +/
284     /+ friend constexpr inline QSizeF operator*(const QSizeF &s, qreal c) noexcept
285     { return QSizeF(s.wd * c, s.ht * c); } +/
286     /+ friend constexpr inline QSizeF operator*(qreal c, const QSizeF &s) noexcept
287     { return s * c; } +/
288     /+ friend inline QSizeF operator/(const QSizeF &s, qreal c)
289     { Q_ASSERT(!qFuzzyIsNull(c)); return QSizeF(s.wd / c, s.ht / c); } +/
290 
291     pragma(inline, true) QSize toSize() const/+ noexcept+/
292     {
293         return QSize(qRound(wd), qRound(ht));
294     }
295 
296     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
297     {
298         /+ [[nodiscard]] static QSizeF fromCGSize(CGSize size) noexcept; +/
299         /+ [[nodiscard]] CGSize toCGSize() const noexcept; +/
300     }
301 
302 private:
303     qreal wd = -1.;
304     qreal ht = -1.;
305 
306     /+ template <std::size_t I,
307               typename S,
308               std::enable_if_t<(I < 2), bool> = true,
309               std::enable_if_t<std::is_same_v<std::decay_t<S>, QSizeF>, bool> = true> +/
310     /+ friend constexpr decltype(auto) get(S &&s) noexcept
311     {
312         static if (I == 0)
313             return (std::forward<S>(s).wd);
314         else static if (I == 1)
315             return (std::forward<S>(s).ht);
316     } +/
317     mixin(CREATE_CONVENIENCE_WRAPPERS);
318 }
319 /+ Q_DECLARE_TYPEINFO(QSizeF, Q_RELOCATABLE_TYPE);
320 
321 
322 /*****************************************************************************
323   QSizeF stream functions
324  *****************************************************************************/
325 
326 #ifndef QT_NO_DATASTREAM
327 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QSizeF &);
328 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QSizeF &);
329 #endif
330 
331 
332 /*****************************************************************************
333   QSizeF inline functions
334  *****************************************************************************/
335 
336 #ifndef QT_NO_DEBUG_STREAM
337 Q_CORE_EXPORT QDebug operator<<(QDebug, const QSizeF &);
338 #endif
339 
340 
341 /*****************************************************************************
342   QSize/QSizeF tuple protocol
343  *****************************************************************************/
344 
345 namespace std {
346     template <>
347     class tuple_size<QT_PREPEND_NAMESPACE(QSize)> : public integral_constant<size_t, 2> {};
348     template <>
349     class tuple_element<0, QT_PREPEND_NAMESPACE(QSize)> { public: using type = int; };
350     template <>
351     class tuple_element<1, QT_PREPEND_NAMESPACE(QSize)> { public: using type = int; };
352 
353     template <>
354     class tuple_size<QT_PREPEND_NAMESPACE(QSizeF)> : public integral_constant<size_t, 2> {};
355     template <>
356     class tuple_element<0, QT_PREPEND_NAMESPACE(QSizeF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
357     template <>
358     class tuple_element<1, QT_PREPEND_NAMESPACE(QSizeF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
359 } +/
360