[sysprof] libsysprof-ui: simplify sizing of positioning in visualizers



commit 2d69a5ff1c5473d4496f32b880b3064ef807b128
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 1 00:18:06 2019 -0700

    libsysprof-ui: simplify sizing of positioning in visualizers
    
    This simplifies the visualizer sizing by avoiding the expanding sizes
    when there is more space available. Doing so allows us to treat all the
    sizing uniformly.
    
    We can also make the ticks area a visualizer for more code re-use.

 src/libsysprof-ui/css/SysprofDisplay-shared.css    |   5 +
 .../sysprof-visualizer-group-private.h             |   4 -
 src/libsysprof-ui/sysprof-visualizer-group.c       |  21 ---
 src/libsysprof-ui/sysprof-visualizer-ticks.c       | 132 +++----------------
 src/libsysprof-ui/sysprof-visualizer-ticks.h       |  18 +--
 src/libsysprof-ui/sysprof-visualizer.c             | 142 ++++++++++-----------
 src/libsysprof-ui/sysprof-visualizer.h             |   6 +
 src/libsysprof-ui/sysprof-visualizers-frame.c      |  98 ++++++--------
 src/libsysprof-ui/sysprof-visualizers-frame.ui     |  12 +-
 9 files changed, 152 insertions(+), 286 deletions(-)
---
diff --git a/src/libsysprof-ui/css/SysprofDisplay-shared.css b/src/libsysprof-ui/css/SysprofDisplay-shared.css
index 45eddf0..483b42a 100644
--- a/src/libsysprof-ui/css/SysprofDisplay-shared.css
+++ b/src/libsysprof-ui/css/SysprofDisplay-shared.css
@@ -24,6 +24,11 @@ SysprofVisualizersFrame box.horizontal.inline-toolbar {
   border-width: 0;
   }
 
+SysprofVisualizersFrame viewport.visualizers {
+  border-right: 1px solid @borders;
+  box-shadow: 1px 1px 10px @borders;
+  }
+
 SysprofVisualizersFrame scrollbar.horizontal {
   color: mix(@theme_fg_color, @theme_selected_bg_color, 0.5);
   background: transparent;
diff --git a/src/libsysprof-ui/sysprof-visualizer-group-private.h 
b/src/libsysprof-ui/sysprof-visualizer-group-private.h
index 850c960..74f3953 100644
--- a/src/libsysprof-ui/sysprof-visualizer-group-private.h
+++ b/src/libsysprof-ui/sysprof-visualizer-group-private.h
@@ -27,10 +27,6 @@
 
 G_BEGIN_DECLS
 
-void                          _sysprof_visualizer_set_data_width          (SysprofVisualizer            
*self,
-                                                                           gint                          
width);
-void                          _sysprof_visualizer_group_set_data_width    (SysprofVisualizerGroup       
*self,
-                                                                           gint                          
width);
 void                          _sysprof_visualizer_group_set_reader        (SysprofVisualizerGroup       
*self,
                                                                            SysprofCaptureReader         
*reader);
 SysprofVisualizerGroupHeader *_sysprof_visualizer_group_header_new        (void);
diff --git a/src/libsysprof-ui/sysprof-visualizer-group.c b/src/libsysprof-ui/sysprof-visualizer-group.c
index 3c5e81d..56f7f63 100644
--- a/src/libsysprof-ui/sysprof-visualizer-group.c
+++ b/src/libsysprof-ui/sysprof-visualizer-group.c
@@ -438,27 +438,6 @@ sysprof_visualizer_group_insert (SysprofVisualizerGroup *self,
     }
 }
 
