[nautilus/wip/ernestask/gtk4-continued] properties-window: Fix usage chart
- From: Ernestas Kulik <ernestask src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/ernestask/gtk4-continued] properties-window: Fix usage chart
- Date: Sat, 28 Jul 2018 10:14:02 +0000 (UTC)
commit 8ef141b67df725e67cc90c17ea046d4729a4860e
Author: Ernestas Kulik <ernestask gnome org>
Date: Sat Jul 28 13:10:17 2018 +0300
properties-window: Fix usage chart
Until now, the usage pie chart was drawing by connecting to ::draw of
the GtkDrawingArea, which has since been obsoleted. Luckily to us, one
can very easily just set the draw function of the drawing area. This
commit does just that and fixes styling issues by moving out class
addition to just before drawing (2 px solid borders were being applied
to the entire drawing area, which wasn’t an intended look).
src/nautilus-properties-window.c | 59 ++++++++++++++++++++++------------------
1 file changed, 32 insertions(+), 27 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 6bbeceaf1..2df8d814f 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -2799,18 +2799,25 @@ should_show_volume_usage (NautilusPropertiesWindow *window)
}
static void
-paint_legend (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
+paint_legend (GtkDrawingArea *drawing_area,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer data)
{
+ GtkWidget *widget;
GtkStyleContext *context;
- GtkAllocation allocation;
- gtk_widget_get_allocation (widget, &allocation);
+ widget = GTK_WIDGET (drawing_area);
context = gtk_widget_get_style_context (widget);
- gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height);
- gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height);
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "disk-space-display");
+
+ gtk_render_background (context, cr, 0, 0, width, height);
+ gtk_render_frame (context, cr, 0, 0, width, height);
+
+ gtk_style_context_restore (context);
}
static void
@@ -2837,9 +2844,10 @@ paint_slice (GtkWidget *widget,
}
context = gtk_widget_get_style_context (widget);
- gtk_style_context_get_border (context, &border);
gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "disk-space-display");
+ gtk_style_context_get_border (context, &border);
gtk_style_context_add_class (context, style_class);
gtk_style_context_get_color (context, &fill);
gtk_style_context_add_class (context, "border");
@@ -2885,26 +2893,26 @@ paint_slice (GtkWidget *widget,
}
static void
-paint_pie_chart (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
+paint_pie_chart (GtkDrawingArea *drawing_area,
+ cairo_t *cr,
+ int width,
+ int height,
+ gpointer data)
{
NautilusPropertiesWindow *window;
+ GtkWidget *widget;
double free, used, reserved;
window = NAUTILUS_PROPERTIES_WINDOW (data);
-
+ widget = GTK_WIDGET (drawing_area);
free = (double) window->volume_free / (double) window->volume_capacity;
used = (double) window->volume_used / (double) window->volume_capacity;
reserved = 1.0 - (used + free);
- paint_slice (widget, cr,
- 0, free, "free");
- paint_slice (widget, cr,
- free + used, reserved, "unknown");
+ paint_slice (widget, cr, 0, free, "free");
+ paint_slice (widget, cr, free + used, reserved, "unknown");
/* paint the used last so its slice strokes are on top */
- paint_slice (widget, cr,
- free, used, "used");
+ paint_slice (widget, cr, free, used, "used");
}
static GtkWidget *
@@ -2950,12 +2958,10 @@ create_pie_widget (NautilusPropertiesWindow *window)
pie_canvas = gtk_drawing_area_new ();
gtk_widget_set_size_request (pie_canvas, 200, 200);
style = gtk_widget_get_style_context (pie_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
used_canvas = gtk_drawing_area_new ();
gtk_widget_set_size_request (used_canvas, 20, 20);
style = gtk_widget_get_style_context (used_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
gtk_style_context_add_class (style, "used");
used_label = gtk_label_new (used);
@@ -2965,7 +2971,6 @@ create_pie_widget (NautilusPropertiesWindow *window)
free_canvas = gtk_drawing_area_new ();
gtk_widget_set_size_request (free_canvas, 20, 20);
style = gtk_widget_get_style_context (free_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
gtk_style_context_add_class (style, "free");
free_label = gtk_label_new (free);
@@ -3052,12 +3057,12 @@ create_pie_widget (NautilusPropertiesWindow *window)
gtk_grid_attach_next_to (grid, fstype_value_label, fstype_label,
GTK_POS_RIGHT, 1, 1);
- g_signal_connect (pie_canvas, "draw",
- G_CALLBACK (paint_pie_chart), window);
- g_signal_connect (used_canvas, "draw",
- G_CALLBACK (paint_legend), window);
- g_signal_connect (free_canvas, "draw",
- G_CALLBACK (paint_legend), window);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (pie_canvas),
+ paint_pie_chart, window, NULL);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (used_canvas),
+ paint_legend, NULL, NULL);
+ gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (free_canvas),
+ paint_legend, NULL, NULL);
return GTK_WIDGET (grid);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]