[libadwaita/wip/exalm/squeezer-fix: 4/5] squeezer: Make layout work with vertical orientation




commit 1d1adb5f93055c2d3eb4d013ab35e6041d33f585
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Apr 12 13:06:49 2021 +0500

    squeezer: Make layout work with vertical orientation
    
    Also properly use xalign/yalign instead of halign/valign.
    
    Fixes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/121

 src/adw-squeezer.c | 50 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/src/adw-squeezer.c b/src/adw-squeezer.c
index e0eaceb..9e2ac3c 100644
--- a/src/adw-squeezer.c
+++ b/src/adw-squeezer.c
@@ -891,12 +891,21 @@ adw_squeezer_size_allocate (GtkWidget *widget,
   if (self->last_visible_child) {
     int min, nat;
 
-    gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_HORIZONTAL,
-                        -1, &min, &nat, NULL, NULL);
-    child_allocation.width = MAX (min, width);
-    gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_VERTICAL,
-                        child_allocation.width, &min, &nat, NULL, NULL);
-    child_allocation.height = MAX (min, height);
+    if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
+      gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_HORIZONTAL,
+                          -1, &min, &nat, NULL, NULL);
+      child_allocation.width = MAX (min, width);
+      gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_VERTICAL,
+                          child_allocation.width, &min, &nat, NULL, NULL);
+      child_allocation.height = MAX (min, height);
+    } else {
+      gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_VERTICAL,
+                          -1, &min, &nat, NULL, NULL);
+      child_allocation.height = MAX (min, height);
+      gtk_widget_measure (self->last_visible_child->widget, GTK_ORIENTATION_HORIZONTAL,
+                          child_allocation.height, &min, &nat, NULL, NULL);
+      child_allocation.width = MAX (min, width);
+    }
 
     gtk_widget_size_allocate (self->last_visible_child->widget, &child_allocation, -1);
   }
@@ -905,23 +914,26 @@ adw_squeezer_size_allocate (GtkWidget *widget,
   child_allocation.height = height;
 
   if (self->visible_child) {
-    int min, nat;
-    GtkAlign valign;
+    int min;
+
+    gtk_widget_measure (self->visible_child->widget, GTK_ORIENTATION_HORIZONTAL,
+                        height, &min, NULL, NULL, NULL);
+    child_allocation.width = MAX (child_allocation.width, min);
 
     gtk_widget_measure (self->visible_child->widget, GTK_ORIENTATION_VERTICAL,
-                        width, &min, &nat, NULL, NULL);
-
-    if (self->interpolate_size) {
-      valign = gtk_widget_get_valign (self->visible_child->widget);
-      child_allocation.height = MAX (nat, height);
-      if (valign == GTK_ALIGN_END &&
-          child_allocation.height > height)
-        child_allocation.y -= nat - height;
-      else if (valign == GTK_ALIGN_CENTER &&
-               child_allocation.height > height)
-        child_allocation.y -= (nat - height) / 2;
+                        width, &min, NULL, NULL, NULL);
+    child_allocation.height = MAX (child_allocation.height, min);
+
+    if (child_allocation.width > width) {
+      if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+        child_allocation.x = (width - child_allocation.width) * (1 - self->xalign);
+      else
+        child_allocation.x = (width - child_allocation.width) * self->xalign;
     }
 
+    if (child_allocation.height > height)
+      child_allocation.y = (height - child_allocation.height) * self->yalign;
+
     gtk_widget_size_allocate (self->visible_child->widget, &child_allocation, -1);
   }
 }


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