[sysprof/wip/visualizers] visualizer-view: add helper viewport for scrolling



commit 8d8c879384f326ee12b8d2893e6ccff9843e5fdc
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 3 16:08:13 2016 -0700

    visualizer-view: add helper viewport for scrolling
    
    We can avoid using the inline scrollbar in favor of overlay
    scrolling if we bridge the adjustment into the GtkViewport.
    This sadly requires us to subclass things to get it just
    right.

 lib/Makefile.am                        |    2 +
 lib/resources/ui/sp-visualizer-view.ui |   19 ++---
 lib/sp-viewport.c                      |  126 ++++++++++++++++++++++++++++++++
 lib/sp-viewport.h                      |   34 +++++++++
 lib/sp-visualizer-view.c               |   13 ---
 5 files changed, 171 insertions(+), 23 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index ef981b8..23b64a4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -173,6 +173,8 @@ libsysprof_ui_@API_VERSION@_la_SOURCES = \
        sp-process-model-row.c \
        sp-profiler-menu-button.c \
        sp-recording-state-view.c \
+       sp-viewport.c \
+       sp-viewport.h \
        sp-visualizer-list.c \
        sp-visualizer-list.h \
        sp-visualizer-row.c \
diff --git a/lib/resources/ui/sp-visualizer-view.ui b/lib/resources/ui/sp-visualizer-view.ui
index c183ec3..9970393 100644
--- a/lib/resources/ui/sp-visualizer-view.ui
+++ b/lib/resources/ui/sp-visualizer-view.ui
@@ -17,24 +17,23 @@
             <property name="visible">true</property>
             <child>
               <object class="GtkScrolledWindow">
-                <!-- Horizontal scrolling is handled by @scrollbar -->
-                <property name="hscrollbar-policy">never</property>
-                <property name="visible">true</property>
+                <property name="hadjustment">scroll_adjustment</property>
                 <property name="propagate-natural-height">true</property>
                 <property name="vexpand">true</property>
+                <property name="visible">true</property>
                 <child>
-                  <object class="SpVisualizerList" id="list">
+                  <object class="SpViewport">
                     <property name="visible">true</property>
+                    <property name="hadjustment">scroll_adjustment</property>
+                    <child>
+                      <object class="SpVisualizerList" id="list">
+                        <property name="visible">true</property>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
             </child>
-            <child>
-              <object class="GtkScrollbar" id="scrollbar">
-                <property name="adjustment">scroll_adjustment</property>
-                <property name="orientation">horizontal</property>
-              </object>
-            </child>
           </object>
         </child>
       </object>
