[gtk+/native-layout] GtkAlignment now tries to allocate natural size to the child if available and does the height-for-wi



commit 3a9ab87489d7396acfec49ce611e85cf9003f9fe
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Apr 20 01:22:31 2010 -0400

    GtkAlignment now tries to allocate natural size to the child if available and does the height-for-width calculation depending on allocation.

 gtk/gtkalignment.c |   40 +++++++++++++++++++++++++++-------------
 1 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkalignment.c b/gtk/gtkalignment.c
index 7e879ca..73905f8 100644
--- a/gtk/gtkalignment.c
+++ b/gtk/gtkalignment.c
@@ -423,7 +423,6 @@ gtk_alignment_size_allocate (GtkWidget     *widget,
   GtkAlignment *alignment;
   GtkBin *bin;
   GtkAllocation child_allocation;
-  GtkRequisition child_requisition;
   gint width, height;
   gint border_width;
   gint padding_horizontal, padding_vertical;
@@ -439,8 +438,9 @@ gtk_alignment_size_allocate (GtkWidget     *widget,
   if (bin->child && gtk_widget_get_visible (bin->child))
     {
       GtkExtendedLayout *layout = GTK_EXTENDED_LAYOUT (bin->child);
-
-      gtk_extended_layout_get_desired_size (layout, NULL, &child_requisition);
+      gint child_nat_width;
+      gint child_nat_height;
+      gint child_width, child_height;
 
       border_width = GTK_CONTAINER (alignment)->border_width;
 
@@ -451,22 +451,36 @@ gtk_alignment_size_allocate (GtkWidget     *widget,
       width  = MAX (1, allocation->width - padding_horizontal - 2 * border_width);
       height = MAX (1, allocation->height - padding_vertical - 2 * border_width);
 
-      if (child_requisition.width > width)
-        gtk_extended_layout_get_height_for_width (layout, width, NULL,
-                                                  &child_requisition.height);
-      else if (child_requisition.height > height)
-        gtk_extended_layout_get_width_for_height (layout, height, NULL,
-                                                  &child_requisition.width);
+      if (gtk_extended_layout_is_height_for_width (layout))
+	{
+	  gtk_extended_layout_get_desired_width (layout, NULL, &child_nat_width);
+
+	  child_width = MIN (width, child_nat_width);
+
+	  gtk_extended_layout_get_height_for_width (layout, child_width, NULL, &child_nat_height);
+
+	  child_height = MIN (height, child_nat_height);
+	}
+      else
+	{
+	  gtk_extended_layout_get_desired_height (layout, NULL, &child_nat_height);
+
+	  child_height = MIN (height, child_nat_height);
+
+	  gtk_extended_layout_get_width_for_height (layout, child_height, NULL, &child_nat_width);
+
+	  child_width = MIN (width, child_nat_width);
+	}
 
-      if (width > child_requisition.width)
-	child_allocation.width = (child_requisition.width *
+      if (width > child_width)
+	child_allocation.width = (child_width *
 				  (1.0 - alignment->xscale) +
 				  width * alignment->xscale);
       else
 	child_allocation.width = width;
 
-      if (height > child_requisition.height)
-	child_allocation.height = (child_requisition.height *
+      if (height > child_height)
+	child_allocation.height = (child_height *
 				   (1.0 - alignment->yscale) +
 				   height * alignment->yscale);
       else



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