[libhandy] css: Add hdy_css_adjust_for_size()



commit 6363314012d1bbea59a089768544af52ddf36deb
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Feb 9 20:40:56 2021 +0500

    css: Add hdy_css_adjust_for_size()

 src/hdy-css-private.h |  4 ++++
 src/hdy-css.c         | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
---
diff --git a/src/hdy-css-private.h b/src/hdy-css-private.h
index daaefdc6..84388bda 100644
--- a/src/hdy-css-private.h
+++ b/src/hdy-css-private.h
@@ -14,6 +14,10 @@
 
 G_BEGIN_DECLS
 
+gint hdy_css_adjust_for_size (GtkWidget      *widget,
+                              GtkOrientation  orientation,
+                              gint            for_size);
+
 void hdy_css_measure (GtkWidget      *widget,
                       GtkOrientation  orientation,
                       gint           *minimum,
diff --git a/src/hdy-css.c b/src/hdy-css.c
index f01a8763..fc336060 100644
--- a/src/hdy-css.c
+++ b/src/hdy-css.c
@@ -8,6 +8,40 @@
 
 #include "hdy-css-private.h"
 
+gint
+hdy_css_adjust_for_size (GtkWidget      *widget,
+                         GtkOrientation  orientation,
+                         gint            for_size)
+{
+  GtkStyleContext *style_context = gtk_widget_get_style_context (widget);
+  GtkStateFlags state_flags = gtk_widget_get_state_flags (widget);
+  GtkBorder border, margin, padding;
+  gint css_width, css_height;
+
+  if (for_size < 0)
+    return -1;
+
+  /* Manually apply minimum sizes, the border, the padding and the margin as we
+   * can't use the private GtkGagdet.
+   */
+  gtk_style_context_get (style_context, state_flags,
+                         "min-width", &css_width,
+                         "min-height", &css_height,
+                         NULL);
+  gtk_style_context_get_border (style_context, state_flags, &border);
+  gtk_style_context_get_margin (style_context, state_flags, &margin);
+  gtk_style_context_get_padding (style_context, state_flags, &padding);
+
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
+    return MAX (for_size, css_width) -
+           border.left - margin.left - padding.left +
+           border.right - margin.right - padding.right;
+  else
+    return MAX (for_size, css_height) -
+           border.top - margin.top - padding.top +
+           border.bottom - margin.bottom - padding.bottom;
+}
+
 void
 hdy_css_measure (GtkWidget      *widget,
                  GtkOrientation  orientation,


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