[gtk+/wip/csoriano/pathbar-prototype: 65/68] gtkhidingbox: fix wrong extra space distribution



commit 1a438e919af8a720a546b432d9836732aad9bef9
Author: Carlos Soriano <csoriano gnome org>
Date:   Fri Nov 6 19:08:34 2015 +0100

    gtkhidingbox: fix wrong extra space distribution
    
    It was using the whole allocation to distribute the space,
    instead of the actual extra space.

 gtk/gtkhidingbox.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkhidingbox.c b/gtk/gtkhidingbox.c
index af5c89d..55a2873 100644
--- a/gtk/gtkhidingbox.c
+++ b/gtk/gtkhidingbox.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include "gtkhidingboxprivate.h"
+#include "gtkwidgetprivate.h"
 #include "gtkintl.h"
 #include "gtksizerequest.h"
 #include "gtkbuildable.h"
@@ -168,6 +169,7 @@ gtk_hiding_box_forall (GtkContainer *container,
 static void
 update_children_visibility (GtkHidingBox     *box,
                             GtkRequestedSize *sizes,
+                            gint             *children_size,
                             gint             *n_visible_children,
                             gint             *n_visible_children_expanding,
                             GtkAllocation    *allocation)
@@ -177,12 +179,12 @@ update_children_visibility (GtkHidingBox     *box,
   GList *child;
   GtkRequestedSize *sizes_temp;
   gint i;
-  gint children_size = -priv->spacing;
   GList *children;
   gboolean allocate_more_children = TRUE;
 
   *n_visible_children = 0;
   *n_visible_children_expanding = 0;
+  *children_size = -priv->spacing;
   children = g_list_copy (priv->children);
   sizes_temp = g_newa (GtkRequestedSize, g_list_length (priv->children));
   if (priv->hide_direction == GTK_DIR_LEFT)
@@ -214,10 +216,10 @@ update_children_visibility (GtkHidingBox     *box,
                  sizes_temp[i].natural_size, sizes_temp[i].minimum_size,
                  allocation->height);
 
-      children_size += sizes_temp[i].minimum_size + priv->spacing;
+      *children_size += sizes_temp[i].minimum_size + priv->spacing;
       sizes_temp[i].data = child_widget;
 
-      if (children_size > allocation->width)
+      if (*children_size > allocation->width)
         {
           gtk_widget_set_child_visible (child_widget, FALSE);
           allocate_more_children = FALSE;
@@ -256,8 +258,7 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
   GtkTextDirection direction;
   GtkAllocation child_allocation;
   GtkRequestedSize *sizes;
-  gint size = 0;
-  gint extra = 0;
+  gint extra_space = 0;
   gint x = 0;
   gint i;
   GList *child;
@@ -265,12 +266,13 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
   gint spacing = priv->spacing;
   gint n_visible_children = 0;
   gint n_visible_children_expanding = 0;
+  gint children_size = 0;
   GtkAllocation clip, child_clip;
 
   gtk_widget_set_allocation (widget, allocation);
 
   sizes = g_newa (GtkRequestedSize, g_list_length (priv->children));
-  update_children_visibility (box, sizes, &n_visible_children,
+  update_children_visibility (box, sizes, &children_size, &n_visible_children,
                               &n_visible_children_expanding, allocation);
 
   /* If there is no visible child, simply return. */
@@ -280,12 +282,12 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
   direction = gtk_widget_get_direction (widget);
 
   /* Bring children up to allocation width first */
-  size = gtk_distribute_natural_allocation (MAX (0, allocation->width), n_visible_children, sizes);
+  extra_space = allocation->width - (n_visible_children - 1) * spacing - children_size;
+  extra_space = gtk_distribute_natural_allocation (MAX (0, extra_space), n_visible_children, sizes);
   /* Only now we can subtract the spacings */
-  size -= (n_visible_children - 1) * spacing;
 
   if (n_visible_children > 1)
-    extra = size / MAX (1, n_visible_children_expanding);
+    extra_space = extra_space / MAX (1, n_visible_children_expanding);
 
   x = allocation->x;
   for (i = 0, child = priv->children; child != NULL; child = child->next)
@@ -298,7 +300,7 @@ gtk_hiding_box_size_allocate (GtkWidget     *widget,
       child_allocation.x = x;
       child_allocation.y = allocation->y;
       if (gtk_widget_get_hexpand (child_widget))
-        child_allocation.width = sizes[i].minimum_size + extra;
+        child_allocation.width = sizes[i].minimum_size + extra_space;
       else
         child_allocation.width = sizes[i].minimum_size;
 


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