1use cxx::{type_id, ExternType};
7use std::fmt;
8
9#[cxx::bridge]
10mod ffi {
11 #[namespace = "Qt"]
12 unsafe extern "C++" {
13 include!("cxx-qt-lib/qt.h");
14 type AspectRatioMode = crate::AspectRatioMode;
15 }
16
17 unsafe extern "C++" {
18 include!("cxx-qt-lib/qmargins.h");
19 type QMargins = crate::QMargins;
20 include!("cxx-qt-lib/qsize.h");
21 type QSize = super::QSize;
22 include!("cxx-qt-lib/qstring.h");
23 type QString = crate::QString;
24 include!("cxx-qt-lib/qsizef.h");
25 #[allow(dead_code)]
26 type QSizeF = crate::QSizeF;
27
28 #[rust_name = "bounded_to"]
30 fn boundedTo(self: &QSize, other_size: &QSize) -> QSize;
31
32 #[rust_name = "expanded_to"]
34 fn expandedTo(self: &QSize, other_size: &QSize) -> QSize;
35
36 fn height(self: &QSize) -> i32;
38
39 #[rust_name = "is_empty"]
41 fn isEmpty(self: &QSize) -> bool;
42
43 #[rust_name = "is_null"]
45 fn isNull(self: &QSize) -> bool;
46
47 #[rust_name = "is_valid"]
49 fn isValid(self: &QSize) -> bool;
50
51 #[rust_name = "grown_by"]
53 fn grownBy(self: &QSize, margins: QMargins) -> QSize;
54
55 fn scale(self: &mut QSize, size: &QSize, mode: AspectRatioMode);
57
58 fn scaled(self: &QSize, s: &QSize, mode: AspectRatioMode) -> QSize;
60
61 #[rust_name = "set_height"]
63 fn setHeight(self: &mut QSize, height: i32);
64
65 #[rust_name = "set_width"]
67 fn setWidth(self: &mut QSize, width: i32);
68
69 #[rust_name = "shrunk_by"]
71 fn shrunkBy(self: &QSize, margins: QMargins) -> QSize;
72
73 #[cfg(any(cxxqt_qt_version_at_least_7, cxxqt_qt_version_at_least_6_4))]
76 #[rust_name = "to_sizef"]
77 fn toSizeF(self: &QSize) -> QSizeF;
78
79 fn transpose(self: &mut QSize);
81
82 fn transposed(self: &QSize) -> QSize;
84
85 fn width(self: &QSize) -> i32;
87 }
88
89 #[namespace = "rust::cxxqtlib1"]
90 unsafe extern "C++" {
91 include!("cxx-qt-lib/common.h");
92
93 #[doc(hidden)]
94 #[rust_name = "qsize_init_default"]
95 fn construct() -> QSize;
96 #[doc(hidden)]
97 #[rust_name = "qsize_init"]
98 fn construct(w: i32, h: i32) -> QSize;
99 #[doc(hidden)]
100 #[rust_name = "qsize_to_qstring"]
101 fn toQString(value: &QSize) -> QString;
102 #[doc(hidden)]
103 #[rust_name = "qsize_plus"]
104 fn operatorPlus(a: &QSize, b: &QSize) -> QSize;
105 #[doc(hidden)]
106 #[rust_name = "qsize_minus"]
107 fn operatorMinus(a: &QSize, b: &QSize) -> QSize;
108 #[doc(hidden)]
109 #[rust_name = "qsize_mul"]
110 fn operatorMul(a: f64, b: &QSize) -> QSize;
111 #[doc(hidden)]
112 #[rust_name = "qsize_div"]
113 fn operatorDiv(a: f64, b: &QSize) -> QSize;
114 }
115}
116
117#[derive(Debug, Clone, PartialEq, Eq)]
119#[repr(C)]
120pub struct QSize {
121 width: i32,
122 height: i32,
123}
124
125impl QSize {
126 pub fn new(width: i32, height: i32) -> Self {
128 ffi::qsize_init(width, height)
129 }
130}
131
132impl Default for QSize {
133 fn default() -> Self {
135 ffi::qsize_init_default()
136 }
137}
138
139impl fmt::Display for QSize {
140 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
141 write!(f, "{}", ffi::qsize_to_qstring(self))
142 }
143}
144
145impl std::ops::Add for QSize {
146 type Output = Self;
147 fn add(self, other: Self) -> Self {
148 ffi::qsize_plus(&self, &other)
149 }
150}
151
152impl std::ops::Sub for QSize {
153 type Output = Self;
154 fn sub(self, other: Self) -> Self {
155 ffi::qsize_minus(&self, &other)
156 }
157}
158
159impl std::ops::Mul<f64> for QSize {
160 type Output = Self;
161 fn mul(self, rhs: f64) -> Self {
162 ffi::qsize_mul(rhs, &self)
163 }
164}
165
166impl std::ops::Div<f64> for QSize {
167 type Output = Self;
168 fn div(self, rhs: f64) -> Self {
169 ffi::qsize_div(rhs, &self)
170 }
171}
172
173unsafe impl ExternType for QSize {
177 type Id = type_id!("QSize");
178 type Kind = cxx::kind::Trivial;
179}