[libhandy/wip/haecker-felix/flap-widget: 112/138] Implement allocate_content() func




commit 01ab0910e6c48e92f5f2f162a3f75aa9356070fe
Author: Felix Häcker <haeckerfelix gnome org>
Date:   Mon Jul 27 16:37:04 2020 +0200

    Implement allocate_content() func

 src/hdy-flap.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 3 deletions(-)
---
diff --git a/src/hdy-flap.c b/src/hdy-flap.c
index 7828d1bd..c1fe0965 100644
--- a/src/hdy-flap.c
+++ b/src/hdy-flap.c
@@ -200,8 +200,7 @@ get_flap_size (HdyFlap        *self,
   if (self->flap == NULL)
     return 0;
 
-  flap = hdy_flap_get_flap (self);
-  gtk_widget_get_preferred_size (flap, &flap_min_size, &flap_nat_size);
+  gtk_widget_get_preferred_size (hdy_flap_get_flap (self), &flap_min_size, &flap_nat_size);
 
   if (widget_orientation == GTK_ORIENTATION_HORIZONTAL) {
     if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -272,9 +271,58 @@ allocate_flap (HdyFlap       *self,
 
 static void
 allocate_content (HdyFlap       *self,
-                  GtkAllocation *widget_allocation)
+                  GtkAllocation *widget_alloc)
 {
+  GtkWidget *content = gtk_bin_get_child ((GtkBin*) self);
+  gint content_x = 0, content_y = 0;
+  GtkRequisition flap_min, flap_nat;
+  GtkRequisition content_min, content_nat;
+  GtkAllocation alloc;
 
+  if (self->flap != NULL) {
+    gtk_widget_get_preferred_size (self->flap, &flap_min, &flap_nat);
+  } else {
+      flap_min.height = 0;
+      flap_min.width = 0;
+  }
+
+  gtk_widget_get_preferred_size (content, &content_min, &content_nat);
+
+  if (self->orientation == GTK_ORIENTATION_HORIZONTAL){
+      int min = content_min.width + flap_min.width;
+      if (self->flap_mode == HDY_FLAP_MODE_AUTO)
+        self->overlay = widget_alloc-> width <= min;
+
+      if (self->flap_position == adjust_for_text_direction (self, GTK_PACK_START)){
+          content_x = widget_alloc->x + adjust_for_overlay (self, get_flap_size(self, widget_alloc, 
GTK_ORIENTATION_HORIZONTAL));
+          content_y = widget_alloc->y;
+      }
+      if (self->flap_position == adjust_for_text_direction (self, GTK_PACK_END)){
+          content_x = widget_alloc->x;
+          content_y = widget_alloc->y;
+      }
+  }
+
+  if (self->orientation == GTK_ORIENTATION_VERTICAL){
+      gint min = content_min.height + flap_min.height;
+      if (self->flap_mode == HDY_FLAP_MODE_AUTO) self->overlay = widget_alloc->height <= min;
+
+      if (self->flap_position == GTK_PACK_START){
+          content_x = widget_alloc->x;
+          content_y = widget_alloc->y + adjust_for_overlay (self, get_flap_size(self, widget_alloc, 
GTK_ORIENTATION_VERTICAL));
+      }
+      if (self->flap_position == GTK_PACK_END){
+          content_x = widget_alloc->x;
+          content_y = widget_alloc->y;
+      }
+  }
+
+  alloc.x = content_x;
+  alloc.y = content_y;
+  alloc.width = get_flap_size (self, widget_alloc, GTK_ORIENTATION_HORIZONTAL);
+  alloc.height = get_flap_size (self, widget_alloc, GTK_ORIENTATION_VERTICAL);
+
+  gtk_widget_size_allocate (content, &alloc);
 }
 
 static void


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