Skip to content
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

gdk: Rename GdkCairoContextExt::set_source_{rgba => color} #1476

Merged
merged 3 commits into from
Aug 22, 2023
Merged
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
2 changes: 1 addition & 1 deletion examples/flow_box/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn create_color_button(color: &'static str) -> gtk::Button {

let rgba = gdk::RGBA::from_str(color).unwrap();
drawing_area.set_draw_func(move |_, cr, _width, _height| {
GdkCairoContextExt::set_source_rgba(cr, &rgba);
cr.set_source_color(&rgba);
cr.paint().expect("Invalid cairo surface state");
});
button.set_child(Some(&drawing_area));
Expand Down
2 changes: 1 addition & 1 deletion gdk4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[dependencies]
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19"}
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["use_glib"]}
RealKC marked this conversation as resolved.
Show resolved Hide resolved
ffi = {package = "gdk4-sys", path = "./sys", version = "0.8"}
gdk-pixbuf = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19"}
gio = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["v2_66"]}
Expand Down
61 changes: 28 additions & 33 deletions gdk4/src/cairo_interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +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")]
fn set_source_rgba(&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 @@ -71,7 +45,7 @@ impl GdkCairoContextExt for Context {
) {
skip_assert_initialized!();
ffi::gdk_cairo_draw_from_gl(
mut_override(self.to_glib_none().0),
self.to_raw(),
surface.to_glib_none().0,
source,
source_type,
Expand All @@ -83,27 +57,48 @@ impl GdkCairoContextExt for Context {
);
}

fn set_source_rgba(&self, rgba: &RGBA) {
#[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);
ffi::gdk_cairo_set_source_rgba(self.to_raw(), rgba.to_glib_none().0);
}
}

#[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);
ffi::gdk_cairo_set_source_pixbuf(self.to_raw(), pixbuf.to_glib_none().0, x, y);
}
}

#[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);
ffi::gdk_cairo_rectangle(self.to_raw(), rectangle.to_glib_none().0);
}
}

#[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);
ffi::gdk_cairo_region(self.to_raw(), region.to_glib_none().0);
}
}
}

impl GdkCairoContextExt for Context {}

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

pub trait Sealed {
RealKC marked this conversation as resolved.
Show resolved Hide resolved
fn to_raw(&self) -> *mut cairo_t;
}

impl Sealed for Context {
fn to_raw(&self) -> *mut cairo_t {
self.to_raw_none()
}
}
}
2 changes: 1 addition & 1 deletion gsk4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[dependencies]
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19"}
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["use_glib"]}
ffi = {package = "gsk4-sys", path = "./sys", version = "0.8"}
gdk = {package = "gdk4", path = "../gdk4", version = "0.8"}
glib = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["v2_66"]}
Expand Down
2 changes: 1 addition & 1 deletion gtk4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]

[dependencies]
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19"}
cairo-rs = {git = "https://github.com/gtk-rs/gtk-rs-core", version = "0.19", features = ["use_glib"]}
ffi = {package = "gtk4-sys", path = "./sys", version = "0.8"}
field-offset = "0.3"
futures-channel = "0.3"
Expand Down
Loading