diff options
author | Benjamin Otte <otte@redhat.com> | 2014-10-03 06:45:38 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2014-10-03 06:45:38 +0200 |
commit | 23a4affb6f158275cdd5e8e824240f6a5c4190a9 (patch) | |
tree | 684fcce978bd62fbb1adc702bad0f0728ace31e3 /demos/gtk-demo/flowbox.c | |
parent | 40e09737090b1437474bb479709b95c79c45d4ac (diff) | |
download | gtk+-23a4affb6f158275cdd5e8e824240f6a5c4190a9.tar.gz |
gtk-demo: Improve flowbox demo code
Overriding the background color for a color swatch is wrong. The color
is not the background, it's the foreground, so it should be painted in
a draw signal handler.
Diffstat (limited to 'demos/gtk-demo/flowbox.c')
-rw-r--r-- | demos/gtk-demo/flowbox.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/demos/gtk-demo/flowbox.c b/demos/gtk-demo/flowbox.c index c0d921735d..38ce3c06b0 100644 --- a/demos/gtk-demo/flowbox.c +++ b/demos/gtk-demo/flowbox.c @@ -12,18 +12,31 @@ static GtkWidget *window = NULL; +static gboolean +draw_color (GtkWidget *drawingarea, + cairo_t *cr, + const char *color_name) +{ + GdkRGBA rgba; + + if (gdk_rgba_parse (&rgba, color_name)) + { + gdk_cairo_set_source_rgba (cr, &rgba); + cairo_paint (cr); + } + + return FALSE; +} + static GtkWidget * color_swatch_new (const gchar *color) { GtkWidget *button, *area; - GdkRGBA rgba; - - gdk_rgba_parse (&rgba, color); button = gtk_button_new (); area = gtk_drawing_area_new (); + g_signal_connect (area, "draw", G_CALLBACK (draw_color), (gpointer) color); gtk_widget_set_size_request (area, 24, 24); - gtk_widget_override_background_color (area, 0, &rgba); gtk_container_add (GTK_CONTAINER (button), area); gtk_widget_show_all (button); |