[gtk+/center-box: 4/7] center box: handle missing start or end widgets



commit 3dc7e71c32ea16542266390ad9fd05e2174c2429
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 3 13:17:19 2017 -0400

    center box: handle missing start or end widgets

 gtk/gtkcenterbox.c |  114 +++++++++++++++++++++++++++++++--------------------
 1 files changed, 69 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c
index 49f8e67..3a13b0d 100644
--- a/gtk/gtkcenterbox.c
+++ b/gtk/gtkcenterbox.c
@@ -47,22 +47,16 @@ gtk_center_box_measure (GtkWidget      *widget,
   GtkCenterBox *self = GTK_CENTER_BOX (widget);
   int min, nat, min_baseline, nat_baseline;
 
-  gtk_widget_measure (self->start_widget,
-                      orientation,
-                      for_size,
-                      minimum, natural,
-                      minimum_baseline, natural_baseline);
+  *minimum = *natural = 0;
 
-  if (self->center_widget)
+  if (self->start_widget)
     {
-      gtk_widget_measure (self->center_widget,
+      gtk_widget_measure (self->start_widget,
                           orientation,
                           for_size,
                           &min, &nat,
                           &min_baseline, &nat_baseline);
 
-      /* XXX How are baselines even handled? */
-
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
         {
           *minimum = *minimum + min;
@@ -75,23 +69,45 @@ gtk_center_box_measure (GtkWidget      *widget,
         }
     }
 
-  gtk_widget_measure (self->end_widget,
-                      orientation,
-                      for_size,
-                      &min, &nat,
-                      &min_baseline, &nat_baseline);
-
-  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+  if (self->center_widget)
     {
-      *minimum = *minimum + min;
-      *natural = *natural + nat;
+      gtk_widget_measure (self->center_widget,
+                          orientation,
+                          for_size,
+                          &min, &nat,
+                          &min_baseline, &nat_baseline);
+
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
+        {
+          *minimum = *minimum + min;
+          *natural = *natural + nat;
+        }
+      else /* GTK_ORIENTATION_VERTICAL */
+        {
+          *minimum = MAX (*minimum, min);
+          *natural = MAX (*minimum, nat);
+        }
     }
-  else /* GTK_ORIENTATION_VERTICAL */
+
+  if (self->end_widget)
     {
-      *minimum = MAX (*minimum, min);
-      *natural = MAX (*minimum, nat);
-    }
+      gtk_widget_measure (self->end_widget,
+                          orientation,
+                          for_size,
+                          &min, &nat,
+                          &min_baseline, &nat_baseline);
 
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
+        {
+          *minimum = *minimum + min;
+          *natural = *natural + nat;
+        }
+      else /* GTK_ORIENTATION_VERTICAL */
+        {
+          *minimum = MAX (*minimum, min);
+          *natural = MAX (*minimum, nat);
+        }
+    }
 }
 
 static void
@@ -102,38 +118,44 @@ gtk_center_box_size_allocate (GtkWidget     *widget,
   GtkAllocation child_allocation;
   GtkAllocation clip = *allocation;
   GtkAllocation child_clip;
-  int start_size, end_size;
+  int start_size = 0;
+  int end_size = 0;
   int min, nat;
 
   GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
 
   /* TODO: Allocate natural sizes if possible? */
 
-  /* Start Box */
-  gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
-                      allocation->height,
-                      &min, &nat, NULL, NULL);
-  child_allocation.x = allocation->x;
   child_allocation.y = allocation->y;
-  child_allocation.width = min;
   child_allocation.height = allocation->height;
 
-  gtk_widget_size_allocate (self->start_widget, &child_allocation);
-  gtk_widget_get_clip (self->start_widget, &child_clip);
-  gdk_rectangle_union (&clip, &clip, &child_clip);
-  start_size = child_allocation.width;
+  if (self->start_widget)
+    {
+      gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
+                          allocation->height,
+                          &min, &nat, NULL, NULL);
+      child_allocation.x = allocation->x;
+      child_allocation.width = min;
+
+      gtk_widget_size_allocate (self->start_widget, &child_allocation);
+      gtk_widget_get_clip (self->start_widget, &child_clip);
+      gdk_rectangle_union (&clip, &clip, &child_clip);
+      start_size = child_allocation.width;
+    }
 
-  /* End Box */
-  gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
-                      allocation->height,
-                      &min, &nat, NULL, NULL);
-  child_allocation.x = allocation->x + allocation->width - min;
-  child_allocation.width = min;
+  if (self->end_widget)
+    {
+      gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
+                          allocation->height,
+                          &min, &nat, NULL, NULL);
+      child_allocation.x = allocation->x + allocation->width - min;
+      child_allocation.width = min;
 
-  gtk_widget_size_allocate (self->end_widget, &child_allocation);
-  gtk_widget_get_clip (self->end_widget, &child_clip);
-  gdk_rectangle_union (&clip, &clip, &child_clip);
-  end_size = child_allocation.width;
+      gtk_widget_size_allocate (self->end_widget, &child_allocation);
+      gtk_widget_get_clip (self->end_widget, &child_clip);
+      gdk_rectangle_union (&clip, &clip, &child_clip);
+      end_size = child_allocation.width;
+    }
 
   /* Center Widget */
   if (self->center_widget)
@@ -166,12 +188,14 @@ gtk_center_box_snapshot (GtkWidget   *widget,
 {
   GtkCenterBox *self = GTK_CENTER_BOX (widget);
 
-  gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
+  if (self->start_widget)
+    gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
 
   if (self->center_widget)
     gtk_widget_snapshot_child (widget, self->center_widget, snapshot);
 
-  gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
+  if (self->end_widget)
+    gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
 }
 
 static void


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