From 56221afaf882a7ec673b32b059a86eafa29c3bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Wed, 1 Mar 2023 13:33:56 +0100 Subject: [PATCH] Implement std::ops for QRectF --- crates/cxx-qt-lib/src/core/qrectf.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/cxx-qt-lib/src/core/qrectf.rs b/crates/cxx-qt-lib/src/core/qrectf.rs index 0a3cb5e51..98e38f168 100644 --- a/crates/cxx-qt-lib/src/core/qrectf.rs +++ b/crates/cxx-qt-lib/src/core/qrectf.rs @@ -11,9 +11,11 @@ mod ffi { unsafe extern "C++" { include!("cxx-qt-lib/qrectf.h"); include!("cxx-qt-lib/qstring.h"); + include!("cxx-qt-lib/qmarginsf.h"); type QRectF = super::QRectF; type QString = crate::QString; + type QMarginsF = crate::QMarginsF; /// Returns the height of the rectangle. fn height(self: &QRectF) -> f64; @@ -51,6 +53,12 @@ mod ffi { #[doc(hidden)] #[rust_name = "qrectf_to_qstring"] fn toQString(value: &QRectF) -> QString; + #[doc(hidden)] + #[rust_name = "qrectf_plus"] + fn operatorPlus(a: &QRectF, b: &QMarginsF) -> QRectF; + #[doc(hidden)] + #[rust_name = "qrectf_minus"] + fn operatorMinus(a: &QRectF, b: &QMarginsF) -> QRectF; } } @@ -84,6 +92,21 @@ impl fmt::Display for QRectF { } } +type QMarginsF = crate::QMarginsF; +impl std::ops::Add for QRectF { + type Output = Self; + fn add(self, other: QMarginsF) -> Self { + ffi::qrectf_plus(&self, &other) + } +} + +impl std::ops::Sub for QRectF { + type Output = Self; + fn sub(self, other: QMarginsF) -> Self { + ffi::qrectf_minus(&self, &other) + } +} + // Safety: // // Static checks on the C++ side ensure that QRectF is trivial.