[gtk+] widget: Add get_width() and get_height()
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] widget: Add get_width() and get_height()
- Date: Thu, 2 Nov 2017 10:50:54 +0000 (UTC)
commit 8f55647fbb8d522869e5f47e181a3894e778bcec
Author: Timm Bäder <mail baedert org>
Date: Thu Nov 2 11:21:29 2017 +0100
widget: Add get_width() and get_height()
docs/reference/gtk/gtk4-sections.txt | 2 +
gtk/gtkwidget.c | 64 ++++++++++++++++++++++++++++++++++
gtk/gtkwidget.h | 5 +++
3 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 4a933fd..60c29a6 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4580,6 +4580,8 @@ gtk_widget_get_allocated_height
gtk_widget_get_allocation
gtk_widget_get_allocated_baseline
gtk_widget_get_allocated_size
+gtk_widget_get_width
+gtk_widget_get_height
gtk_widget_get_clip
gtk_widget_contains
gtk_widget_get_can_default
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index fda90dc..bdac230 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -15500,3 +15500,67 @@ gtk_widget_init_legacy_controller (GtkWidget *widget)
"gtk-widget-legacy-event-controller",
controller, g_object_unref);
}
+
+/**
+ * gtk_widget_get_width:
+ * @widget: a #GtkWidget
+ *
+ * Returns the content width of the widget, as passed to its size-allocate implementation.
+ * This is the size you should be using in GtkWidgetClass.snapshot(). For pointer
+ * events, see gtk_widget_contains().
+ *
+ * Returns: The width of @widget
+ *
+ * Since: 3.94
+ */
+int
+gtk_widget_get_width (GtkWidget *widget)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+ GtkBorder margin, border, padding;
+ GtkCssStyle *style;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ style = gtk_css_node_get_style (priv->cssnode);
+ get_box_margin (style, &margin);
+ get_box_border (style, &border);
+ get_box_padding (style, &padding);
+
+ return priv->allocation.width -
+ margin.left - margin.right -
+ border.left - border.right -
+ padding.left - padding.right;
+}
+
+/**
+ * gtk_widget_get_height:
+ * @widget: a #GtkWidget
+ *
+ * Returns the content height of the widget, as passed to its size-allocate implementation.
+ * This is the size you should be using in GtkWidgetClass.snapshot(). For pointer
+ * events, see gtk_widget_contains().
+ *
+ * Returns: The height of @widget
+ *
+ * Since: 3.94
+ */
+int
+gtk_widget_get_height (GtkWidget *widget)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+ GtkBorder margin, border, padding;
+ GtkCssStyle *style;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ style = gtk_css_node_get_style (priv->cssnode);
+ get_box_margin (style, &margin);
+ get_box_border (style, &border);
+ get_box_padding (style, &padding);
+
+ return priv->allocation.height -
+ margin.top - margin.bottom -
+ border.top - border.bottom -
+ padding.top - padding.bottom;
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index a8af148..243e80d 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -743,6 +743,11 @@ void gtk_widget_get_allocated_size (GtkWidget *widget,
GDK_AVAILABLE_IN_ALL
void gtk_widget_get_allocation (GtkWidget *widget,
GtkAllocation *allocation);
+GDK_AVAILABLE_IN_3_94
+int gtk_widget_get_width (GtkWidget *widget);
+GDK_AVAILABLE_IN_3_94
+int gtk_widget_get_height (GtkWidget *widget);
+
GDK_AVAILABLE_IN_3_14
void gtk_widget_get_clip (GtkWidget *widget,
GtkAllocation *clip);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]