scrolledwindow: Fix measuring non-overlay, always visible scrollbars

The last part of logic in gtk_scrolled_window_measure () that accounted
for scrollbars was handling the hscrollbar first, and vscrollbar second.
For each of them, it looked at the orientation we're being measured in,
and either added or MAX'ed scrollbar's size request into ours (or not,
depending on scrollbar policy and whether overlay scrolling is used).

In case of GTK_ORIENTATION_HORIZONTAL, this resulted in

    // MAX in hscrollbar width.
    minimum_req = MAX (minimum_req, min_scrollbar_width + sborder.left + sborder.right);
    // Add in vscrollbar width.
    minimum_req += min_scrollbar_width;

whereas for GTK_ORIENTATION_VERTICAL, it was

    // Add in hscrollbar height.
    minimum_req += min_scrollbar_height;
    // MAX in vscrollbar height.
    minimum_req = MAX (minimum_req, min_scrollbar_height + sborder.top + sborder.bottom);

The former is correct and the latter is wrong: we should be adding the
size requests of the scrollbars together, and MAX'ing them with the
content size request.

Fix this by refactoring the logic to first handle the MAX'ing, and then
the addition.

This fixes the following criticals:

Gtk-CRITICAL **: 17:26:51.406: Allocation height too small. Tried to allocate 15x31, but GtkScrollbar 0x2a00fac0 needs at least 15x46.

that were happening when all of:
- scrollbar policy was set to ALWAYS,
- overlay scrolling was disabled,
- the scrollable child was really small.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
This commit is contained in:
Sergey Bugaev
2024-10-03 18:38:59 +03:00
parent 3d7ac47e5e
commit 2cf1651235

View File

@@ -1844,19 +1844,30 @@ gtk_scrolled_window_measure (GtkWidget *widget,
* Now add to the requisition any additional space for surrounding scrollbars
* and the special scrollable border.
*/
if (policy_may_be_visible (priv->hscrollbar_policy))
if (orientation == GTK_ORIENTATION_HORIZONTAL && policy_may_be_visible (priv->hscrollbar_policy))
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
int min_scrollbar_width, nat_scrollbar_width;
int min_scrollbar_width, nat_scrollbar_width;
gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
&min_scrollbar_width, &nat_scrollbar_width,
NULL, NULL);
minimum_req = MAX (minimum_req, min_scrollbar_width + sborder.left + sborder.right);
natural_req = MAX (natural_req, nat_scrollbar_width + sborder.left + sborder.right);
}
else if (!priv->use_indicators && priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
&min_scrollbar_width, &nat_scrollbar_width,
NULL, NULL);
minimum_req = MAX (minimum_req, min_scrollbar_width + sborder.left + sborder.right);
natural_req = MAX (natural_req, nat_scrollbar_width + sborder.left + sborder.right);
}
else if (orientation == GTK_ORIENTATION_VERTICAL && policy_may_be_visible (priv->vscrollbar_policy))
{
int min_scrollbar_height, nat_scrollbar_height;
gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_VERTICAL, -1,
&min_scrollbar_height, &nat_scrollbar_height,
NULL, NULL);
minimum_req = MAX (minimum_req, min_scrollbar_height + sborder.top + sborder.bottom);
natural_req = MAX (natural_req, nat_scrollbar_height + sborder.top + sborder.bottom);
}
if (!priv->use_indicators)
{
if (orientation == GTK_ORIENTATION_VERTICAL && priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
{
int min_scrollbar_height, nat_scrollbar_height;
@@ -1867,21 +1878,7 @@ gtk_scrolled_window_measure (GtkWidget *widget,
minimum_req += min_scrollbar_height;
natural_req += nat_scrollbar_height;
}
}
if (policy_may_be_visible (priv->vscrollbar_policy))
{
if (orientation == GTK_ORIENTATION_VERTICAL)
{
int min_scrollbar_height, nat_scrollbar_height;
gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_VERTICAL, -1,
&min_scrollbar_height, &nat_scrollbar_height,
NULL, NULL);
minimum_req = MAX (minimum_req, min_scrollbar_height + sborder.top + sborder.bottom);
natural_req = MAX (natural_req, nat_scrollbar_height + sborder.top + sborder.bottom);
}
else if (!priv->use_indicators && priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
else if (orientation == GTK_ORIENTATION_HORIZONTAL && priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
{
int min_scrollbar_width, nat_scrollbar_width;