GNOME Bugzilla – Bug 107597
GnomeColorPicker style button
Last modified: 2011-02-04 16:12:26 UTC
I took Federicos color picker found in libgnomeui and adapted it to the gtk coding style and interface conventions (e.g. use GdkColor for color arguments, not doubles, guint8s or guint16s). One thing that might be nice to add would be a way to make the swatch size somehow correspond to the font size or stock icon size or at least be settable.
Created attachment 14777 [details] gtkcolorpicker.h
Created attachment 14778 [details] gtkcolorpicker.c
I'd like to see "Button" in the name - GtkColorButton or GtkColorPickerButton or something like that. Maybe others have better ideas. As-is it's kind of hard to remember how this is different from GtkColorSelection. Agree that the swatch should scale - even if the size request never changes, it really needs to grow with the size allocation, GnomeColorPicker right now looks a little silly if you get allocation > request. I don't understand the "dither" property (don't know when you would use it) - maybe at least needs docs that suggest when to use it.
CCing Federico, maybe he remembers a use case for dithering. I'll look into renaming and making it scale.
Here is a simplified version. I decided to drop the dither property and renamed it to GtkColorPickerButton. Maybe GtkColorSelectionButton would be nicer, to go along with GtkColorSelection and GtkColorSelectionDialog. There is also a little testgtk addition to try it out.
Created attachment 14801 [details] gtkcolorpickerbutton.h
Created attachment 14802 [details] gtkcolorpickerbutton.c
Created attachment 14803 [details] [review] patch
Here are the latest versions; I decided to rename it to GtkColorSelectionButton.
Created attachment 15079 [details] gtkcolorselbutton.h
Created attachment 15080 [details] gtkcolorselbutton.c
Just noticed playing with gnome-terminal - GTK_WIN_POS_MOUSE must die ;-) gtk_window_set_position (GTK_WINDOW (priv->cs_dialog), GTK_WIN_POS_MOUSE); Adrian does have an interesting point; would it be better, in something like gnome-terminal, if clicking the button opened a little palette popup (like a combo), instead of the color dialog? The popup is fewer user steps for common tasks, assuming people usually want one of the preset colors, but more user steps if people usually want a custom color. don't know.
New version, incorporating feedback from Owen and Havoc: * shorter name: GtkColorButton * avoid double<->guint16 conversion * base widget size on font * replace deprecated GTK_TYPE boilerplate with G_TYPE boilerplate * only render in expose_event * remove unnecessary keypress handler * don't set GTK_WIN_POS_MOUSE * fix indentation Do we need gtk_color_button_set_use_palette() ?
Created attachment 15086 [details] gtkcolorbutton.h
Created attachment 15087 [details] gtkcolorbutton.c
Note that further cleanups would be possible by sharing the code to draw the color swatch with GtkColorSelection, which contains similar code for drawing the old/new color sample.
> Do we need gtk_color_button_set_use_palette() ? If we want to go the combo route, I'd think it would just be covered by Kris's combo widget, so we probably should not try to do that feature with this codebase. I guess my gut instinct is that we should have this and the combo both. I'm not sure if GtkColorCombo is something that would come with GTK, or just something that would be easy to do with the new combo widget. But the use cases for the two widgets seem a bit different, depending on whether you're likely to be picking the same color over and over for say different spreadsheet cells, or picking your favorite exact perfect color one time for your gnome-panel.
Created attachment 17892 [details] gtkcolorbutton.h
Created attachment 17893 [details] gtkcolorbutton.c
The new version has the following changes: - moved to instance private data - improved documentation - fixed a few bugs noticed while doing the above
2 requests 1) Can you supply a screenshot 2) I'm about to rework the colour combo/palette objects in gnumeric to support an alpha channel. Using GdkColors as the only interface will preclude support for that. You may want to revisit that choice.
There is really no need for a screenshot here. This thing looks exactly like the GnomeColorPicker currently found in libgnomeui... and it opens a regular GtkColorSelectionDialog. I guess you've seen those already. This widget is really different from a color combo like you want. A color combo like widget will probably arrive in gtk2.4 via the combobox work of Kristian... Regarding alpha support: There is gdk_color_button_[gs]et_alpha(), so alpha is fully supported. Admittedly, you have to get the RGB and A in two separate function calls.
Created attachment 17934 [details] gtkcolorbutton.h - taken into account comments on font picker
Created attachment 17935 [details] gtkcolorbutton.c - taken comments on font button into account
Committed.