[nautilus/antonioffix-menus-and-popovers: 14/14] view-icon-controller: Scroll only as necessary to reveal



commit 85fc37a18e80c8e63d1f7f625792ad2fdbd6d8ae
Author: António Fernandes <antoniof gnome org>
Date:   Sat Jan 13 21:43:41 2018 +0000

    view-icon-controller: Scroll only as necessary to reveal
    
    Currently we always scroll the item to reveal to the top.
    
    This will scroll the item even if it is already visible
    but not in the first row.
    
    Instead, scroll as little as necessary to reveal the whole
    item, matching the behavior of list view and canvas view.

 src/nautilus-view-icon-controller.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 4326efeda..aacb8c1c4 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -397,6 +397,7 @@ real_reveal_selection (NautilusFilesView *files_view,
     GtkAllocation allocation;
     GtkWidget *content_widget;
     GtkAdjustment *vadjustment;
+    int view_height;
 
     selection = nautilus_view_get_selection (NAUTILUS_VIEW (files_view));
     if (selection == NULL)
@@ -417,8 +418,21 @@ real_reveal_selection (NautilusFilesView *files_view,
 
     gtk_widget_get_allocation (item_ui, &allocation);
     content_widget = nautilus_files_view_get_content_widget (files_view);
+    view_height = gtk_widget_get_allocated_height (content_widget);
     vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (content_widget));
-    gtk_adjustment_set_value (vadjustment, allocation.y);
+
+    /* Scroll only as necessary. TODO: Would be nice to have this as part of
+     * GtkFlowBox. GtkTreeView and GtkSourceView have something similar. */
+    if (allocation.y < gtk_adjustment_get_value (vadjustment))
+    {
+        gtk_adjustment_set_value (vadjustment, allocation.y);
+    }
+    else if (allocation.y + allocation.height >
+                gtk_adjustment_get_value (vadjustment) + view_height)
+    {
+        gtk_adjustment_set_value (vadjustment,
+                                  allocation.y + allocation.height - view_height);
+    }
 
     if (revealed_area)
     {


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