-static void
-propagate_data_width_cb (GtkWidget *widget,
-                         gpointer   user_data)
-{
-  _sysprof_visualizer_set_data_width (SYSPROF_VISUALIZER (widget),
-                                      GPOINTER_TO_INT (user_data));
-}
-
-void
-_sysprof_visualizer_group_set_data_width (SysprofVisualizerGroup *self,
-                                          gint                    width)
-{
-  SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self);
-
-  g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self));
-
-  gtk_container_foreach (GTK_CONTAINER (priv->visualizers),
-                         propagate_data_width_cb,
-                         GINT_TO_POINTER (width));
-}
-
 gint
 sysprof_visualizer_group_get_priority (SysprofVisualizerGroup *self)
 {
diff --git a/src/libsysprof-ui/sysprof-visualizer-ticks.c b/src/libsysprof-ui/sysprof-visualizer-ticks.c
index 9b3ec35..c136d02 100644
--- a/src/libsysprof-ui/sysprof-visualizer-ticks.c
+++ b/src/libsysprof-ui/sysprof-visualizer-ticks.c
@@ -34,15 +34,10 @@
 #define MIN_TICK_DISTANCE 20
 #define LABEL_HEIGHT_PX 10
 
-SYSPROF_ALIGNED_BEGIN (8)
 struct _SysprofVisualizerTicks
 {
-  GtkDrawingArea parent_instance;
-
-  gint64 epoch;
-  gint64 begin_time;
-  gint64 end_time;
-} SYSPROF_ALIGNED_END (8);
+  SysprofVisualizer parent_instance;
+};
 
 enum {
   TICK_MINUTES,
@@ -75,7 +70,7 @@ struct {
   { 1, 1, SYSPROF_NSEC_PER_SEC / 10000 },
 };
 
-G_DEFINE_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, GTK_TYPE_DRAWING_AREA)
+G_DEFINE_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, SYSPROF_TYPE_VISUALIZER)
 
 static void
 update_label_text (PangoLayout *layout,
@@ -138,16 +133,6 @@ update_label_text (PangoLayout *layout,
   pango_layout_set_text (layout, str, -1);
 }
 
-static inline gdouble
-get_x_for_time (SysprofVisualizerTicks   *self,
-                const GtkAllocation *alloc,
-                gint64               t)
-{
-  gint64 timespan = self->end_time - self->begin_time;
-  gdouble x_ratio = (gdouble)(t - self->begin_time) / (gdouble)timespan;
-  return alloc->width * x_ratio;
-}
-
 static gboolean
 draw_ticks (SysprofVisualizerTicks *self,
             cairo_t           *cr,
@@ -156,8 +141,8 @@ draw_ticks (SysprofVisualizerTicks *self,
             gboolean           label_mode)
 {
   GtkAllocation alloc;
+  gint64 begin_time, end_time;
   gdouble half;
-  gint64 x_offset;
   gint count = 0;
 
   g_assert (SYSPROF_IS_VISUALIZER_TICKS (self));
@@ -166,6 +151,9 @@ draw_ticks (SysprofVisualizerTicks *self,
   g_assert (ticks >= 0);
   g_assert (ticks < N_TICKS);
 
+  begin_time = sysprof_visualizer_get_begin_time (SYSPROF_VISUALIZER (self));
+  end_time = sysprof_visualizer_get_end_time (SYSPROF_VISUALIZER (self));
+
   /*
    * If we are in label_model, we don't draw the ticks but only the labels.
    * That way we can determine which tick level managed to draw a tick in
@@ -175,17 +163,12 @@ draw_ticks (SysprofVisualizerTicks *self,
 
   half = tick_sizing[ticks].width / 2.0;
 
-  /* Take our epoch into account to calculate the offset of the
-   * first tick, which might not align perfectly when the beginning
-   * of the visible area.
-   */
-  x_offset = (self->begin_time - self->epoch) % tick_sizing[ticks].span;
   gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
 
   if G_UNLIKELY (label_mode)
     {
-      PangoLayout *layout;
       PangoFontDescription *font_desc;
+      PangoLayout *layout;
       gboolean want_msec;
       gint last_x2 = G_MININT;
       gint w, h;
@@ -205,17 +188,15 @@ draw_ticks (SysprofVisualizerTicks *self,
        */
       want_msec = tick_sizing[ticks].span < SYSPROF_NSEC_PER_SEC;
 
-      for (gint64 t = self->begin_time - x_offset;
-           t <= self->end_time;
-           t += tick_sizing[ticks].span)
+      for (gint64 t = begin_time; t <= end_time; t += tick_sizing[ticks].span)
         {
-          gdouble x = get_x_for_time (self, &alloc, t);
+          gdouble x = sysprof_visualizer_get_x_for_time (SYSPROF_VISUALIZER (self), t);
 
           if (x < (last_x2 + MIN_TICK_DISTANCE))
             continue;
 
           cairo_move_to (cr, (gint)x + 2.5 - (gint)half, 2);
-          update_label_text (layout, t - self->epoch, want_msec);
+          update_label_text (layout, t - begin_time, want_msec);
           pango_layout_get_pixel_size (layout, &w, &h);
           pango_cairo_show_layout (cr, layout);
 
@@ -226,12 +207,9 @@ draw_ticks (SysprofVisualizerTicks *self,
     }
   else
     {
-      for (gint64 t = self->begin_time - x_offset;
-           t <= self->end_time;
-           t += tick_sizing[ticks].span)
+      for (gint64 t = begin_time; t <= end_time; t += tick_sizing[ticks].span)
         {
-          gdouble x = get_x_for_time (self, &alloc, t);
-
+          gdouble x = sysprof_visualizer_get_x_for_time (SYSPROF_VISUALIZER (self), t);
           cairo_move_to (cr, (gint)x - .5 - (gint)half, alloc.height);
           cairo_line_to (cr, (gint)x - .5 - (gint)half, alloc.height - tick_sizing[ticks].height);
           count++;
@@ -258,12 +236,15 @@ sysprof_visualizer_ticks_draw (GtkWidget *widget,
   g_assert (SYSPROF_IS_VISUALIZER_TICKS (self));
   g_assert (cr != NULL);
 
-  if (0 == (timespan = self->end_time - self->begin_time))
+  timespan = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self));
+  if (timespan == 0)
     return GDK_EVENT_PROPAGATE;
 
   style = gtk_widget_get_style_context (widget);
 
   gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
+  alloc.x = 0;
+  alloc.y = 0;
 
   gtk_render_background (style, cr, 0, 0, alloc.width, alloc.height);
 
@@ -326,9 +307,6 @@ sysprof_visualizer_ticks_class_init (SysprofVisualizerTicksClass *klass)
 static void
 sysprof_visualizer_ticks_init (SysprofVisualizerTicks *self)
 {
-  self->end_time = SYSPROF_NSEC_PER_SEC * 60;
-
-  gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
 }
 
 GtkWidget *
@@ -336,79 +314,3 @@ sysprof_visualizer_ticks_new (void)
 {
   return g_object_new (SYSPROF_TYPE_VISUALIZER_TICKS, NULL);
 }
-
-void
-sysprof_visualizer_ticks_get_time_range (SysprofVisualizerTicks *self,
-                                         gint64                 *begin_time,
-                                         gint64                 *end_time)
-{
-  g_return_if_fail (SYSPROF_IS_VISUALIZER_TICKS (self));
-  g_return_if_fail (begin_time != NULL || end_time != NULL);
-
-  if (begin_time != NULL)
-    *begin_time = self->begin_time;
-
-  if (end_time != NULL)
-    *end_time = self->end_time;
-}
-
-void
-sysprof_visualizer_ticks_set_time_range (SysprofVisualizerTicks *self,
-                                         gint64                  begin_time,
-                                         gint64                  end_time)
-{
-  g_return_if_fail (SYSPROF_IS_VISUALIZER_TICKS (self));
-
-  if (begin_time > end_time)
-    {
-      gint64 tmp = begin_time;
-      begin_time = end_time;
-      end_time = tmp;
-    }
-
-  self->begin_time = begin_time;
-  self->end_time = end_time;
-
-  gtk_widget_queue_draw (GTK_WIDGET (self));
-}
-
-gint64
-sysprof_visualizer_ticks_get_epoch (SysprofVisualizerTicks *self)
-{
-  g_return_val_if_fail (SYSPROF_IS_VISUALIZER_TICKS (self), 0);
-
-  return self->epoch;
-}
-
-/*
- * Sets the epoch for the visualizer ticks.
- *
- * The epoch is the "real" starting time of the capture, where as the
- * sysprof_visualizer_ticks_set_time_range() function sets the visible range
- * of the capture.
- *
- * This is used to calculate the offset of the beginning of the capture
- * from begin_time so that the ticks appear in the proper location.
- *
- * This function should only need to be called when the reader is changed.
- */
-void
-sysprof_visualizer_ticks_set_epoch (SysprofVisualizerTicks *self,
-                                    gint64                  epoch)
-{
-  g_return_if_fail (SYSPROF_IS_VISUALIZER_TICKS (self));
-
-  if (self->epoch != epoch)
-    {
-      self->epoch = epoch;
-      gtk_widget_queue_draw (GTK_WIDGET (self));
-    }
-}
-
-gint64
-sysprof_visualizer_ticks_get_duration (SysprofVisualizerTicks *self)
-{
-  g_return_val_if_fail (SYSPROF_IS_VISUALIZER_TICKS (self), 0);
-
-  return self->end_time - self->begin_time;
-}
diff --git a/src/libsysprof-ui/sysprof-visualizer-ticks.h b/src/libsysprof-ui/sysprof-visualizer-ticks.h
index aa963fa..cb4d6f5 100644
--- a/src/libsysprof-ui/sysprof-visualizer-ticks.h
+++ b/src/libsysprof-ui/sysprof-visualizer-ticks.h
@@ -22,22 +22,14 @@
 
 #include <gtk/gtk.h>
 
+#include "sysprof-visualizer.h"
+
 G_BEGIN_DECLS
 
 #define SYSPROF_TYPE_VISUALIZER_TICKS (sysprof_visualizer_ticks_get_type())
 
-G_DECLARE_FINAL_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, SYSPROF, VISUALIZER_TICKS, 
GtkDrawingArea)
-
-GtkWidget *sysprof_visualizer_ticks_new            (void);
-void       sysprof_visualizer_ticks_set_epoch      (SysprofVisualizerTicks *self,
-                                                    gint64                  epoch);
-gint64     sysprof_visualizer_ticks_get_epoch      (SysprofVisualizerTicks *self);
-void       sysprof_visualizer_ticks_get_time_range (SysprofVisualizerTicks *self,
-                                                    gint64                 *begin_time,
-                                                    gint64                 *end_time);
-void       sysprof_visualizer_ticks_set_time_range (SysprofVisualizerTicks *self,
-                                                    gint64                  begin_time,
-                                                    gint64                  end_time);
-gint64     sysprof_visualizer_ticks_get_duration   (SysprofVisualizerTicks *self);
+G_DECLARE_FINAL_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, SYSPROF, VISUALIZER_TICKS, 
SysprofVisualizer)
+
+GtkWidget *sysprof_visualizer_ticks_new (void);
 
 G_END_DECLS
diff --git a/src/libsysprof-ui/sysprof-visualizer.c b/src/libsysprof-ui/sysprof-visualizer.c
index 41ffba5..eae1277 100644
--- a/src/libsysprof-ui/sysprof-visualizer.c
+++ b/src/libsysprof-ui/sysprof-visualizer.c
@@ -32,10 +32,10 @@ typedef struct
   gint64 end_time;
   gint64 duration;
 
-  /* The width for [begin_time..end_time] which may be less
-   * than what the widgets allocation is.
+  /* A cached allocation that has the borders subtracted so that
+   * we place the content within the expected area.
    */
-  gint data_width;
+  GtkAllocation cache_alloc;
 } SysprofVisualizerPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (SysprofVisualizer, sysprof_visualizer, DZL_TYPE_BIN)
@@ -50,31 +50,51 @@ enum {
 
 static GParamSpec *properties [N_PROPS];
 
-static gboolean
-sysprof_visualizer_draw (GtkWidget *widget,
-                         cairo_t   *cr)
+static inline void
+subtract_border (GtkAllocation *alloc,
+                 GtkBorder     *border)
 {
-  g_assert (SYSPROF_IS_VISUALIZER (widget));
-  g_assert (cr != NULL);
+#if 0
+  g_print ("Border; %d %d %d %d\n", border->top, border->left, border->bottom, border->right);
+#endif
+
+  alloc->x += border->left;
+  alloc->y += border->top;
+  alloc->width -= border->left + border->right;
+  alloc->height -= border->top + border->bottom;
+}
+
+static void
+adjust_alloc_for_borders (SysprofVisualizer *self,
+                          GtkAllocation     *alloc)
+{
+  GtkStyleContext *style_context;
+  GtkBorder border;
+  GtkStateFlags state;
+
+  g_assert (SYSPROF_IS_VISUALIZER (self));
+  g_assert (alloc != NULL);
 
-  GTK_WIDGET_CLASS (sysprof_visualizer_parent_class)->draw (widget, cr);
+  state = gtk_widget_get_state_flags (GTK_WIDGET (self));
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
+  gtk_style_context_get_border (style_context, state, &border);
 
-  return GDK_EVENT_PROPAGATE;
+  subtract_border (alloc, &border);
 }
 
 static void
-sysprof_visualizer_get_preferred_width (GtkWidget *widget,
-                                        gint      *min_width,
-                                        gint      *nat_width)
+sysprof_visualizer_size_allocate (GtkWidget     *widget,
+                                  GtkAllocation *alloc)
 {
   SysprofVisualizer *self = (SysprofVisualizer *)widget;
   SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self);
 
   g_assert (SYSPROF_IS_VISUALIZER (self));
-  g_assert (min_width != NULL);
-  g_assert (nat_width != NULL);
 
-  *min_width = *nat_width = priv->data_width ? priv->data_width : 1;
+  GTK_WIDGET_CLASS (sysprof_visualizer_parent_class)->size_allocate (widget, alloc);
+
+  priv->cache_alloc = *alloc;
+  adjust_alloc_for_borders (self, &priv->cache_alloc);
 }
 
 static void
@@ -155,8 +175,7 @@ sysprof_visualizer_class_init (SysprofVisualizerClass *klass)
   object_class->get_property = sysprof_visualizer_get_property;
   object_class->set_property = sysprof_visualizer_set_property;
 
-  widget_class->draw = sysprof_visualizer_draw;
-  widget_class->get_preferred_width = sysprof_visualizer_get_preferred_width;
+  widget_class->size_allocate = sysprof_visualizer_size_allocate;
 
   properties [PROP_BEGIN_TIME] =
     g_param_spec_int64 ("begin-time",
@@ -239,6 +258,15 @@ sysprof_visualizer_get_end_time (SysprofVisualizer *self)
   return priv->end_time;
 }
 
+gint64
+sysprof_visualizer_get_duration (SysprofVisualizer *self)
+{
+  g_return_val_if_fail (SYSPROF_IS_VISUALIZER (self), 0);
+
+  return sysprof_visualizer_get_end_time (self) -
+         sysprof_visualizer_get_begin_time (self);
+}
+
 void
 sysprof_visualizer_set_reader (SysprofVisualizer    *self,
                                SysprofCaptureReader *reader)
@@ -258,39 +286,7 @@ sysprof_visualizer_set_reader (SysprofVisualizer    *self,
   if (SYSPROF_VISUALIZER_GET_CLASS (self)->set_reader)
     SYSPROF_VISUALIZER_GET_CLASS (self)->set_reader (self, reader);
 
-  gtk_widget_queue_resize (GTK_WIDGET (self));
-}
-
-static inline void
-subtract_border (GtkAllocation *alloc,
-                 GtkBorder     *border)
-{
-#if 0
-  g_print ("Border; %d %d %d %d\n", border->top, border->left, border->bottom, border->right);
-#endif
-
-  alloc->x += border->left;
-  alloc->y += border->top;
-  alloc->width -= border->left + border->right;
-  alloc->height -= border->top + border->bottom;
-}
-
-static void
-adjust_alloc_for_borders (SysprofVisualizer *self,
-                          GtkAllocation     *alloc)
-{
-  GtkStyleContext *style_context;
-  GtkBorder border;
-  GtkStateFlags state;
-
-  g_assert (SYSPROF_IS_VISUALIZER (self));
-  g_assert (alloc != NULL);
-
-  state = gtk_widget_get_state_flags (GTK_WIDGET (self));
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
-  gtk_style_context_get_border (style_context, state, &border);
-
-  subtract_border (alloc, &border);
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
 
 void
@@ -301,46 +297,46 @@ sysprof_visualizer_translate_points (SysprofVisualizer                    *self,
                                      guint                                 n_out_points)
 {
   SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self);
-  GtkAllocation alloc;
-  gint graph_width;
+  const GtkAllocation *a;
 
   g_return_if_fail (SYSPROF_IS_VISUALIZER (self));
   g_return_if_fail (in_points != NULL);
   g_return_if_fail (out_points != NULL);
   g_return_if_fail (n_in_points == n_out_points);
 
-  gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
-  adjust_alloc_for_borders (self, &alloc);
-
-  graph_width = priv->data_width;
+  a = &priv->cache_alloc;
 
   for (guint i = 0; i < n_in_points; i++)
     {
-      out_points[i].x = (in_points[i].x * graph_width);
-      out_points[i].y = alloc.height - (ABS (in_points[i].y) * alloc.height);
+      out_points[i].x = (in_points[i].x * a->width);
+      out_points[i].y = a->height - (ABS (in_points[i].y) * a->height);
     }
 }
 
-void
-_sysprof_visualizer_set_data_width (SysprofVisualizer *self,
-                                    gint               data_width)
+gint
+sysprof_visualizer_get_x_for_time (SysprofVisualizer *self,
+                                   gint64             time)
 {
   SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self);
 
-  g_return_if_fail (SYSPROF_IS_VISUALIZER (self));
-
-  if (priv->data_width != data_width)
-    {
-      priv->data_width = data_width;
-      gtk_widget_queue_resize (GTK_WIDGET (self));
-    }
+  return ((time - priv->begin_time) / (gdouble)priv->duration) * priv->cache_alloc.width;
 }
 
-gint
-sysprof_visualizer_get_x_for_time (SysprofVisualizer *self,
-                                   gint64             time)
+void
+sysprof_visualizer_set_time_range (SysprofVisualizer *self,
+                                   gint64             begin_time,
+                                   gint64             end_time)
 {
   SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self);
 
-  return ((time - priv->begin_time) / (gdouble)priv->duration) * priv->data_width;
+  g_return_if_fail (SYSPROF_IS_VISUALIZER (self));
+
+  priv->begin_time = begin_time;
+  priv->end_time = end_time;
+  priv->duration = end_time - begin_time;
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BEGIN_TIME]);
+  g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_END_TIME]);
+
+  gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
diff --git a/src/libsysprof-ui/sysprof-visualizer.h b/src/libsysprof-ui/sysprof-visualizer.h
index 618f82d..38b94d4 100644
--- a/src/libsysprof-ui/sysprof-visualizer.h
+++ b/src/libsysprof-ui/sysprof-visualizer.h
@@ -67,6 +67,12 @@ gint64       sysprof_visualizer_get_begin_time   (SysprofVisualizer
 SYSPROF_AVAILABLE_IN_ALL
 gint64       sysprof_visualizer_get_end_time     (SysprofVisualizer                    *self);
 SYSPROF_AVAILABLE_IN_ALL
+void         sysprof_visualizer_set_time_range   (SysprofVisualizer                    *self,
+                                                  gint64                                begin_time,
+                                                  gint64                                end_time);
+SYSPROF_AVAILABLE_IN_ALL
+gint64       sysprof_visualizer_get_duration     (SysprofVisualizer                    *self);
+SYSPROF_AVAILABLE_IN_ALL
 void         sysprof_visualizer_set_reader       (SysprofVisualizer                    *self,
                                                   SysprofCaptureReader                 *reader);
 SYSPROF_AVAILABLE_IN_ALL
diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.c b/src/libsysprof-ui/sysprof-visualizers-frame.c
index a116920..d2baf7e 100644
--- a/src/libsysprof-ui/sysprof-visualizers-frame.c
+++ b/src/libsysprof-ui/sysprof-visualizers-frame.c
@@ -57,6 +57,8 @@ struct _SysprofVisualizersFrame
   SysprofZoomManager     *zoom_manager;
   GtkScale               *zoom_scale;
   GtkSizeGroup           *left_column;
+  GtkViewport            *ticks_viewport;
+  GtkViewport            *visualizers_viewport;
 };
 
 typedef struct
