[gtk+/wip/baedert/drawing: 46/156] sizerequest: Honor css min size



commit 2c76de5545e0d7e514f813c6b6b492ecfd1e6b7c
Author: Timm Bäder <mail baedert org>
Date:   Wed May 3 19:23:35 2017 +0200

    sizerequest: Honor css min size

 gtk/gtksizerequest.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index 0f18d6d..811ce80 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -29,6 +29,9 @@
 #include "gtksizegroup-private.h"
 #include "gtksizerequestcacheprivate.h"
 #include "gtkwidgetprivate.h"
+#include "gtkcssnodeprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+#include "gtkbutton.h"
 
 
 #ifdef G_ENABLE_CONSISTENCY_CHECKS
@@ -81,6 +84,48 @@ pop_recursion_check (GtkWidget       *widget,
 #define pop_recursion_check(widget, orientation)
 #endif /* G_ENABLE_CONSISTENCY_CHECKS */
 
+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);
+}
+
 static void
 gtk_widget_query_size_for_orientation (GtkWidget        *widget,
                                        GtkOrientation    orientation,
@@ -280,6 +325,39 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
                                      nat_baseline);
     }
 
+
+  /* We commit the requested size *without css values applied* into the cache! */
+  {
+    GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
+    GtkBorder margin, border, padding;
+    int css_min_size;
+    int extra_size;
+
+    get_box_margin (style, &margin);
+    get_box_border (style, &border);
+    get_box_padding (style, &padding);
+
+    if (orientation == GTK_ORIENTATION_HORIZONTAL)
+      {
+        extra_size = margin.left + margin.right + border.left + border.right + padding.left + padding.right;
+        css_min_size = get_number (style, GTK_CSS_PROPERTY_MIN_WIDTH);
+      }
+    else
+      {
+        extra_size = margin.top + margin.bottom + border.top + border.bottom + padding.top + padding.bottom;
+        css_min_size = get_number (style, GTK_CSS_PROPERTY_MIN_HEIGHT);
+      }
+    min_size = MAX (min_size, css_min_size);
+    nat_size = MAX (nat_size, css_min_size);
+
+    min_size += extra_size;
+    nat_size += extra_size;
+
+    /* TODO: Baselines */
+    /* TODO: The GtkCssGadget code has a warning for for_size < min_for_size
+     *       where min_for_size depends on the css values */
+  }
+
   if (minimum_size)
     *minimum_size = min_size;
 


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