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