diff options
author | Timm Bäder <mail@baedert.org> | 2017-11-02 11:21:29 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2017-11-02 11:54:06 +0100 |
commit | 8f55647fbb8d522869e5f47e181a3894e778bcec (patch) | |
tree | c4f1e741c869dfcab8d61f026ea3c36abfdb39f5 | |
parent | 8fa20f87e48fe1a7bb80f9c9664c2b718e1636c9 (diff) | |
download | gtk+-8f55647fbb8d522869e5f47e181a3894e778bcec.tar.gz |
widget: Add get_width() and get_height()
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 2 | ||||
-rw-r--r-- | gtk/gtkwidget.c | 64 | ||||
-rw-r--r-- | 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 4a933fdbff..60c29a666e 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 fda90dcace..bdac23070a 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 a8af148c4d..243e80df2b 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); |