From 23a4affb6f158275cdd5e8e824240f6a5c4190a9 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 3 Oct 2014 06:45:38 +0200 Subject: [PATCH] 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. --- demos/gtk-demo/flowbox.c | 21 +++++++++++++++++---- 1 file 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);