[gtk+] iconview: Don't expand items to more than natural size



commit e133c6cb71e8416c5848ad06c680e6b5a0b9b16e
Author: Benjamin Otte <otte redhat com>
Date:   Mon May 7 01:35:00 2012 +0200

    iconview: Don't expand items to more than natural size
    
    This ensures that items stay left-aligned instead of slowly expanding into
    empty space when widening the iconview. It's also what the iconview did
    pre-refactoring.
    
    Note that for cases where natural width != minimum width, the cells
    might still expand and shrink back.

 gtk/gtkiconview.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 7aaf158..c891509 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -2777,7 +2777,8 @@ gtk_icon_view_layout (GtkIconView *icon_view)
   GtkIconViewPrivate *priv = icon_view->priv;
   GtkWidget *widget = GTK_WIDGET (icon_view);
   GList *items;
-  gint item_width;
+  gint min_item_width, max_item_width; /* These include item_padding */
+  gint item_width; /* this doesn't include item_padding */
   gint n_columns, n_rows, n_items;
   gint col, row;
   GtkRequestedSize *sizes;
@@ -2795,12 +2796,13 @@ gtk_icon_view_layout (GtkIconView *icon_view)
                                           &n_columns);
   n_rows = (n_items + n_columns - 1) / n_columns;
 
+  gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &min_item_width, &max_item_width);
+
   if (n_columns <= 1)
     {
       /* We might need vertical scrolling here */
-      gtk_icon_view_get_preferred_item_size (icon_view, GTK_ORIENTATION_HORIZONTAL, -1, &item_width, NULL);
-      item_width += 2 * priv->item_padding + 2 * priv->margin;
-      priv->width = MAX (item_width, gtk_widget_get_allocated_width (widget));
+      int min_width = min_item_width + 2 * priv->margin;
+      priv->width = MAX (min_width, gtk_widget_get_allocated_width (widget));
     }
   else
     {
@@ -2809,6 +2811,7 @@ gtk_icon_view_layout (GtkIconView *icon_view)
 
   item_width = (priv->width - 2 * priv->margin + priv->column_spacing) / n_columns;
   item_width -= priv->column_spacing;
+  item_width = MIN (item_width, max_item_width);
   item_width -= 2 * priv->item_padding;
 
   gtk_cell_area_context_reset (priv->cell_area_context);



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