Skip to content

Commit

Permalink
Implement std::ops for QRectF
Browse files Browse the repository at this point in the history
  • Loading branch information
vimpostor authored and ahayzen-kdab committed Mar 1, 2023
1 parent 918628c commit 56221af
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/cxx-qt-lib/src/core/qrectf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -84,6 +92,21 @@ impl fmt::Display for QRectF {
}
}

type QMarginsF = crate::QMarginsF;
impl std::ops::Add<QMarginsF> for QRectF {
type Output = Self;
fn add(self, other: QMarginsF) -> Self {
ffi::qrectf_plus(&self, &other)
}
}

impl std::ops::Sub<QMarginsF> 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.
Expand Down

0 comments on commit 56221af

Please sign in to comment.