[gtk+/wip/csoriano/pathbar-bin-view-window: 2/2] gtkrevealer: support minimum size of child



commit e1dc830e9eefc850962b5e7b700da3611600fcd8
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Jun 15 18:22:32 2016 +0200

    gtkrevealer: support minimum size of child
    
    GtkRevealer always allocates the natural size of the child so the
    bin_window can take care of the animation with the full allocation of
    the child.
    
    However when GtkRevealer allocates the child doesn't take into
    account the minimum size of the child. On the other hand it does take
    into account the minimum size of the child when reporting the preferred
    size to the parent of the GtkRevealer.
    This behaviour clips the child of the GtkRevealer if the parent
    allocates less than the natural size.
    
    To fix this inconsistency, the patch makes the child adapt the
    allocation of the GtkRevealer as long as it's not under the minimum
    size of the child.
    
    Note that it no longer takes into account the animation type to report
    the child size. I don't think that part is necessary.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767722

 gtk/gtkrevealer.c |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index b23f66a..3d7e4d8 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -308,9 +308,11 @@ gtk_revealer_get_child_allocation (GtkRevealer   *revealer,
                                    GtkAllocation *child_allocation)
 {
   GtkWidget *child;
-  GtkRevealerTransitionType transition;
   GtkBorder padding;
   gint vertical_padding, horizontal_padding;
+  GtkRequisition minimum_size;
+  GtkRequisition natural_size;
+
 
   g_return_if_fail (revealer != NULL);
   g_return_if_fail (allocation != NULL);
@@ -327,19 +329,21 @@ gtk_revealer_get_child_allocation (GtkRevealer   *revealer,
 
   child = gtk_bin_get_child (GTK_BIN (revealer));
   if (child != NULL && gtk_widget_get_visible (child))
-    {
-      transition = effective_transition (revealer);
-      if (transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT ||
-          transition == GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT)
-        gtk_widget_get_preferred_width_for_height (child, MAX (0, allocation->height - vertical_padding), 
NULL,
-                                                   &child_allocation->width);
-      else
-        gtk_widget_get_preferred_height_for_width (child, MAX (0, allocation->width - horizontal_padding), 
NULL,
-                                                   &child_allocation->height);
-    }
+    gtk_widget_get_preferred_size (child, &minimum_size, &natural_size);
+
+  if (natural_size.width > allocation->width - horizontal_padding)
+      child_allocation->width = CLAMP (allocation->width - horizontal_padding,
+                                       minimum_size.width,
+                                       natural_size.width);
+  else
+      child_allocation->width = allocation->width - horizontal_padding;
 
-  child_allocation->width = MAX (child_allocation->width, allocation->width - horizontal_padding);
-  child_allocation->height = MAX (child_allocation->height, allocation->height - vertical_padding);
+  if (natural_size.height > allocation->height - vertical_padding)
+      child_allocation->height = CLAMP (allocation->height - vertical_padding,
+                                        minimum_size.height,
+                                        natural_size.height);
+  else
+      child_allocation->height = allocation->height - vertical_padding;
 }
 
 static void


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