Compare commits

...

1 Commits

Author SHA1 Message Date
Benjamin Otte
3744345bb4 viewport: Keep scroll position in percent
Previously, the code tried to keep the absolute scroll position
unchanged, which meant that when the child or the viewport changed size,
the top left of the viewport would keep locked to the same coordinate in
the child.

With the new code, we keep the point of the viewport unchanged that
matches the percentage the scrollbar has been scrolled.

In particular, that means a centered child stays centered and a child
stays at the bottom (or top) when the scrollbar is scolled to the end
(or start, like before).
2021-12-28 04:21:41 +01:00

View File

@@ -150,11 +150,17 @@ viewport_set_adjustment_values (GtkViewport *viewport,
int child_size)
{
GtkAdjustment *adjustment;
double upper, value;
double upper, value, old_range;
adjustment = viewport->adjustment[orientation];
upper = child_size;
value = gtk_adjustment_get_value (adjustment);
old_range = gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment);
if (old_range > 0)
{
double percentage = value / old_range;
value = percentage * (child_size - viewport_size);
}
/* We clamp to the left in RTL mode */
if (orientation == GTK_ORIENTATION_HORIZONTAL &&