@@ -91,7 +93,7 @@ get_time_from_x (SysprofVisualizersFrame *self,
   g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
 
   gtk_widget_get_allocation (GTK_WIDGET (self->ticks), &alloc);
-  duration = sysprof_visualizer_ticks_get_duration (self->ticks);
+  duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks));
 
   if (alloc.width < 1)
     return 0;
@@ -147,7 +149,7 @@ visualizers_draw_after_cb (SysprofVisualizersFrame *self,
   draw.list = list;
   draw.cr = cr;
   draw.begin_time = self->begin_time;
-  draw.duration = sysprof_visualizer_ticks_get_duration (self->ticks);
+  draw.duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks));
 
   if (draw.duration == 0)
     return GDK_EVENT_PROPAGATE;
@@ -265,48 +267,38 @@ visualizers_motion_notify_event_cb (SysprofVisualizersFrame *self,
 }
 
 static void
-propagate_data_width_cb (GtkWidget *widget,
-                         gpointer   user_data)
+set_children_width_request_cb (GtkWidget *widget,
+                               gpointer   data)
 {
-  _sysprof_visualizer_group_set_data_width (SYSPROF_VISUALIZER_GROUP (widget),
-                                            GPOINTER_TO_INT (user_data));
+  gtk_widget_set_size_request (widget, GPOINTER_TO_INT (data), -1);
 }
 
 static void
