Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

cairo_interaction::set_source_rgba() is not public #135

Closed
Susurrus opened this issue Feb 21, 2017 · 5 comments
Closed

cairo_interaction::set_source_rgba() is not public #135

Susurrus opened this issue Feb 21, 2017 · 5 comments

Comments

@Susurrus
Copy link
Contributor

Susurrus commented Feb 21, 2017

This applies to a lof of the functions in that file. I've been trying to copy some C code and it's converted basically to the following Rust example:

let icon = gtk::DrawingArea::new();
icon.connect_draw(|w, c| {
    let style_context = w.get_style_context().unwrap();
    let foreground = style_context.get_color(w.get_state_flags());
    c.set_source_rgba (&foreground);
});

Unfortunately this doesn't compile because of both the missing get_color() (tracked in gtk-rs/gtk#454), but also because the equivalent of gdk_cairo_set_source_rgba() isn't available. It's implemented in gdk::cairo_interaction and I would think it'd be usable since the c argument to the closure is a cairo::Context. Is there something I'm missing here?

I should note that if you call c.get_clip_rectangle() within the callback it will compile successfully, so I'm wondering if there's a compiler bug that is allowing Context to have two set_source_rgba functions implemented on it and silently ignores the duplicate one?

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 7, 2017

@EPashkin I mentioned this in my PR for the RGBA stuff, but I figured I'd break it out as a separate issue. Any idea what's going on here?

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 7, 2017

Indeed, this looks to be a compiler bug. If I rename ContextExt::set_source_rgba to set_source_rgba2, then I can use that function in the connect_draw closure.

So here's the question, how do we want to resolve this? We have two functions, gdk_cairo_set_source_rgba and cairo_set_source_rgba. Is there a convention for how to handle duplicate function names within the gtk-rs namespace?

Pinging both @EPashkin and @GuillaumeGomez because I don't know how this should be resolved.

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 7, 2017

Looks like I was wrong, sorry about the noise! Just talked to some people on IRC and the proper way to use these functions is the do <Context as ContextExt>::set_source_rgba(&c, &foreground); where use cairo::Context; and use gdk::prelude::*; where used to bring both the struct and trait into scope.

So closing this.

@Susurrus Susurrus closed this as completed Mar 7, 2017
@EPashkin
Copy link
Member

EPashkin commented Mar 7, 2017

IMHO ContextExt::set_source_rgba(&c, &foreground) will work too

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 7, 2017

The compiler complained about the types and using the explicit syntax fixed it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants