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

Implement StyleContext::{get_color, lookup_color} #462

Merged
merged 2 commits into from
Mar 11, 2017

Conversation

Susurrus
Copy link
Contributor

@Susurrus Susurrus commented Mar 6, 2017

This is done manually because the RGBA struct isn't generally usable by gir yet.

Closes #454.

@EPashkin
Copy link
Member

EPashkin commented Mar 6, 2017

Comment about closing must go to first comment to work.

@@ -55,9 +50,11 @@ impl<O: IsA<ColorChooser>> ColorChooserExt for O {
}
}

fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: Vec<GdkRGBA>) {
fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: Vec<RGBA>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colors: &[RGBA] and as_mut_ptr IMHO won't work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need something like to_glib_none().0, but its work also need "tested"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or collecting to Vec<ffi::GdkRGBA> and pass pointer to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow, are you saying that the colors argument should not be Vec<RGBA> or are you saying my conversion from Vec<RGBA> to *mut gdk_ffi::GdkRGBA is wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need colors: &[RGBA] and body changed back

@EPashkin
Copy link
Member

EPashkin commented Mar 8, 2017

I add few comments to reminder, it mainly for case when gtk-rs/gdk#140 selected to merge.

unsafe { ffi::gtk_color_chooser_get_rgba(self.to_glib_none().0, &mut color) };
fn get_rgba(&self) -> RGBA {
let mut color = unsafe { RGBA::uninitialized() };
unsafe { ffi::gtk_color_chooser_get_rgba(self.to_glib_none().0, color.to_glib_none_mut().0) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single unsafe block

color
}

fn set_rgba(&self, color: GdkRGBA) {
unsafe { ffi::gtk_color_chooser_set_rgba(self.to_glib_none().0, &color) };
fn set_rgba(&self, color: RGBA) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to color: &RGBA to complement with record usage

}
}

pub fn lookup_color(&self, color_name: &str) -> Option<gdk::RGBA> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See gtk-rs/gdk#140 (comment) with changing local variable name to color to be equivalent generated version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

color_name is actually what's used in the GTK docs which is why I used it: https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-lookup-color

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 8, 2017

@EPashkin Just pushed new commits that should resolve all your comments.

@@ -55,9 +52,13 @@ impl<O: IsA<ColorChooser>> ColorChooserExt for O {
}
}

fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: Vec<GdkRGBA>) {
fn add_palette(&self, orientation: Orientation, colors_per_line: i32, colors: &mut [RGBA]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No &mut just &

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be mut for the as_mut_ptr call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, looks like that should have been an as_ptr() call, in which case you're correct.

@EPashkin
Copy link
Member

EPashkin commented Mar 8, 2017

@Susurrus Sorry, but after RGBA have glib::Value support you need use generated code for it.
So manual style_context.rs no longer needed.

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 8, 2017

@EPashkin Yeah, that makes more sense! Cool, that enables a bunch more functions too, including one that was already manually implemented, so that's nice. Hopefully this is now correct.

unsafe {
let mut rgba = mem::uninitialized();
ffi::gtk_color_button_get_rgba(self.to_glib_none().0, &mut rgba);
unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and set_rgba also not needed as it implemented by ColorChooserExt
I don't know why rust now don't nags about multiple cases even on use.

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 8, 2017

I've removed the set_rgba and get_rgba functions as you asked.

Also, with the addition of the RGBA type, the auto-generated code now includes StyleContext::GetBackgroundColor and StyleContext::GetBorderColor, both of which are deprecated as of 3.16. Should I disable their autogeneration or leave them?

@EPashkin
Copy link
Member

EPashkin commented Mar 8, 2017

Thanks.
Ignoring not needed.
We ignore only functions, that deprecated by v3.4.
It controlled by Gir.toml parameters min_cfg_version and deprecate_by_min_version

@Susurrus
Copy link
Contributor Author

Susurrus commented Mar 8, 2017

Okay, so I don't need to do anything about those two functions then?

@EPashkin
Copy link
Member

EPashkin commented Mar 8, 2017

Yes, this functions stays as is, deprecation will noted on docs as for http://gtk-rs.org/docs/gtk/prelude/trait.WidgetExt.html#tymethod.drag_source_set_icon_stock

@EPashkin
Copy link
Member

@GuillaumeGomez Maybe merge this before PR's related to gtk-rs/examples#112 ?

@GuillaumeGomez
Copy link
Member

And another one I forgot... Thanks @EPashkin for the reminder and thanks a lot @Susurrus for the PR!

@GuillaumeGomez GuillaumeGomez merged commit 974759d into gtk-rs:master Mar 11, 2017
@Susurrus
Copy link
Contributor Author

Awesome, thanks for helping through implementing this @GuillaumeGomez and @EPashkin!

alex179ohm pushed a commit to alex179ohm/gtk that referenced this pull request Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants