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



commit 3c81ea519e8a269953dc725584fb9e5d0d5c1b9f
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 1b7007982..93a921cff 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)
@@ -409,8 +410,21 @@ real_reveal_selection (NautilusFilesView *files_view)
     item_ui = nautilus_view_item_model_get_item_ui (item_model);
     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 has 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);
+    }
 
     g_list_foreach (selection, (GFunc) g_object_unref, NULL);
 }


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