diff --git a/lib/sp-viewport.c b/lib/sp-viewport.c
new file mode 100644
index 0000000..7efa297
--- /dev/null
+++ b/lib/sp-viewport.c
@@ -0,0 +1,126 @@
+/* sp-viewport.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This is meant to act like GtkViewport but allow us to override the
+ * GtkAdjustment without having viewport change our values.
+ */
+
+#define G_LOG_DOMAIN "sp-viewport"
+
+#include "sp-viewport.h"
+
+struct _SpViewport
+{
+  GtkViewport parent_instance;
+
+  GtkAdjustment *hadjustment;
+  GtkAdjustment *vadjustment;
+};
+
+G_DEFINE_TYPE (SpViewport, sp_viewport, GTK_TYPE_VIEWPORT)
+
+enum {
+  PROP_0,
+  N_PROPS,
+
+  /* Overridden properties */
+  PROP_HADJUSTMENT,
+  PROP_VADJUSTMENT,
+};
+
+static void
+sp_viewport_finalize (GObject *object)
+{
+  SpViewport *self = (SpViewport *)object;
+
+  g_clear_object (&self->hadjustment);
+  g_clear_object (&self->vadjustment);
+
+  G_OBJECT_CLASS (sp_viewport_parent_class)->finalize (object);
+}
+
+static void
+sp_viewport_get_property (GObject    *object,
+                          guint       prop_id,
+                          GValue     *value,
+                          GParamSpec *pspec)
+{
+  SpViewport *self = SP_VIEWPORT (object);
+
+  switch (prop_id)
+    {
+    case PROP_HADJUSTMENT:
+      g_value_set_object (value, self->hadjustment);
+      break;
+
+    case PROP_VADJUSTMENT:
+      g_value_set_object (value, self->vadjustment);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sp_viewport_set_property (GObject      *object,
+                          guint         prop_id,
+                          const GValue *value,
+                          GParamSpec   *pspec)
+{
+  SpViewport *self = SP_VIEWPORT (object);
+
+  switch (prop_id)
+    {
+    case PROP_HADJUSTMENT:
+      g_clear_object (&self->hadjustment);
+      self->hadjustment = g_value_dup_object (value);
+      g_object_notify_by_pspec (object, pspec);
+      break;
+
+    case PROP_VADJUSTMENT:
+      g_clear_object (&self->vadjustment);
+      self->vadjustment = g_value_dup_object (value);
+      g_object_notify_by_pspec (object, pspec);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+sp_viewport_class_init (SpViewportClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = sp_viewport_set_property;
+  object_class->get_property = sp_viewport_get_property;
+  object_class->finalize = sp_viewport_finalize;
+
+  g_object_class_override_property (object_class, PROP_HADJUSTMENT, "hadjustment");
+  g_object_class_override_property (object_class, PROP_VADJUSTMENT, "vadjustment");
+}
+
+static void
+sp_viewport_init (SpViewport *self)
+{
+  self->hadjustment = gtk_adjustment_new (0, 0, 0, 0, 0, 0);
+  self->vadjustment = gtk_adjustment_new (0, 0, 0, 0, 0, 0);
+}
diff --git a/lib/sp-viewport.h b/lib/sp-viewport.h
new file mode 100644
index 0000000..dff59aa
--- /dev/null
+++ b/lib/sp-viewport.h
@@ -0,0 +1,34 @@
+/* sp-viewport.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SP_VIEWPORT_H
+#define SP_VIEWPORT_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define SP_TYPE_VIEWPORT (sp_viewport_get_type())
+
+G_DECLARE_FINAL_TYPE (SpViewport, sp_viewport, SP, VIEWPORT, GtkViewport)
+
+GtkWidget *sp_viewport_new (void);
+
+G_END_DECLS
+
+#endif /* SP_VIEWPORT_H */
diff --git a/lib/sp-visualizer-view.c b/lib/sp-visualizer-view.c
index 96763b2..ed2bd9f 100644
--- a/lib/sp-visualizer-view.c
+++ b/lib/sp-visualizer-view.c
@@ -33,7 +33,6 @@ typedef struct
 
   SpVisualizerList  *list;
   GtkAdjustment     *scroll_adjustment;
-  GtkScrollbar      *scrollbar;
   SpVisualizerTicks *ticks;
 } SpVisualizerViewPrivate;
 
@@ -155,17 +154,6 @@ sp_visualizer_view_notify_zoom (SpVisualizerView *self,
 
   if (value + page_size > upper)
     gtk_adjustment_set_value (priv->scroll_adjustment, upper - page_size);
-
-  if (priv->reader != NULL)
-    {
-      gint64 real_range;
-      gboolean visible;
-
-      real_range = sp_capture_reader_get_end_time (priv->reader)
-                 - sp_capture_reader_get_start_time (priv->reader);
-      visible = (gtk_adjustment_get_page_size (priv->scroll_adjustment) < real_range);
-      gtk_widget_set_visible (GTK_WIDGET (priv->scrollbar), visible);
-    }
 }
 
 static void
@@ -271,7 +259,6 @@ sp_visualizer_view_class_init (SpVisualizerViewClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sp-visualizer-view.ui");
   gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, list);
   gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, scroll_adjustment);
-  gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, scrollbar);
   gtk_widget_class_bind_template_child_private (widget_class, SpVisualizerView, ticks);
 
   gtk_widget_class_set_css_name (widget_class, "visualizers");


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