[libhandy] Add CSS sizing helpers for measure() and size_allocate()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] Add CSS sizing helpers for measure() and size_allocate()
- Date: Wed, 5 Aug 2020 17:19:59 +0000 (UTC)
commit b1678f2b3c570ef7d1f1931dcc884d5b7ec748b0
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Aug 5 14:47:15 2020 +0200
Add CSS sizing helpers for measure() and size_allocate()
The hdy_css_measure() and hdy_css_size_allocate() will help properly
apply CSS size properties.
doc/meson.build | 1 +
src/hdy-css-private.h | 25 ++++++++++++++++++
src/hdy-css.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
4 files changed, 100 insertions(+)
---
diff --git a/doc/meson.build b/doc/meson.build
index dcb7c7ac..eeab57a4 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -8,6 +8,7 @@ private_headers = [
'gtk-window-private.h',
'hdy-animation-private.h',
'hdy-carousel-box-private.h',
+ 'hdy-css-private.h',
'hdy-enums.h',
'hdy-enums-private.h',
'hdy-main-private.h',
diff --git a/src/hdy-css-private.h b/src/hdy-css-private.h
new file mode 100644
index 00000000..d8190b57
--- /dev/null
+++ b/src/hdy-css-private.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#pragma once
+
+#if !defined(_HANDY_INSIDE) && !defined(HANDY_COMPILATION)
+#error "Only <handy.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+void hdy_css_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimum,
+ gint *natural);
+
+void hdy_css_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+
+G_END_DECLS
diff --git a/src/hdy-css.c b/src/hdy-css.c
new file mode 100644
index 00000000..daae8edc
--- /dev/null
+++ b/src/hdy-css.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#include "config.h"
+
+#include "hdy-css-private.h"
+
+void
+hdy_css_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ gint *minimum,
+ gint *natural)
+{
+ 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;
+
+ /* 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_VERTICAL) {
+ *minimum = MAX (*minimum, css_height) +
+ border.top + margin.top + padding.top +
+ border.bottom + margin.bottom + padding.bottom;
+ *natural = MAX (*natural, css_height) +
+ border.top + margin.top + padding.top +
+ border.bottom + margin.bottom + padding.bottom;
+ } else {
+ *minimum = MAX (*minimum, css_width) +
+ border.left + margin.left + padding.left +
+ border.right + margin.right + padding.right;
+ *natural = MAX (*natural, css_width) +
+ border.left + margin.left + padding.left +
+ border.right + margin.right + padding.right;
+ }
+}
+
+void
+hdy_css_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkStyleContext *style_context;
+ GtkStateFlags state_flags;
+ GtkBorder border, margin, padding;
+
+ /* Manually apply the border, the padding and the margin as we can't use the
+ * private GtkGagdet.
+ */
+ style_context = gtk_widget_get_style_context (widget);
+ state_flags = gtk_widget_get_state_flags (widget);
+ 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);
+ allocation->width -= border.left + border.right +
+ margin.left + margin.right +
+ padding.left + padding.right;
+ allocation->height -= border.top + border.bottom +
+ margin.top + margin.bottom +
+ padding.top + padding.bottom;
+ allocation->x = border.left + margin.left + padding.left;
+ allocation->y = border.top + margin.top + padding.top;
+}
diff --git a/src/meson.build b/src/meson.build
index 8b79ec12..11d4100e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -126,6 +126,7 @@ src_sources = [
'hdy-carousel-indicator-lines.c',
'hdy-clamp.c',
'hdy-combo-row.c',
+ 'hdy-css.c',
'hdy-deck.c',
'hdy-enum-value-object.c',
'hdy-expander-row.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]