widget: Add get_width() and get_height()
authorTimm Bäder <mail@baedert.org>
Thu, 2 Nov 2017 10:21:29 +0000 (11:21 +0100)
committerTimm Bäder <mail@baedert.org>
Thu, 2 Nov 2017 10:54:06 +0000 (11:54 +0100)
docs/reference/gtk/gtk4-sections.txt
gtk/gtkwidget.c
gtk/gtkwidget.h

index 4a933fdbff26953de6809cfbb611f7806dca570f..60c29a666ea75654ecf69745c6e17a393357357f 100644 (file)
@@ -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
index fda90dcace4afdc37246190be97211f6e5d56eab..bdac23070a9172ef478b32c63bb879734899855c 100644 (file)
@@ -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;
+}
index a8af148c4de5f3b89733468ab0148765de369558..243e80df2b8cf0a1aac1fd6920000fd8f9563617 100644 (file)
@@ -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);