-sysprof_visualizers_frame_notify_zoom (SysprofVisualizersFrame *self,
-                                       GParamSpec              *pspec,
-                                       SysprofZoomManager      *zoom_manager)
+set_children_width_request (GtkContainer *container,
+                            gint          width)
 {
-  gint data_width;
+  g_assert (GTK_IS_CONTAINER (container));
 
-  g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
-  g_assert (SYSPROF_IS_ZOOM_MANAGER (zoom_manager));
-
-  data_width = sysprof_zoom_manager_get_width_for_duration (self->zoom_manager,
-                                                            self->end_time - self->begin_time);
-  gtk_container_foreach (GTK_CONTAINER (self->visualizers),
-                         propagate_data_width_cb,
-                         GINT_TO_POINTER (data_width));
-  gtk_widget_queue_allocate (GTK_WIDGET (self));
+  gtk_container_foreach (container,
+                         set_children_width_request_cb,
+                         GINT_TO_POINTER (width));
 }
 
 static void
-sysprof_visualizers_frame_apply_zoom (SysprofVisualizersFrame *self,
-                                      const GtkAllocation     *alloc)
+sysprof_visualizers_frame_notify_zoom (SysprofVisualizersFrame *self,
+                                       GParamSpec              *pspec,
+                                       SysprofZoomManager      *zoom_manager)
 {
   gint64 duration;
-  gint64 end_time;
+  gint data_width;
 
   g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
+  g_assert (SYSPROF_IS_ZOOM_MANAGER (zoom_manager));
 
-  duration = sysprof_zoom_manager_get_duration_for_width (self->zoom_manager, alloc->width);
-  end_time = self->begin_time + duration;
-
-  sysprof_scrollmap_set_time_range (self->hscrollbar,
-                                    self->begin_time,
-                                    MAX (self->end_time, end_time));
-  sysprof_visualizer_ticks_set_epoch (self->ticks, self->begin_time);
-  sysprof_visualizer_ticks_set_time_range (self->ticks, self->begin_time, end_time);
+  duration = self->end_time - self->begin_time;
+  data_width = sysprof_zoom_manager_get_width_for_duration (self->zoom_manager, duration);
+  set_children_width_request (GTK_CONTAINER (self->ticks_viewport), data_width);
+  set_children_width_request (GTK_CONTAINER (self->visualizers_viewport), data_width);
 }
 
 static gint
