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.
This commit is contained in:
Benjamin Otte 2014-10-03 06:45:38 +02:00
parent 40e0973709
commit 23a4affb6f

View File

@ -12,18 +12,31 @@
static GtkWidget *window = NULL; 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 * static GtkWidget *
color_swatch_new (const gchar *color) color_swatch_new (const gchar *color)
{ {
GtkWidget *button, *area; GtkWidget *button, *area;
GdkRGBA rgba;
gdk_rgba_parse (&rgba, color);
button = gtk_button_new (); button = gtk_button_new ();
area = gtk_drawing_area_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_set_size_request (area, 24, 24);
gtk_widget_override_background_color (area, 0, &rgba);
gtk_container_add (GTK_CONTAINER (button), area); gtk_container_add (GTK_CONTAINER (button), area);
gtk_widget_show_all (button); gtk_widget_show_all (button);