[gtk/label-sizing] widget: Don't overadjust allocations
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/label-sizing] widget: Don't overadjust allocations
- Date: Mon, 18 Oct 2021 23:56:24 +0000 (UTC)
commit 3742fabae040d914e6ae58edf31170a54a980f21
Author: Benjamin Otte <otte redhat com>
Date: Tue Oct 19 01:08:06 2021 +0200
widget: Don't overadjust allocations
When adjusting allocations, don't query height for the current width,
but query it for the adjusted width.
And adjust width not to the width-for-any-height, but to
width-for-allocated-height.
gtk/gtkwidget.c | 47 +++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 78a282829b..6360fa16c7 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3841,29 +3841,42 @@ gtk_widget_adjust_size_allocation (GtkWidget *widget,
if (priv->halign == GTK_ALIGN_FILL && priv->valign == GTK_ALIGN_FILL)
return;
+ /* Note that adjust_for_align removes any margins from the
+ * allocated sizes and possibly limits them to the natural sizes */
+
if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
{
- /* Go ahead and request the height for allocated width, note that the internals
- * of get_height_for_width will internally limit the for_size to natural size
- * when aligning implicitly.
- */
- gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL, -1,
+ gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
+ allocation->height + priv->margin.top + priv->margin.bottom,
&min_width, &natural_width, NULL, NULL);
+ adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
+ natural_width - priv->margin.left - priv->margin.right,
+ &allocation->x,
+ &allocation->width);
gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
- allocation->width + priv->margin.left + priv->margin.right,
+ allocation->width,
&min_height, &natural_height, NULL, NULL);
+ adjust_for_align (priv->valign,
+ natural_height - priv->margin.top - priv->margin.bottom,
+ &allocation->y,
+ &allocation->height);
}
else
{
- /* Go ahead and request the width for allocated height, note that the internals
- * of get_width_for_height will internally limit the for_size to natural size
- * when aligning implicitly.
- */
- gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL, -1,
+ gtk_widget_measure (widget, GTK_ORIENTATION_VERTICAL,
+ allocation->width + priv->margin.left + priv->margin.right,
&min_height, &natural_height, NULL, NULL);
+ adjust_for_align (priv->valign,
+ natural_height - priv->margin.top - priv->margin.bottom,
+ &allocation->y,
+ &allocation->height);
gtk_widget_measure (widget, GTK_ORIENTATION_HORIZONTAL,
- allocation->height + priv->margin.top + priv->margin.bottom,
+ allocation->height,
&min_width, &natural_width, NULL, NULL);
+ adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
+ natural_width - priv->margin.left - priv->margin.right,
+ &allocation->x,
+ &allocation->width);
}
#ifdef G_ENABLE_CONSISTENCY_CHECKS
@@ -3877,16 +3890,6 @@ gtk_widget_adjust_size_allocation (GtkWidget *widget,
allocation->width, allocation->height,
min_width, min_height);
#endif
- /* Now that we have the right natural height and width, go ahead and remove any margins from the
- * allocated sizes and possibly limit them to the natural sizes */
- adjust_for_align (effective_align (priv->halign, _gtk_widget_get_direction (widget)),
- natural_width - priv->margin.left - priv->margin.right,
- &allocation->x,
- &allocation->width);
- adjust_for_align (priv->valign,
- natural_height - priv->margin.top - priv->margin.bottom,
- &allocation->y,
- &allocation->height);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]