[gtk+/wip/baedert/drawing: 138/301] widget: Pass content allocation to size-allocate vfunc



commit 62e2aaf7389b4a6a9e9ee14cc6219ce8d0798d9a
Author: Timm Bäder <mail baedert org>
Date:   Wed May 3 19:45:33 2017 +0200

    widget: Pass content allocation to size-allocate vfunc

 gtk/gtkwidget.c |  109 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 65 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 243277e..b0f125d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5340,6 +5340,48 @@ gtk_widget_invalidate_widget_windows (GtkWidget      *widget,
                                       invalidate_predicate, widget);
 }
 
+static gint
+get_number (GtkCssStyle *style,
+            guint        property)
+{
+  double d = _gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100);
+
+  if (d < 1)
+    return ceil (d);
+  else
+    return floor (d);
+}
+
+static void
+get_box_margin (GtkCssStyle *style,
+                GtkBorder   *margin)
+{
+  margin->top = get_number (style, GTK_CSS_PROPERTY_MARGIN_TOP);
+  margin->left = get_number (style, GTK_CSS_PROPERTY_MARGIN_LEFT);
+  margin->bottom = get_number (style, GTK_CSS_PROPERTY_MARGIN_BOTTOM);
+  margin->right = get_number (style, GTK_CSS_PROPERTY_MARGIN_RIGHT);
+}
+
+static void
+get_box_border (GtkCssStyle *style,
+                GtkBorder   *border)
+{
+  border->top = get_number (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH);
+  border->left = get_number (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH);
+  border->bottom = get_number (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH);
+  border->right = get_number (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH);
+}
+
+static void
+get_box_padding (GtkCssStyle *style,
+                 GtkBorder   *border)
+{
+  border->top = get_number (style, GTK_CSS_PROPERTY_PADDING_TOP);
+  border->left = get_number (style, GTK_CSS_PROPERTY_PADDING_LEFT);
+  border->bottom = get_number (style, GTK_CSS_PROPERTY_PADDING_BOTTOM);
+  border->right = get_number (style, GTK_CSS_PROPERTY_PADDING_RIGHT);
+}
+
 /**
  * gtk_widget_size_allocate_with_baseline:
  * @widget: a #GtkWidget
@@ -5378,6 +5420,8 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
   gint natural_width, natural_height, dummy;
   gint min_width, min_height;
   gint old_baseline;
+  GtkCssStyle *style;
+  GtkBorder margin, border, padding;
 
   priv = widget->priv;
 
@@ -5514,8 +5558,8 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
   if (real_allocation.width < 0 || real_allocation.height < 0)
     {
       g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
-                real_allocation.width,
-                real_allocation.height);
+                 real_allocation.width,
+                 real_allocation.height);
     }
 
   real_allocation.width = MAX (real_allocation.width, 1);
@@ -5530,6 +5574,25 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
   if (!alloc_needed && !size_changed && !position_changed && !baseline_changed)
     goto out;
 
+
+  /* Set the widget allocation to real_allocation now, pass the smaller allocation to the vfunc */
+  gtk_widget_set_allocation (widget, &real_allocation);
+
+  style = gtk_css_node_get_style (priv->cssnode);
+  get_box_margin (style, &margin);
+  get_box_border (style, &border);
+  get_box_padding (style, &padding);
+
+  /* Since gtk_widget_measure does it for us, we can be sure here that
+   * the given alloaction is large enough for the css margin/bordder/padding */
+  real_allocation.x += margin.left + border.left + padding.left;
+  real_allocation.y += margin.top + border.top + padding.top;
+  real_allocation.width -= margin.left + border.left + padding.left +
+                           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))
     g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
@@ -15265,48 +15328,6 @@ gtk_widget_reset_controllers (GtkWidget *widget)
     }
 }
 
-static gint
-get_number (GtkCssStyle *style,
-            guint        property)
-{
-  double d = _gtk_css_number_value_get (gtk_css_style_get_value (style, property), 100);
-
-  if (d < 1)
-    return ceil (d);
-  else
-    return floor (d);
-}
-
-static void
-get_box_margin (GtkCssStyle *style,
-                GtkBorder   *margin)
-{
-  margin->top = get_number (style, GTK_CSS_PROPERTY_MARGIN_TOP);
-  margin->left = get_number (style, GTK_CSS_PROPERTY_MARGIN_LEFT);
-  margin->bottom = get_number (style, GTK_CSS_PROPERTY_MARGIN_BOTTOM);
-  margin->right = get_number (style, GTK_CSS_PROPERTY_MARGIN_RIGHT);
-}
-
-static void
-get_box_border (GtkCssStyle *style,
-                GtkBorder   *border)
-{
-  border->top = get_number (style, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH);
-  border->left = get_number (style, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH);
-  border->bottom = get_number (style, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH);
-  border->right = get_number (style, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH);
-}
-
-static void
-get_box_padding (GtkCssStyle *style,
-                 GtkBorder   *border)
-{
-  border->top = get_number (style, GTK_CSS_PROPERTY_PADDING_TOP);
-  border->left = get_number (style, GTK_CSS_PROPERTY_PADDING_LEFT);
-  border->bottom = get_number (style, GTK_CSS_PROPERTY_PADDING_BOTTOM);
-  border->right = get_number (style, GTK_CSS_PROPERTY_PADDING_RIGHT);
-}
-
 void
 gtk_widget_snapshot (GtkWidget   *widget,
                      GtkSnapshot *snapshot)


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