Skip to content

Commit

Permalink
gdk: Seal GdkCairoContextExt and move method impls within trait defin…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
RealKC committed Aug 22, 2023
1 parent 2a56564 commit 3668cc1
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions gdk4/src/cairo_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,14 @@ impl GdkCairoSurfaceExt for cairo::Surface {

// rustdoc-stripper-ignore-next
/// Trait containing integration methods with [`cairo::Context`].
pub trait GdkCairoContextExt {
pub trait GdkCairoContextExt: sealed::Sealed {
// rustdoc-stripper-ignore-next
/// # Safety
///
/// It's the responsibility of the caller to ensure that source
/// is a valid GL resource.
#[doc(alias = "gdk_cairo_draw_from_gl")]
#[allow(clippy::too_many_arguments)]
unsafe fn draw_from_gl(
&self,
surface: &Surface,
source: i32,
source_type: i32,
buffer_scale: i32,
x: i32,
y: i32,
width: i32,
height: i32,
);

#[doc(alias = "gdk_cairo_set_source_rgba")]
#[doc(alias = "set_source_rgba")]
fn set_source_color(&self, rgba: &RGBA);

#[doc(alias = "gdk_cairo_set_source_pixbuf")]
fn set_source_pixbuf(&self, pixbuf: &Pixbuf, x: f64, y: f64);

#[doc(alias = "gdk_cairo_rectangle")]
fn add_rectangle(&self, rectangle: &Rectangle);

#[doc(alias = "gdk_cairo_region")]
fn add_region(&self, region: &Region);
}

impl GdkCairoContextExt for Context {
unsafe fn draw_from_gl(
&self,
surface: &Surface,
Expand All @@ -72,7 +45,7 @@ impl GdkCairoContextExt for Context {
) {
skip_assert_initialized!();
ffi::gdk_cairo_draw_from_gl(
mut_override(self.to_glib_none().0),
mut_override(self.into_glib()),
surface.to_glib_none().0,
source,
source_type,
Expand All @@ -84,27 +57,48 @@ impl GdkCairoContextExt for Context {
);
}

#[doc(alias = "gdk_cairo_set_source_rgba")]
#[doc(alias = "set_source_rgba")]
fn set_source_color(&self, rgba: &RGBA) {
unsafe {
ffi::gdk_cairo_set_source_rgba(self.to_glib_none().0, rgba.to_glib_none().0);

Check failure on line 64 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / macOS

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied

Check failure on line 64 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied
}
}

#[doc(alias = "gdk_cairo_set_source_pixbuf")]
fn set_source_pixbuf(&self, pixbuf: &Pixbuf, x: f64, y: f64) {
unsafe {
ffi::gdk_cairo_set_source_pixbuf(self.to_glib_none().0, pixbuf.to_glib_none().0, x, y);

Check failure on line 71 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / macOS

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied

Check failure on line 71 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied
}
}

#[doc(alias = "gdk_cairo_rectangle")]
fn add_rectangle(&self, rectangle: &Rectangle) {
unsafe {
ffi::gdk_cairo_rectangle(self.to_glib_none().0, rectangle.to_glib_none().0);

Check failure on line 78 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / macOS

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied

Check failure on line 78 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied
}
}

#[doc(alias = "gdk_cairo_region")]
fn add_region(&self, region: &Region) {
unsafe {
ffi::gdk_cairo_region(self.to_glib_none().0, region.to_glib_none().0);

Check failure on line 85 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / macOS

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied

Check failure on line 85 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

the method `to_glib_none` exists for reference `&Self`, but its trait bounds were not satisfied
}
}
}

impl GdkCairoContextExt for Context {}

mod sealed {
use cairo::{ffi::cairo_t, Context};

pub trait Sealed {
fn into_glib(&self) -> *mut cairo_t;
}

impl Sealed for Context {
fn into_glib(&self) -> *mut cairo_t {
self.into_glib_none().0

Check failure on line 101 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / macOS

no method named `into_glib_none` found for reference `&cairo::Context` in the current scope

Check failure on line 101 in gdk4/src/cairo_interaction.rs

View workflow job for this annotation

GitHub Actions / Windows MSVC

no method named `into_glib_none` found for reference `&cairo::Context` in the current scope
}
}
}

0 comments on commit 3668cc1

Please sign in to comment.