@@ -372,27 +364,6 @@ sysprof_visualizers_frame_add (GtkContainer *container,
   GTK_CONTAINER_CLASS (sysprof_visualizers_frame_parent_class)->add (container, child);
 }
 
-static void
-sysprof_visualizers_frame_size_allocate (GtkWidget     *widget,
-                                         GtkAllocation *alloc)
-{
-  SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)widget;
-  gdouble zoom;
-
-  g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
-  g_assert (alloc != NULL);
-
-  GTK_WIDGET_CLASS (sysprof_visualizers_frame_parent_class)->size_allocate (widget, alloc);
-
-  zoom = sysprof_zoom_manager_get_zoom (self->zoom_manager);
-
-  if (alloc->width != self->last_alloc.width || zoom != self->last_zoom)
-    sysprof_visualizers_frame_apply_zoom (self, alloc);
-
-  self->last_alloc = *alloc;
-  self->last_zoom = zoom;
-}
-
 static void
 sysprof_visualizers_frame_selection_changed (SysprofVisualizersFrame *self,
                                              SysprofSelection        *selection)
@@ -420,6 +391,20 @@ sysprof_visualizers_frame_group_activated_cb (SysprofVisualizersFrame      *self
   g_signal_emit_by_name (group, "group-activated");
 }
 
