Skip to content

Implement Display in qpen #93

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
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/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