window: update zoom reset label to display current zoom

This commit is contained in:
Christian Hergert
2016-09-28 18:06:33 -07:00
parent baf26fa0b6
commit 60e917a5d1
2 changed files with 26 additions and 1 deletions

View File

@ -215,6 +215,7 @@
<property name="visible">true</property>
<child>
<object class="GtkBox">
<property name="hexpand">true</property>
<property name="orientation">horizontal</property>
<property name="margin-bottom">12</property>
<property name="visible">true</property>
@ -240,8 +241,13 @@
<child>
<object class="GtkButton">
<property name="action-name">zoom.zoom-one</property>
<property name="label" translatable="yes">100%</property>
<property name="visible">true</property>
<child>
<object class="GtkLabel" id="zoom_one_label">
<property name="width-chars">5</property>
<property name="visible">true</property>
</object>
</child>
</object>
</child>
<child>

View File

@ -18,6 +18,7 @@
#include <errno.h>
#include <glib/gi18n.h>
#include <math.h>
#include <sysprof.h>
#include <sysprof-ui.h>
@ -52,6 +53,7 @@ struct _SpWindow
GtkStack *view_stack;
SpVisualizerView *visualizers;
SpZoomManager *zoom_manager;
GtkLabel *zoom_one_label;
guint stats_handler;
@ -715,6 +717,17 @@ sp_window_reset_paned (SpWindow *self)
gtk_paned_set_position (self->paned, MAX (min_height, MIN (nat_height, 300)));
}
static gboolean
zoom_level_to_string (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data)
{
gdouble percent = 100.0 * g_value_get_double (from_value);
g_value_take_string (to_value, g_strdup_printf ("%u%%", (guint)ceil (percent)));
return TRUE;
}
static void
sp_window_destroy (GtkWidget *widget)
{
@ -786,6 +799,8 @@ sp_window_class_init (SpWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, SpWindow, title);
gtk_widget_class_bind_template_child (widget_class, SpWindow, view_stack);
gtk_widget_class_bind_template_child (widget_class, SpWindow, visualizers);
gtk_widget_class_bind_template_child (widget_class, SpWindow, zoom_manager);
gtk_widget_class_bind_template_child (widget_class, SpWindow, zoom_one_label);
}
static void
@ -834,6 +849,10 @@ sp_window_init (SpWindow *self)
self,
G_CONNECT_SWAPPED);
g_object_bind_property_full (self->zoom_manager, "zoom", self->zoom_one_label, "label",
G_BINDING_SYNC_CREATE,
zoom_level_to_string, NULL, NULL, NULL);
/*
* Setup actions for the window.
*/