From 8ca299e82bbcca6ba59b1648864c8434a704107b Mon Sep 17 00:00:00 2001 From: Matthijs Velsink Date: Sun, 25 Aug 2024 22:54:43 +0200 Subject: [PATCH 1/2] scale: Fix GTK_POS_TOP marks and value order If both marks are set on top, and the value is drawn on top, the value should be drawn outside the marks for a horizontal scale. Currently, that order is incorrect, with the marks shifted up and the value drawn between the slider and the marks. This fixes that order. --- gtk/gtkscale.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 907996ec3c..50192faf95 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -382,7 +382,7 @@ gtk_scale_allocate_value (GtkScale *scale) case GTK_POS_TOP: value_alloc.x = slider_center_x - value_alloc.width / 2; - value_alloc.y = slider_bounds.origin.y - value_alloc.height; + value_alloc.y = 0; break; case GTK_POS_BOTTOM: @@ -582,7 +582,7 @@ gtk_scale_size_allocate (GtkWidget *widget, &marks_height, NULL, NULL, NULL); marks_rect.x = 0; - marks_rect.y = 0; + marks_rect.y = range_rect.y - marks_height; marks_rect.width = range_rect.width; marks_rect.height = marks_height; gtk_widget_size_allocate (priv->top_marks_widget, &marks_rect, -1); From d58b545ffb887dc58b72ee6757960e06d39d71f9 Mon Sep 17 00:00:00 2001 From: Matthijs Velsink Date: Sun, 25 Aug 2024 22:59:22 +0200 Subject: [PATCH 2/2] scale: Don't apply borders twice for value The measured size of the range already includes borders that the scale calculates. This includes the drawn value. So in the measurement of scale, the size of the value shouldn't just be added to the size of the scale, as then the size is effectively added twice. To fix this, we first measure the minimum size of the range. Then, we determine the minimum size of our scale. Only then do we set the minimum size to maximum of those two values. --- gtk/gtkscale.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c index 50192faf95..c2974cf2a3 100644 --- a/gtk/gtkscale.c +++ b/gtk/gtkscale.c @@ -1436,11 +1436,12 @@ gtk_scale_measure (GtkWidget *widget, GtkScale *scale = GTK_SCALE (widget); GtkScalePrivate *priv = gtk_scale_get_instance_private (scale); GtkOrientation scale_orientation; + int range_minimum, range_natural, scale_minimum = 0, scale_natural = 0; GTK_WIDGET_CLASS (gtk_scale_parent_class)->measure (widget, orientation, for_size, - minimum, natural, + &range_minimum, &range_natural, minimum_baseline, natural_baseline); scale_orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)); @@ -1462,8 +1463,8 @@ gtk_scale_measure (GtkWidget *widget, marks_size = MAX (top_marks_size, bottom_marks_size); - *minimum = MAX (*minimum, marks_size); - *natural = MAX (*natural, marks_size); + scale_minimum = MAX (scale_minimum, marks_size); + scale_natural = MAX (scale_natural, marks_size); } if (priv->value_widget) @@ -1477,29 +1478,32 @@ gtk_scale_measure (GtkWidget *widget, { if (orientation == GTK_ORIENTATION_HORIZONTAL) { - *minimum = MAX (*minimum, min); - *natural = MAX (*natural, nat); + scale_minimum = MAX (scale_minimum, min); + scale_natural = MAX (scale_natural, nat); } else { - *minimum += min; - *natural += nat; + scale_minimum += min; + scale_natural += nat; } } else { if (orientation == GTK_ORIENTATION_HORIZONTAL) { - *minimum += min; - *natural += nat; + scale_minimum += min; + scale_natural += nat; } else { - *minimum = MAX (*minimum, min); - *natural = MAX (*natural, nat); + scale_minimum = MAX (scale_minimum, min); + scale_natural = MAX (scale_natural, nat); } } } + + *minimum = MAX (range_minimum, scale_minimum); + *natural = MAX (range_natural, scale_natural); } static void