Skip to content

Add display for qlinef/qline #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use crate::QPoint;
use cxx::{type_id, ExternType};
use std::fmt;

#[cxx::bridge]
mod ffi {
Expand All @@ -13,6 +14,8 @@ mod ffi {
type QLine = super::QLine;
include!("cxx-qt-lib/qpoint.h");
type QPoint = crate::QPoint;
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;

/// Returns the line's start point.
fn p1(self: &QLine) -> QPoint;
Expand Down Expand Up @@ -79,6 +82,10 @@ mod ffi {
#[doc(hidden)]
#[rust_name = "qline_new"]
fn construct(pt1: QPoint, pt2: QPoint) -> QLine;

#[doc(hidden)]
#[rust_name = "qline_to_qstring"]
fn toQString(value: &QLine) -> QString;
}
}

Expand All @@ -104,6 +111,12 @@ impl Default for QLine {
}
}

impl fmt::Display for QLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ffi::qline_to_qstring(self))
}
}

// Safety:
//
// Static checks on the C++ side ensure that QLine is trivial.
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/core/qlinef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::QLine;
use crate::QPointF;
use cxx::{type_id, ExternType};
use std::fmt;

#[cxx::bridge]
mod ffi {
Expand All @@ -16,6 +17,8 @@ mod ffi {
type QLine = crate::QLine;
include!("cxx-qt-lib/qpointf.h");
type QPointF = crate::QPointF;
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;

/// Returns the angle of the line in degrees.
fn angle(self: &QLineF) -> f64;
Expand Down Expand Up @@ -121,6 +124,10 @@ mod ffi {
#[doc(hidden)]
#[rust_name = "qlinef_from_qline"]
fn construct(line: &QLine) -> QLineF;

#[doc(hidden)]
#[rust_name = "qlinef_to_qstring"]
fn toQString(value: &QLineF) -> QString;
}
}

Expand Down Expand Up @@ -161,6 +168,12 @@ impl From<QLineF> for ffi::QLine {
}
}

impl fmt::Display for QLineF {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ffi::qlinef_to_qstring(self))
}
}

// Safety:
//
// Static checks on the C++ side ensure that QLineF is trivial.
Expand Down
13 changes: 13 additions & 0 deletions crates/cxx-qt-lib/src/gui/qpen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
// SPDX-License-Identifier: MIT OR Apache-2.0
use cxx::{type_id, ExternType};
use std::fmt;
use std::mem::MaybeUninit;

#[cxx::bridge]
Expand All @@ -20,6 +21,8 @@ mod ffi {
type QPen = super::QPen;
include!("cxx-qt-lib/qcolor.h");
type QColor = crate::QColor;
include!("cxx-qt-lib/qstring.h");
type QString = crate::QString;

/// Returns the pen's cap style.
#[rust_name = "cap_style"]
Expand Down Expand Up @@ -117,6 +120,10 @@ mod ffi {
#[doc(hidden)]
#[rust_name = "qpen_eq"]
fn operatorEq(a: &QPen, b: &QPen) -> bool;

#[doc(hidden)]
#[rust_name = "qpen_to_qstring"]
fn toQString(value: &QPen) -> QString;
}
}

Expand Down Expand Up @@ -167,6 +174,12 @@ impl From<&ffi::PenStyle> for QPen {
}
}

impl fmt::Display for QPen {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", ffi::qpen_to_qstring(self))
}
}

// Safety:
//
// Static checks on the C++ side to ensure the size is the same.
Expand Down