+static void
+sysprof_visualizers_frame_size_allocate (GtkWidget     *widget,
+                                         GtkAllocation *alloc)
+{
+  SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)widget;
+
+  g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self));
+  g_assert (alloc != NULL);
+
+  sysprof_scrollmap_set_time_range (self->hscrollbar, self->begin_time, self->end_time);
+
+  GTK_WIDGET_CLASS (sysprof_visualizers_frame_parent_class)->size_allocate (widget, alloc);
+}
+
 static void
 sysprof_visualizers_frame_finalize (GObject *object)
 {
@@ -479,6 +464,8 @@ sysprof_visualizers_frame_class_init (SysprofVisualizersFrameClass *klass)
   gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, vscroller);
   gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, zoom_manager);
   gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, zoom_scale);
+  gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, ticks_viewport);
+  gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, visualizers_viewport);
 
   properties [PROP_SELECTED_GROUP] =
     g_param_spec_object ("selected-group",
@@ -681,9 +668,6 @@ sysprof_visualizers_frame_load_async (SysprofVisualizersFrame *self,
   self->begin_time = sysprof_capture_reader_get_start_time (reader);
   self->end_time = sysprof_capture_reader_get_end_time (reader);
 
-  if (alloc.width)
-    sysprof_visualizers_frame_apply_zoom (self, &alloc);
-
    /* Now we need to run through the frames and index their times
     * so that we can calculate the number of items per bucket when
     * drawing the scrollbar.
@@ -708,11 +692,9 @@ sysprof_visualizers_frame_load_finish (SysprofVisualizersFrame  *self,
 
   if ((timings = g_task_propagate_pointer (G_TASK (result), error)))
     {
-      GtkAllocation alloc;
-
-      gtk_widget_get_allocation (GTK_WIDGET (self->ticks), &alloc);
       sysprof_scrollmap_set_timings (self->hscrollbar, timings);
-      sysprof_visualizers_frame_apply_zoom (self, &alloc);
+      sysprof_scrollmap_set_time_range (self->hscrollbar, self->begin_time, self->end_time);
+      sysprof_visualizer_set_time_range (SYSPROF_VISUALIZER (self->ticks), self->begin_time, self->end_time);
       gtk_widget_queue_resize (GTK_WIDGET (self));
 
       return TRUE;
diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.ui b/src/libsysprof-ui/sysprof-visualizers-frame.ui
index 11cda09..60c5940 100644
--- a/src/libsysprof-ui/sysprof-visualizers-frame.ui
+++ b/src/libsysprof-ui/sysprof-visualizers-frame.ui
@@ -122,10 +122,14 @@
                     <property name="hscrollbar_policy">external</property>
                     <property name="vscrollbar_policy">never</property>
                     <child>
-                      <object class="GtkViewport">
+                      <object class="GtkViewport" id="ticks_viewport">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
+                        <property name="halign">start</property>
                         <property name="shadow_type">none</property>
+                        <style>
+                          <class name="visualizers"/>
+                        </style>
                         <child>
                           <object class="SysprofVisualizerTicks" id="ticks">
                             <property name="visible">True</property>
@@ -223,10 +227,14 @@
                         <property name="vscrollbar_policy">never</property>
                         <property name="propagate_natural_height">True</property>
                         <child>
-                          <object class="GtkViewport">
+                          <object class="GtkViewport" id="visualizers_viewport">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="shadow_type">none</property>
+                            <property name="halign">start</property>
+                            <style>
+                              <class name="visualizers"/>
+                            </style>
                             <child>
                               <object class="GtkListBox" id="visualizers">
                                 <property name="visible">True</property>


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