1
0
Fork 0

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.
pull/14018/head
Peter Nelson 2025-04-20 23:23:52 +01:00 committed by GitHub
parent 0efbb3a7a7
commit e9a92b8795
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -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;

View File

@ -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();
}