Skip to content

Commit

Permalink
Implement std::ops for QMargins
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 37e6e8f commit 918628c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions crates/cxx-qt-lib/src/core/qrect.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/qrect.h");
include!("cxx-qt-lib/qstring.h");
include!("cxx-qt-lib/qmargins.h");

type QRect = super::QRect;
type QString = crate::QString;
type QMargins = crate::QMargins;

/// Returns the height of the rectangle.
fn height(self: &QRect) -> i32;
Expand Down Expand Up @@ -51,6 +53,12 @@ mod ffi {
#[doc(hidden)]
#[rust_name = "qrect_to_qstring"]
fn toQString(value: &QRect) -> QString;
#[doc(hidden)]
#[rust_name = "qrect_plus"]
fn operatorPlus(a: &QRect, b: &QMargins) -> QRect;
#[doc(hidden)]
#[rust_name = "qrect_minus"]
fn operatorMinus(a: &QRect, b: &QMargins) -> QRect;
}
}

Expand Down Expand Up @@ -85,6 +93,21 @@ impl fmt::Display for QRect {
}
}

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

impl std::ops::Sub<QMargins> for QRect {
type Output = Self;
fn sub(self, other: QMargins) -> Self {
ffi::qrect_minus(&self, &other)
}
}

// Safety:
//
// Static checks on the C++ side ensure that QRect is trivial.
Expand Down

0 comments on commit 918628c

Please sign in to comment.