From e9a92b8795a2a2a31aa914b841e9b0ff1a9c5292 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 20 Apr 2025 23:23:52 +0100 Subject: [PATCH] Fix: Odd drawing and crash if scrollbar is not tall enough. (#14052) Under certain conditions the scrollbar "tab" could be too large for the scrollbar, and cause issues. Caused by an off-by-one in height calculation. --- src/widget.cpp | 8 ++++---- src/window.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index cde3eba7bf..e8198a8bca 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -155,19 +155,19 @@ static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom, bo } else { button_size = NWidgetScrollbar::GetVerticalDimension().height; } - top += button_size; // top points to just below the up-button - bottom -= button_size; // bottom points to top of the down-button + top += button_size; // top points to just below the up-button + bottom -= button_size; // bottom points to just before the down-button int count = sb->GetCount(); int cap = sb->GetCapacity(); if (count > cap) { - int height = (bottom - top); + int height = bottom + 1 - top; int slider_height = std::max(button_size, cap * height / count); height -= slider_height; top += height * sb->GetPosition() / (count - cap); - bottom = top + slider_height; + bottom = top + slider_height - 1; } Point pt; diff --git a/src/window.cpp b/src/window.cpp index 7b3a694ab3..022f917c60 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2315,7 +2315,7 @@ static void HandleScrollbarScrolling(Window *w) int range = sb->GetCount() - sb->GetCapacity(); if (range <= 0) return; - int pos = RoundDivSU((i + _scrollbar_start_pos) * range, _scrollbar_size); + int pos = RoundDivSU((i + _scrollbar_start_pos) * range, std::max(1, _scrollbar_size)); if (rtl) pos = range - pos; if (sb->SetPosition(pos)) w->SetDirty(); }