[libhandy/wip/haecker-felix/flap-widget: 116/138] Implement measure()




commit 0ea45eb91492960c8e3b5eb8856b390eaeab165e
Author: Felix Häcker <haeckerfelix gnome org>
Date:   Mon Jul 27 18:31:40 2020 +0200

    Implement measure()

 src/hdy-flap.c | 62 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index 4cc464f7..d4baab8b 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -150,24 +150,6 @@ hdy_flap_set_property (GObject      *object,
   }
 }
 
-/* This private method is prefixed by the call name because it will be a virtual
- * method in GTK 4.
- */
-static void
-hdy_flap_measure (GtkWidget      *widget,
-                  GtkOrientation  orientation,
-                  int             for_size,
-                  int            *minimum,
-                  int            *natural,
-                  int            *minimum_baseline,
-                  int            *natural_baseline)
-{
-  HdyFlap *self = HDY_FLAP (widget);
-  GtkBin *bin = GTK_BIN (widget);
-  GtkWidget *child;
-  gint child_size;
-}
-
 static gint
 adjust_for_overlay (HdyFlap *self,
                     gint     value)
@@ -190,6 +172,50 @@ adjust_for_text_direction (HdyFlap     *self,
   return pack_type;
 }
 
+/* This private method is prefixed by the call name because it will be a virtual
+ * method in GTK 4.
+ */
+static void
+hdy_flap_measure (GtkWidget      *widget,
+                  GtkOrientation  orientation,
+                  int             for_size,
+                  int            *minimum,
+                  int            *natural,
+                  int            *minimum_baseline,
+                  int            *natural_baseline)
+{
+  HdyFlap *self = HDY_FLAP (widget);
+  GtkWidget *content = gtk_bin_get_child ((GtkBin*) self);
+
+  gint content_min = 0, content_nat = 0;
+  gint flap_min = 0, flap_nat = 0;
+
+  if (orientation == GTK_ORIENTATION_VERTICAL){
+      if (content != NULL) gtk_widget_get_preferred_height (content, &content_min, &content_nat);
+      if (self->flap != NULL) gtk_widget_get_preferred_height (self->flap, &flap_min, &flap_nat);
+
+      if (self->orientation == GTK_ORIENTATION_VERTICAL && self->flap_mode != HDY_FLAP_MODE_AUTO){
+          *minimum = MAX (content_min + adjust_for_overlay (self, flap_min), flap_min);
+          *natural = MAX (content_nat + adjust_for_overlay (self, flap_nat), flap_nat);
+          return;
+      }
+  }
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL){
+      if (content != NULL) gtk_widget_get_preferred_width (content, &content_min, &content_nat);
+      if (self->flap != NULL) gtk_widget_get_preferred_width (self->flap, &flap_min, &flap_nat);
+
+      if (self->orientation == GTK_ORIENTATION_HORIZONTAL && self->flap_mode != HDY_FLAP_MODE_AUTO){
+          *minimum = MAX (content_min + adjust_for_overlay (self, flap_min), flap_min);
+          *natural = MAX (content_nat + adjust_for_overlay (self, flap_nat), flap_nat);
+          return;
+      }
+  }
+
+  *minimum = MAX (content_min, flap_min);
+  *natural = MAX (content_nat, flap_nat);
+}
+
 static gint
 get_flap_size (HdyFlap        *self,
                GtkAllocation  *widget_alloc,


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