[sysprof] libsysprof-ui: fit-to-zoom and tooltips



commit 33c8e2fc267838ae5dc52864bebf2d7194046ce6
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 15 14:31:54 2019 -0700

    libsysprof-ui: fit-to-zoom and tooltips

 src/libsysprof-ui/sysprof-capture-view.c     | 35 +++++++++++++++++++++++++++-
 src/libsysprof-ui/sysprof-zoom-manager.c     |  4 ++--
 src/libsysprof-ui/ui/sysprof-capture-view.ui | 14 +++++++----
 3 files changed, 45 insertions(+), 8 deletions(-)
---
diff --git a/src/libsysprof-ui/sysprof-capture-view.c b/src/libsysprof-ui/sysprof-capture-view.c
index cab0406..d1e84ec 100644
--- a/src/libsysprof-ui/sysprof-capture-view.c
+++ b/src/libsysprof-ui/sysprof-capture-view.c
@@ -258,7 +258,7 @@ sysprof_capture_view_scan_worker (GTask        *task,
       if (begin_time < features.begin_time)
         features.begin_time = begin_time;
 
-      if (end_time < features.end_time)
+      if (end_time > features.end_time)
         features.end_time = end_time;
     }
 
@@ -506,6 +506,26 @@ sysprof_capture_view_selection_changed_cb (SysprofCaptureView *self,
   sysprof_capture_view_generate_callgraph_async (self, priv->reader, selection, NULL, NULL, NULL);
 }
 
+static void
+fit_zoom_cb (GSimpleAction *action,
+             GVariant      *param,
+             gpointer       user_data)
+{
+  SysprofCaptureView *self = user_data;
+  SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self);
+  GtkAllocation alloc;
+  gdouble zoom;
+  gint64 duration;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (SYSPROF_IS_CAPTURE_VIEW (self));
+
+  duration = priv->features.end_time - priv->features.begin_time;
+  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
+  zoom = sysprof_zoom_manager_fit_zoom_for_duration (priv->zoom_manager, duration, alloc.width);
+  sysprof_zoom_manager_set_zoom (priv->zoom_manager, zoom);
+}
+
 static void
 sysprof_capture_view_finalize (GObject *object)
 {
@@ -583,7 +603,11 @@ static void
 sysprof_capture_view_init (SysprofCaptureView *self)
 {
   SysprofCaptureViewPrivate *priv = sysprof_capture_view_get_instance_private (self);
+  g_autoptr(GSimpleActionGroup) group = NULL;
   SysprofSelection *selection;
+  static GActionEntry actions[] = {
+    { "fit-zoom", fit_zoom_cb },
+  };
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -597,6 +621,15 @@ sysprof_capture_view_init (SysprofCaptureView *self)
   gtk_widget_insert_action_group (GTK_WIDGET (self),
                                   "zoom",
                                   G_ACTION_GROUP (priv->zoom_manager));
+
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group),
+                                   actions,
+                                   G_N_ELEMENTS (actions),
+                                   self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self),
+                                  "capture-view",
+                                  G_ACTION_GROUP (group));
 }
 
 /**
diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c
index 41a74fe..e8f97ef 100644
--- a/src/libsysprof-ui/sysprof-zoom-manager.c
+++ b/src/libsysprof-ui/sysprof-zoom-manager.c
@@ -523,7 +523,7 @@ sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self,
 {
   g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 1.0);
   g_return_val_if_fail (duration >= 0, 1.0);
+  g_return_val_if_fail (width >= 0, 1.0);
 
-  return ((gdouble)width / DEFAULT_PIXELS_PER_SEC) /
-         ((gdouble)duration / (gdouble)NSEC_PER_SEC);
+  return (width / DEFAULT_PIXELS_PER_SEC) / (duration / (gdouble)NSEC_PER_SEC);
 }
diff --git a/src/libsysprof-ui/ui/sysprof-capture-view.ui b/src/libsysprof-ui/ui/sysprof-capture-view.ui
index 06e23f0..8c1cc08 100644
--- a/src/libsysprof-ui/ui/sysprof-capture-view.ui
+++ b/src/libsysprof-ui/ui/sysprof-capture-view.ui
@@ -24,6 +24,7 @@
                     <property name="action-name">zoom.zoom-out</property>
                     <property name="focus-on-click">false</property>
                     <property name="visible">true</property>
+                    <property name="tooltip-text" translatable="yes">Zoom Out</property>
                     <child>
                       <object class="GtkImage">
                         <property name="icon-name">zoom-out-symbolic</property>
@@ -34,16 +35,18 @@
                 </child>
                 <child>
                   <object class="GtkButton">
-                    <property name="action-name">zoom.zoom-one</property>
+                    <property name="action-name">capture-view.fit-zoom</property>
                     <property name="focus-on-click">false</property>
+                    <property name="tooltip-text" translatable="yes">Resize to Fit</property>
                     <property name="visible">true</property>
                     <style>
-                      <class name="text-label"/>
+                      <class name="image-button"/>
                     </style>
                     <child>
-                      <object class="GtkLabel">
-                        <property name="label" bind-source="zoom_manager" bind-property="zoom-label" 
bind-flags="sync-create"/>
-                        <property name="width-chars">5</property>
+                      <object class="GtkImage">
+                        <property name="margin-start">12</property>
+                        <property name="margin-end">12</property>
+                        <property name="icon-name">zoom-fit-best-symbolic</property>
                         <property name="visible">true</property>
                       </object>
                     </child>
@@ -53,6 +56,7 @@
                   <object class="GtkButton">
                     <property name="action-name">zoom.zoom-in</property>
                     <property name="focus-on-click">false</property>
+                    <property name="tooltip-text" translatable="yes">Zoom In</property>
                     <property name="visible">true</property>
                     <child>
                       <object class="GtkImage">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]