scale: the size of the value text for the bounds is measured at the size request and kept for the changes of the value, instead of laying out both bounds at each

This commit is contained in:
Daemonratte 2026-10-16 19:55:22 +02:00
commit 8ca795ac37
No known key found for this signature in database

View file

@ -66,6 +66,15 @@ struct _GtkScalePrivate
{
PangoLayout *layout;
GSList *marks;
/* the size of the value text for the bounds of the adjustment,
* which every change of the value asks for; measured again at each
* size request and whenever the bounds, the digits or the style are
* new */
guint value_size_valid : 1;
gint value_width, value_height;
gdouble value_lower, value_upper;
gint value_digits;
};
enum {
@ -821,12 +830,25 @@ _gtk_scale_get_value_size (GtkScale *scale,
if (scale->draw_value)
{
GtkScalePrivate *priv = GTK_SCALE_GET_PRIVATE (scale);
PangoLayout *layout;
PangoRectangle logical_rect;
gchar *txt;
range = GTK_RANGE (scale);
if (priv->value_size_valid &&
priv->value_lower == range->adjustment->lower &&
priv->value_upper == range->adjustment->upper &&
priv->value_digits == scale->digits)
{
if (width)
*width = priv->value_width;
if (height)
*height = priv->value_height;
return;
}
layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
txt = _gtk_scale_format_value (scale, range->adjustment->lower);
@ -852,6 +874,16 @@ _gtk_scale_get_value_size (GtkScale *scale,
*height = MAX (*height, logical_rect.height);
g_object_unref (layout);
if (width && height)
{
priv->value_size_valid = TRUE;
priv->value_width = *width;
priv->value_height = *height;
priv->value_lower = range->adjustment->lower;
priv->value_upper = range->adjustment->upper;
priv->value_digits = scale->digits;
}
}
else
{
@ -955,6 +987,10 @@ gtk_scale_size_request (GtkWidget *widget,
gint n1, w1, h1, n2, w2, h2;
gint slider_length;
/* a new size is asked for: the text of the value may be new as well,
* from a handler of ::format-value */
GTK_SCALE_GET_PRIVATE (widget)->value_size_valid = FALSE;
GTK_WIDGET_CLASS (gtk_scale_parent_class)->size_request (widget, requisition);
gtk_widget_style_get (widget, "slider-length", &slider_length, NULL);
@ -1390,6 +1426,8 @@ _gtk_scale_clear_layout (GtkScale *scale)
g_return_if_fail (GTK_IS_SCALE (scale));
priv->value_size_valid = FALSE;
if (priv->layout)
{
g_object_unref (priv->layout);