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.margins;
13 extern(C++):
14 
15 import qt.config;
16 import qt.core.global;
17 import qt.core.typeinfo;
18 import qt.helpers;
19 
20 /*****************************************************************************
21   QMargins class
22  *****************************************************************************/
23 
24 /// Binding for C++ class [QMargins](https://doc.qt.io/qt-6/qmargins.html).
25 @Q_RELOCATABLE_TYPE extern(C++, class) struct QMargins
26 {
27 public:
28     /+pragma(inline, true) this()/+ noexcept+/
29     {
30         this.m_left = 0;
31         this.m_top = 0;
32         this.m_right = 0;
33         this.m_bottom = 0;
34     }+/
35     pragma(inline, true) this(int aleft, int atop, int aright, int abottom)/+ noexcept+/
36     {
37         this.m_left = aleft;
38         this.m_top = atop;
39         this.m_right = aright;
40         this.m_bottom = abottom;
41     }
42 
43     pragma(inline, true) bool isNull() const/+ noexcept+/
44     { return m_left==0 && m_top==0 && m_right==0 && m_bottom==0; }
45 
46     pragma(inline, true) int left() const/+ noexcept+/
47     { return m_left; }
48     pragma(inline, true) int top() const/+ noexcept+/
49     { return m_top; }
50     pragma(inline, true) int right() const/+ noexcept+/
51     { return m_right; }
52     pragma(inline, true) int bottom() const/+ noexcept+/
53     { return m_bottom; }
54 
55     pragma(inline, true) void setLeft(int aleft)/+ noexcept+/
56     { m_left = aleft; }
57     pragma(inline, true) void setTop(int atop)/+ noexcept+/
58     { m_top = atop; }
59     pragma(inline, true) void setRight(int aright)/+ noexcept+/
60     { m_right = aright; }
61     pragma(inline, true) void setBottom(int abottom)/+ noexcept+/
62     { m_bottom = abottom; }
63 
64     pragma(inline, true) ref QMargins opOpAssign(string op)(ref const(QMargins) margins)/+ noexcept+/ if(op == "+")
65     {
66         return (){return this = this + margins;
67     }();
68     }
69     pragma(inline, true) ref QMargins opOpAssign(string op)(ref const(QMargins) margins)/+ noexcept+/ if(op == "-")
70     {
71         return (){return this = this - margins;
72     }();
73     }
74     pragma(inline, true) ref QMargins opOpAssign(string op)(int margin)/+ noexcept+/ if(op == "+")
75     {
76         m_left += margin;
77         m_top += margin;
78         m_right += margin;
79         m_bottom += margin;
80         return this;
81     }
82     pragma(inline, true) ref QMargins opOpAssign(string op)(int margin)/+ noexcept+/ if(op == "-")
83     {
84         m_left -= margin;
85         m_top -= margin;
86         m_right -= margin;
87         m_bottom -= margin;
88         return this;
89     }
90     /+pragma(inline, true) ref QMargins operator *=(int factor)/+ noexcept+/
91     {
92         return (){return this = this * factor;
93     }();
94     }+/
95     /+pragma(inline, true) ref QMargins operator /=(int divisor)
96     {
97         return (){return this = this / divisor;
98     }();
99     }+/
100     /+pragma(inline, true) ref QMargins operator *=(qreal factor)/+ noexcept+/
101     {
102         return (){return this = this * factor;
103     }();
104     }+/
105     /+pragma(inline, true) ref QMargins operator /=(qreal divisor)
106     {
107         return (){return this = this / divisor;
108     }();
109     }+/
110 
111 private:
112     int m_left = 0;
113     int m_top = 0;
114     int m_right = 0;
115     int m_bottom = 0;
116 
117     /+ friend constexpr inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept
118     {
119         return
120                 m1.m_left == m2.m_left &&
121                 m1.m_top == m2.m_top &&
122                 m1.m_right == m2.m_right &&
123                 m1.m_bottom == m2.m_bottom;
124     } +/
125 
126     /+ friend constexpr inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept
127     {
128         return !(m1 == m2);
129     } +/
130 
131     /+ template <std::size_t I,
132               typename M,
133               std::enable_if_t<(I < 4), bool> = true,
134               std::enable_if_t<std::is_same_v<std::decay_t<M>, QMargins>, bool> = true> +/
135     /+ friend constexpr decltype(auto) get(M &&m) noexcept
136     {
137         static if (I == 0)
138             return (std::forward<M>(m).m_left);
139         else static if (I == 1)
140             return (std::forward<M>(m).m_top);
141         else static if (I == 2)
142             return (std::forward<M>(m).m_right);
143         else static if (I == 3)
144             return (std::forward<M>(m).m_bottom);
145     } +/
146     mixin(CREATE_CONVENIENCE_WRAPPERS);
147 }
148 
149 /+ Q_DECLARE_TYPEINFO(QMargins, Q_RELOCATABLE_TYPE);
150 
151 /*****************************************************************************
152   QMargins stream functions
153  *****************************************************************************/
154 #ifndef QT_NO_DATASTREAM
155 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMargins &);
156 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMargins &);
157 #endif +/
158 
159 /*****************************************************************************
160   QMargins inline functions
161  *****************************************************************************/
162 
163 
164 /+pragma(inline, true) QMargins operator +(ref const(QMargins) m1, ref const(QMargins) m2)/+ noexcept+/
165 {
166     return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
167                     m1.right() + m2.right(), m1.bottom() + m2.bottom());
168 }+/
169 
170 /+pragma(inline, true) QMargins operator -(ref const(QMargins) m1, ref const(QMargins) m2)/+ noexcept+/
171 {
172     return QMargins(m1.left() - m2.left(), m1.top() - m2.top(),
173                     m1.right() - m2.right(), m1.bottom() - m2.bottom());
174 }+/
175 
176 /+pragma(inline, true) QMargins operator +(ref const(QMargins) lhs, int rhs)/+ noexcept+/
177 {
178     return QMargins(lhs.left() + rhs, lhs.top() + rhs,
179                     lhs.right() + rhs, lhs.bottom() + rhs);
180 }+/
181 
182 /+pragma(inline, true) QMargins operator +(int lhs, ref const(QMargins) rhs)/+ noexcept+/
183 {
184     return QMargins(rhs.left() + lhs, rhs.top() + lhs,
185                     rhs.right() + lhs, rhs.bottom() + lhs);
186 }+/
187 
188 /+pragma(inline, true) QMargins operator -(ref const(QMargins) lhs, int rhs)/+ noexcept+/
189 {
190     return QMargins(lhs.left() - rhs, lhs.top() - rhs,
191                     lhs.right() - rhs, lhs.bottom() - rhs);
192 }+/
193 
194 /+pragma(inline, true) QMargins operator *(ref const(QMargins) margins, int factor)/+ noexcept+/
195 {
196     return QMargins(margins.left() * factor, margins.top() * factor,
197                     margins.right() * factor, margins.bottom() * factor);
198 }+/
199 
200 /+pragma(inline, true) QMargins operator *(int factor, ref const(QMargins) margins)/+ noexcept+/
201 {
202     return QMargins(margins.left() * factor, margins.top() * factor,
203                     margins.right() * factor, margins.bottom() * factor);
204 }+/
205 
206 /+pragma(inline, true) QMargins operator *(ref const(QMargins) margins, qreal factor)/+ noexcept+/
207 {
208     return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
209                     qRound(margins.right() * factor), qRound(margins.bottom() * factor));
210 }+/
211 
212 /+pragma(inline, true) QMargins operator *(qreal factor, ref const(QMargins) margins)/+ noexcept+/
213 {
214     return QMargins(qRound(margins.left() * factor), qRound(margins.top() * factor),
215                     qRound(margins.right() * factor), qRound(margins.bottom() * factor));
216 }+/
217 
218 /+pragma(inline, true) QMargins operator /(ref const(QMargins) margins, int divisor)
219 {
220     return QMargins(margins.left() / divisor, margins.top() / divisor,
221                     margins.right() / divisor, margins.bottom() / divisor);
222 }+/
223 
224 /+pragma(inline, true) QMargins operator /(ref const(QMargins) margins, qreal divisor)
225 {
226     return QMargins(qRound(margins.left() / divisor), qRound(margins.top() / divisor),
227                     qRound(margins.right() / divisor), qRound(margins.bottom() / divisor));
228 }+/
229 
230 /+pragma(inline, true) QMargins operator |(ref const(QMargins) m1, ref const(QMargins) m2)/+ noexcept+/
231 {
232     return QMargins(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
233                     qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
234 }+/
235 
236 /+pragma(inline, true) QMargins operator +(ref const(QMargins) margins)/+ noexcept+/
237 {
238     return margins;
239 }+/
240 
241 /+pragma(inline, true) QMargins operator -(ref const(QMargins) margins)/+ noexcept+/
242 {
243     return QMargins(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
244 }+/
245 
246 /+ #ifndef QT_NO_DEBUG_STREAM
247 Q_CORE_EXPORT QDebug operator<<(QDebug, const QMargins &);
248 #endif +/
249 
250 /*****************************************************************************
251   QMarginsF class
252  *****************************************************************************/
253 
254 /// Binding for C++ class [QMarginsF](https://doc.qt.io/qt-6/qmarginsf.html).
255 @Q_RELOCATABLE_TYPE extern(C++, class) struct QMarginsF
256 {
257 public:
258     /+pragma(inline, true) this()/+ noexcept+/
259     {
260         this.m_left = 0;
261         this.m_top = 0;
262         this.m_right = 0;
263         this.m_bottom = 0;
264     }+/
265     pragma(inline, true) this(qreal aleft, qreal atop, qreal aright, qreal abottom)/+ noexcept+/
266     {
267         this.m_left = aleft;
268         this.m_top = atop;
269         this.m_right = aright;
270         this.m_bottom = abottom;
271     }
272     pragma(inline, true) this(ref const(QMargins) margins)/+ noexcept+/
273     {
274         this.m_left = margins.left();
275         this.m_top = margins.top();
276         this.m_right = margins.right();
277         this.m_bottom = margins.bottom();
278     }
279 
280     pragma(inline, true) bool isNull() const/+ noexcept+/
281     { return qFuzzyIsNull(m_left) && qFuzzyIsNull(m_top) && qFuzzyIsNull(m_right) && qFuzzyIsNull(m_bottom); }
282 
283     pragma(inline, true) qreal left() const/+ noexcept+/
284     { return m_left; }
285     pragma(inline, true) qreal top() const/+ noexcept+/
286     { return m_top; }
287     pragma(inline, true) qreal right() const/+ noexcept+/
288     { return m_right; }
289     pragma(inline, true) qreal bottom() const/+ noexcept+/
290     { return m_bottom; }
291 
292     pragma(inline, true) void setLeft(qreal aleft)/+ noexcept+/
293     { m_left = aleft; }
294     pragma(inline, true) void setTop(qreal atop)/+ noexcept+/
295     { m_top = atop; }
296     pragma(inline, true) void setRight(qreal aright)/+ noexcept+/
297     { m_right = aright; }
298     pragma(inline, true) void setBottom(qreal abottom)/+ noexcept+/
299     { m_bottom = abottom; }
300 
301     pragma(inline, true) ref QMarginsF opOpAssign(string op)(ref const(QMarginsF) margins)/+ noexcept+/ if(op == "+")
302     {
303         return (){return this = this + margins;
304     }();
305     }
306     pragma(inline, true) ref QMarginsF opOpAssign(string op)(ref const(QMarginsF) margins)/+ noexcept+/ if(op == "-")
307     {
308         return (){return this = this - margins;
309     }();
310     }
311     pragma(inline, true) ref QMarginsF opOpAssign(string op)(qreal addend)/+ noexcept+/ if(op == "+")
312     {
313         m_left += addend;
314         m_top += addend;
315         m_right += addend;
316         m_bottom += addend;
317         return this;
318     }
319     pragma(inline, true) ref QMarginsF opOpAssign(string op)(qreal subtrahend)/+ noexcept+/ if(op == "-")
320     {
321         m_left -= subtrahend;
322         m_top -= subtrahend;
323         m_right -= subtrahend;
324         m_bottom -= subtrahend;
325         return this;
326     }
327     /+pragma(inline, true) ref QMarginsF operator *=(qreal factor)/+ noexcept+/
328     {
329         return (){return this = this * factor;
330     }();
331     }+/
332     /+pragma(inline, true) ref QMarginsF operator /=(qreal divisor)
333     {
334         return (){return this = this / divisor;
335     }();
336     }+/
337 
338     pragma(inline, true) QMargins toMargins() const/+ noexcept+/
339     {
340         return QMargins(qRound(m_left), qRound(m_top), qRound(m_right), qRound(m_bottom));
341     }
342 
343 private:
344     qreal m_left = 0;
345     qreal m_top = 0;
346     qreal m_right = 0;
347     qreal m_bottom = 0;
348 
349     /+ friend constexpr inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
350     {
351         return qFuzzyCompare(lhs.left(), rhs.left())
352             && qFuzzyCompare(lhs.top(), rhs.top())
353             && qFuzzyCompare(lhs.right(), rhs.right())
354             && qFuzzyCompare(lhs.bottom(), rhs.bottom());
355     } +/
356 
357     /+ friend constexpr inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
358     {
359         return !(lhs == rhs);
360     } +/
361 
362     /+ template <std::size_t I,
363               typename M,
364               std::enable_if_t<(I < 4), bool> = true,
365               std::enable_if_t<std::is_same_v<std::decay_t<M>, QMarginsF>, bool> = true> +/
366     /+ friend constexpr decltype(auto) get(M &&m) noexcept
367     {
368         static if (I == 0)
369             return (std::forward<M>(m).m_left);
370         else static if (I == 1)
371             return (std::forward<M>(m).m_top);
372         else static if (I == 2)
373             return (std::forward<M>(m).m_right);
374         else static if (I == 3)
375             return (std::forward<M>(m).m_bottom);
376     } +/
377     mixin(CREATE_CONVENIENCE_WRAPPERS);
378 }
379 
380 /+ Q_DECLARE_TYPEINFO(QMarginsF, Q_RELOCATABLE_TYPE);
381 
382 /*****************************************************************************
383   QMarginsF stream functions
384  *****************************************************************************/
385 
386 #ifndef QT_NO_DATASTREAM
387 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QMarginsF &);
388 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QMarginsF &);
389 #endif +/
390 
391 /*****************************************************************************
392   QMarginsF inline functions
393  *****************************************************************************/
394 
395 
396 /+pragma(inline, true) QMarginsF operator +(ref const(QMarginsF) lhs, ref const(QMarginsF) rhs)/+ noexcept+/
397 {
398     return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
399                      lhs.right() + rhs.right(), lhs.bottom() + rhs.bottom());
400 }+/
401 
402 /+pragma(inline, true) QMarginsF operator -(ref const(QMarginsF) lhs, ref const(QMarginsF) rhs)/+ noexcept+/
403 {
404     return QMarginsF(lhs.left() - rhs.left(), lhs.top() - rhs.top(),
405                      lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom());
406 }+/
407 
408 /+pragma(inline, true) QMarginsF operator +(ref const(QMarginsF) lhs, qreal rhs)/+ noexcept+/
409 {
410     return QMarginsF(lhs.left() + rhs, lhs.top() + rhs,
411                      lhs.right() + rhs, lhs.bottom() + rhs);
412 }+/
413 
414 /+pragma(inline, true) QMarginsF operator +(qreal lhs, ref const(QMarginsF) rhs)/+ noexcept+/
415 {
416     return QMarginsF(rhs.left() + lhs, rhs.top() + lhs,
417                      rhs.right() + lhs, rhs.bottom() + lhs);
418 }+/
419 
420 /+pragma(inline, true) QMarginsF operator -(ref const(QMarginsF) lhs, qreal rhs)/+ noexcept+/
421 {
422     return QMarginsF(lhs.left() - rhs, lhs.top() - rhs,
423                      lhs.right() - rhs, lhs.bottom() - rhs);
424 }+/
425 
426 /+pragma(inline, true) QMarginsF operator *(ref const(QMarginsF) lhs, qreal rhs)/+ noexcept+/
427 {
428     return QMarginsF(lhs.left() * rhs, lhs.top() * rhs,
429                      lhs.right() * rhs, lhs.bottom() * rhs);
430 }+/
431 
432 /+pragma(inline, true) QMarginsF operator *(qreal lhs, ref const(QMarginsF) rhs)/+ noexcept+/
433 {
434     return QMarginsF(rhs.left() * lhs, rhs.top() * lhs,
435                      rhs.right() * lhs, rhs.bottom() * lhs);
436 }+/
437 
438 /+pragma(inline, true) QMarginsF operator /(ref const(QMarginsF) lhs, qreal divisor)
439 {
440     (mixin(Q_ASSERT(q{divisor < 0 || divisor > 0})));
441     return QMarginsF(lhs.left() / divisor, lhs.top() / divisor,
442                      lhs.right() / divisor, lhs.bottom() / divisor);
443 }+/
444 
445 /+pragma(inline, true) QMarginsF operator |(ref const(QMarginsF) m1, ref const(QMarginsF) m2)/+ noexcept+/
446 {
447     return QMarginsF(qMax(m1.left(), m2.left()), qMax(m1.top(), m2.top()),
448                      qMax(m1.right(), m2.right()), qMax(m1.bottom(), m2.bottom()));
449 }+/
450 
451 /+pragma(inline, true) QMarginsF operator +(ref const(QMarginsF) margins)/+ noexcept+/
452 {
453     return margins;
454 }+/
455 
456 /+pragma(inline, true) QMarginsF operator -(ref const(QMarginsF) margins)/+ noexcept+/
457 {
458     return QMarginsF(-margins.left(), -margins.top(), -margins.right(), -margins.bottom());
459 }+/
460 
461 /+ #ifndef QT_NO_DEBUG_STREAM
462 Q_CORE_EXPORT QDebug operator<<(QDebug, const QMarginsF &);
463 #endif
464 
465 
466 /*****************************************************************************
467   QMargins/QMarginsF tuple protocol
468  *****************************************************************************/
469 
470 namespace std {
471     template <>
472     class tuple_size<QT_PREPEND_NAMESPACE(QMargins)> : public integral_constant<size_t, 4> {};
473     template <>
474     class tuple_element<0, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
475     template <>
476     class tuple_element<1, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
477     template <>
478     class tuple_element<2, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
479     template <>
480     class tuple_element<3, QT_PREPEND_NAMESPACE(QMargins)> { public: using type = int; };
481 
482     template <>
483     class tuple_size<QT_PREPEND_NAMESPACE(QMarginsF)> : public integral_constant<size_t, 4> {};
484     template <>
485     class tuple_element<0, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
486     template <>
487     class tuple_element<1, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
488     template <>
489     class tuple_element<2, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
490     template <>
491     class tuple_element<3, QT_PREPEND_NAMESPACE(QMarginsF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); };
492 } +/
493