mirror of https://github.com/OpenTTD/OpenTTD
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
parent
0efbb3a7a7
commit
e9a92b8795
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue