[gtk+/wip/baedert/drawing: 293/371] Fix baselines wrt css values



commit 8692f2b4b3e6dc03d52921873b4d9e02f99adbca
Author: Timm Bäder <mail baedert org>
Date:   Tue Jun 27 13:27:58 2017 +0200

    Fix baselines wrt css values
    
    The reported minimum baseline is for the reported min height, but if the
    css min-height is greater than that, we need to account for that fact
    when saving the baseline.
    
    Since the reported baseline is relative to the widget's origin, we also
    need to add the top values for margin, border and padding to the
    reported baseline.

 gtk/gtksizerequest.c |   27 +++++++++++++++++++--------
 gtk/gtkwidget.c      |    1 -
 2 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index ea1b7c0..e1baaf1 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -155,6 +155,8 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
     {
       int adjusted_min, adjusted_natural;
       int adjusted_for_size = for_size;
+      int reported_min_size = 0;
+      int reported_nat_size = 0;
 
       style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
       get_box_margin (style, &margin);
@@ -180,7 +182,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
         {
           push_recursion_check (widget, orientation);
           widget_class->measure (widget, orientation, -1,
-                                 &min_size, &nat_size,
+                                 &reported_min_size, &reported_nat_size,
                                  &min_baseline, &nat_baseline);
           pop_recursion_check (widget, orientation);
         }
@@ -214,16 +216,14 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
           widget_class->measure (widget,
                                  orientation,
                                  adjusted_for_size,
-                                 &min_size, &nat_size,
+                                 &reported_min_size, &reported_nat_size,
                                  &min_baseline, &nat_baseline);
           pop_recursion_check (widget, orientation);
 
         }
 
-      /* TODO: Baselines */
-
-      min_size = MAX (0, MAX (min_size, css_min_size)) + css_extra_size;
-      nat_size = MAX (0, MAX (nat_size, css_min_size)) + css_extra_size;
+      min_size = MAX (0, MAX (reported_min_size, css_min_size)) + css_extra_size;
+      nat_size = MAX (0, MAX (reported_nat_size, css_min_size)) + css_extra_size;
 
       if (G_UNLIKELY (min_size > nat_size))
         {
@@ -306,8 +306,19 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
              nat_baseline = -1;
            }
          else
-            gtk_widget_adjust_baseline_request (widget, &min_baseline, &nat_baseline);
-       }
+            {
+              if (css_min_size > reported_min_size)
+                {
+                  min_baseline += (css_min_size - reported_min_size) / 2;
+                  nat_baseline += (css_min_size - reported_min_size) / 2;
+                }
+
+              min_baseline += margin.top + border.top + padding.top;
+              nat_baseline += margin.top + border.top + padding.top;
+
+              gtk_widget_adjust_baseline_request (widget, &min_baseline, &nat_baseline);
+            }
+        }
 
       _gtk_size_request_cache_commit (cache,
                                       orientation,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c477520..81f6fdd 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5557,7 +5557,6 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
                            margin.right + border.right + padding.right;
   real_allocation.height -= margin.top + border.top + padding.top +
                             margin.bottom + border.bottom + padding.bottom;
-  /* TODO: Baseline! */
 
   priv->allocated_baseline = baseline;
   if (g_signal_has_handler_pending (widget, widget_signals[SIZE_ALLOCATE], 0, FALSE))


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