[libhandy] preferences-page: Don't manually add a viewport



commit b639ac10f232397fcdd204913cd30c2a8d689341
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jan 8 13:00:26 2021 +0100

    preferences-page: Don't manually add a viewport
    
    This lets GTK manually add a GtkViewport and bind the scrolled window's
    vertical adjustment to the viewport's, meaning the scrolled window now
    automatically adjusts on the focused child.
    
    This also drops the private vadjustment accessor and drops code in
    HdyPreferencesWindow to manually adjust on the selected child.

 src/hdy-preferences-page-private.h |  2 --
 src/hdy-preferences-page.c         | 12 ------------
 src/hdy-preferences-page.ui        | 14 ++++----------
 src/hdy-preferences-window.c       | 15 ---------------
 4 files changed, 4 insertions(+), 39 deletions(-)
---
diff --git a/src/hdy-preferences-page-private.h b/src/hdy-preferences-page-private.h
index a93ccfd9..ad095480 100644
--- a/src/hdy-preferences-page-private.h
+++ b/src/hdy-preferences-page-private.h
@@ -10,8 +10,6 @@
 
 G_BEGIN_DECLS
 
-GtkAdjustment *hdy_preferences_page_get_vadjustment (HdyPreferencesPage *self);
-
 void hdy_preferences_page_add_preferences_to_model (HdyPreferencesPage *self,
                                                     GListStore         *model);
 
diff --git a/src/hdy-preferences-page.c b/src/hdy-preferences-page.c
index 51fdc0dc..4d5ee3a1 100644
--- a/src/hdy-preferences-page.c
+++ b/src/hdy-preferences-page.c
@@ -326,18 +326,6 @@ hdy_preferences_page_set_title (HdyPreferencesPage *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TITLE]);
 }
 
-GtkAdjustment *
-hdy_preferences_page_get_vadjustment (HdyPreferencesPage *self)
-{
-  HdyPreferencesPagePrivate *priv;
-
-  g_return_val_if_fail (HDY_IS_PREFERENCES_PAGE (self), NULL);
-
-  priv = hdy_preferences_page_get_instance_private (self);
-
-  return gtk_scrolled_window_get_vadjustment (priv->scrolled_window);
-}
-
 /**
  * hdy_preferences_page_add_preferences_to_model: (skip)
  * @self: a #HdyPreferencesPage
diff --git a/src/hdy-preferences-page.ui b/src/hdy-preferences-page.ui
index 536d8d3d..8e53e006 100644
--- a/src/hdy-preferences-page.ui
+++ b/src/hdy-preferences-page.ui
@@ -8,19 +8,13 @@
         <property name="hscrollbar-policy">never</property>
         <property name="propagate-natural-height">True</property>
         <child>
-          <object class="GtkViewport">
-            <property name="shadow-type">none</property>
+          <object class="HdyClamp">
             <property name="visible">True</property>
             <child>
-              <object class="HdyClamp">
+              <object class="GtkBox" id="box">
+                <property name="orientation">vertical</property>
+                <property name="spacing">30</property>
                 <property name="visible">True</property>
-                <child>
-                  <object class="GtkBox" id="box">
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">30</property>
-                    <property name="visible">True</property>
-                  </object>
-                </child>
               </object>
             </child>
           </object>
diff --git a/src/hdy-preferences-window.c b/src/hdy-preferences-window.c
index 8650cc61..640e4ab4 100644
--- a/src/hdy-preferences-window.c
+++ b/src/hdy-preferences-window.c
@@ -223,9 +223,6 @@ search_result_activated_cb (HdyPreferencesWindow *self,
   HdyPreferencesWindowPrivate *priv = hdy_preferences_window_get_instance_private (self);
   HdyPreferencesPage *page;
   HdyPreferencesRow *row;
-  GtkAdjustment *adjustment;
-  GtkAllocation allocation;
-  gint y = 0;
 
   gtk_toggle_button_set_active (priv->search_button, FALSE);
   page = HDY_PREFERENCES_PAGE (g_object_get_data (G_OBJECT (widget), "page"));
@@ -234,21 +231,9 @@ search_result_activated_cb (HdyPreferencesWindow *self,
   g_assert (page != NULL);
   g_assert (row != NULL);
 
-  adjustment = hdy_preferences_page_get_vadjustment (page);
-
-  g_assert (adjustment != NULL);
-
   gtk_stack_set_visible_child (priv->pages_stack, GTK_WIDGET (page));
   gtk_widget_set_can_focus (GTK_WIDGET (row), TRUE);
   gtk_widget_grab_focus (GTK_WIDGET (row));
-
-  if (!gtk_widget_translate_coordinates (GTK_WIDGET (row), GTK_WIDGET (page), 0, 0, NULL, &y))
-    return;
-
-  gtk_container_set_focus_child (GTK_CONTAINER (page), GTK_WIDGET (row));
-  y += gtk_adjustment_get_value (adjustment);
-  gtk_widget_get_allocation (GTK_WIDGET (row), &allocation);
-  gtk_adjustment_clamp_page (adjustment, y, y + allocation.height);
 }
 
 static gboolean


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