[gtk/min-size-revealer-master] gtkrevealer: Support minimum size of child



commit f467ff28c5e2b2d4991fca784a47182a16979ab6
Author: Carlos Soriano <csoriano redhat com>
Date:   Fri Aug 31 16:29:02 2018 +0200

    gtkrevealer: Support minimum size of child

 gtk/gtkrevealer.c | 60 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkrevealer.c b/gtk/gtkrevealer.c
index 49aa81458e..50769a6c32 100644
--- a/gtk/gtkrevealer.c
+++ b/gtk/gtkrevealer.c
@@ -301,51 +301,61 @@ gtk_revealer_get_child_allocation (GtkRevealer         *revealer,
   GtkRevealerPrivate *priv = gtk_revealer_get_instance_private (revealer);
   GtkWidget *child;
   GtkRevealerTransitionType transition;
+  gint minimum_width, natural_width, minimum_height, natural_height;
 
   g_return_if_fail (revealer != NULL);
   g_return_if_fail (allocation != NULL);
 
+  child = gtk_bin_get_child (GTK_BIN (revealer));
   child_allocation->x = 0;
   child_allocation->y = 0;
-  child_allocation->width = 0;
-  child_allocation->height = 0;
-
-  child = gtk_bin_get_child (GTK_BIN (revealer));
-  if (child != NULL && gtk_widget_get_visible (child))
+  child_allocation->width = allocation->width;
+  child_allocation->height = allocation->height;
+  if (child != NULL && priv->current_pos != 1.0 && 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_measure (child, GTK_ORIENTATION_HORIZONTAL,
-                            MAX (0, allocation->height),
-                            NULL, &child_allocation->width, NULL, NULL);
-      else
-        gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL,
-                            MAX (0, allocation->width),
-                            NULL, &child_allocation->height, NULL, NULL);
-
-      child_allocation->width = MAX (child_allocation->width, allocation->width);
-      child_allocation->height = MAX (child_allocation->height, allocation->height);
-
       switch (transition)
         {
+        case GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT:
+          /* allocation * (1 / priv->current_post) is used so that we allocate a
+           * size where the animation progress is taken into account, so the child
+           * can adapt properly between its minimum and natural size.
+           */
+          gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL,
+                              allocation->height,
+                              &minimum_width, &natural_width, NULL, NULL);
+          child_allocation->width = MAX (minimum_width,
+                                         allocation->width * priv->current_pos);
+          child_allocation->x = allocation->width - child_allocation->width;
+          break;
         case GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT:
-            child_allocation->x = - child_allocation->width * (1 - priv->current_pos);
+          gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL,
+                              allocation->height,
+                              &minimum_width, &natural_width, NULL, NULL);
+          child_allocation->width = MAX (minimum_width,
+                                         allocation->width * priv->current_pos);
           break;
         case GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN:
-            child_allocation->y = - child_allocation->height * (1 - priv->current_pos);
+          gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL,
+                              allocation->width,
+                              &minimum_height, &natural_height, NULL, NULL);
+          child_allocation->height = MAX (minimum_height,
+                                          allocation->height * priv->current_pos);
+          child_allocation->y = allocation->height - child_allocation->height;
+          break;
+        case GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP:
+          gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL,
+                              allocation->width,
+                              &minimum_height, &natural_height, NULL, NULL);
+          child_allocation->height = MAX (minimum_height,
+                                          allocation->height * priv->current_pos);
           break;
-
         case GTK_REVEALER_TRANSITION_TYPE_NONE:
         case GTK_REVEALER_TRANSITION_TYPE_CROSSFADE:
-        case GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT:
-        case GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP:
         default:
           break;
         }
     }
-
 }
 
 static void


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