[sysprof] libsysprof-ui: add label helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] libsysprof-ui: add label helper
- Date: Wed, 29 May 2019 22:26:24 +0000 (UTC)
commit 0b4510c0278509e5b45849004663c7b0d1b5e724
Author: Christian Hergert <chergert redhat com>
Date: Mon May 13 22:18:59 2019 -0700
libsysprof-ui: add label helper
src/libsysprof-ui/sysprof-zoom-manager.c | 33 ++++++++++++++++++++++++++++++++
src/libsysprof-ui/sysprof-zoom-manager.h | 2 ++
2 files changed, 35 insertions(+)
---
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c
index 11e5b17..b54146b 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.c
+++ b/src/libsysprof-ui/sysprof-zoom-manager.c
@@ -129,6 +129,10 @@ sysprof_zoom_manager_get_property (GObject *object,
g_value_set_double (value, sysprof_zoom_manager_get_zoom (self));
break;
+ case PROP_ZOOM_LABEL:
+ g_value_take_string (value, sysprof_zoom_manager_get_zoom_label (self));
+ break;
+
case PROP_CAN_ZOOM_IN:
g_value_set_boolean (value, sysprof_zoom_manager_get_can_zoom_in (self));
break;
@@ -218,6 +222,11 @@ sysprof_zoom_manager_class_init (SysprofZoomManagerClass *klass)
1.0,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ properties [PROP_ZOOM_LABEL] =
+ g_param_spec_string ("zoom-label", NULL, NULL,
+ NULL,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, N_PROPS, properties);
}
@@ -407,6 +416,7 @@ sysprof_zoom_manager_set_zoom (SysprofZoomManager *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_IN]);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_OUT]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_LABEL]);
}
}
@@ -477,3 +487,26 @@ action_group_iface_init (GActionGroupInterface *iface)
iface->change_action_state = sysprof_zoom_manager_change_action_state;
iface->activate_action = sysprof_zoom_manager_activate_action;
}
+
+/**
+ * sysprof_zoom_manager_get_zoom_level:
+ * @self: a #SysprofZoomManager
+ *
+ * Returns: (transfer full): a string containing the zoom percentage label
+ *
+ * Since: 3.34
+ */
+gchar *
+sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self)
+{
+ gdouble percent;
+
+ g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), NULL);
+
+ percent = self->zoom * 100.0;
+
+ if (percent < 1.0)
+ return g_strdup_printf ("%0.2lf%%", percent);
+ else
+ return g_strdup_printf ("%d%%", (gint)percent);
+}
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.h b/src/libsysprof-ui/sysprof-zoom-manager.h
index a67bc51..62aa45e 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.h
+++ b/src/libsysprof-ui/sysprof-zoom-manager.h
@@ -62,5 +62,7 @@ gdouble sysprof_zoom_manager_get_zoom (SysprofZoomManager *s
SYSPROF_AVAILABLE_IN_ALL
void sysprof_zoom_manager_set_zoom (SysprofZoomManager *self,
gdouble zoom);
+SYSPROF_AVAILABLE_IN_ALL
+gchar *sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]