mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Rely on Scrollbar::SetPosition to clamp.
Manually clamping scrollbar bounds before calling `SetPosition()` is doubling up work that the function already does.pull/10788/head
parent
d2034d9c38
commit
6202eae9d5
|
@ -860,11 +860,10 @@ struct ScriptDebugWindow : public Window {
|
||||||
/* Detect when the user scrolls the window. Enable autoscroll when the
|
/* Detect when the user scrolls the window. Enable autoscroll when the
|
||||||
* bottom-most line becomes visible. */
|
* bottom-most line becomes visible. */
|
||||||
if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
|
if (this->last_vscroll_pos != this->vscroll->GetPosition()) {
|
||||||
this->autoscroll = this->vscroll->GetPosition() >= log.size() - this->vscroll->GetCapacity();
|
this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= (int)log.size();
|
||||||
}
|
}
|
||||||
if (this->autoscroll) {
|
if (this->autoscroll) {
|
||||||
int scroll_pos = std::max<int>(0, (int)log.size() - this->vscroll->GetCapacity());
|
if (this->vscroll->SetPosition((int)log.size())) {
|
||||||
if (this->vscroll->SetPosition(scroll_pos)) {
|
|
||||||
/* We need a repaint */
|
/* We need a repaint */
|
||||||
this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
|
this->SetWidgetDirty(WID_SCRD_SCROLLBAR);
|
||||||
this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
|
this->SetWidgetDirty(WID_SCRD_LOG_PANEL);
|
||||||
|
|
|
@ -2379,13 +2379,10 @@ static void HandleScrollbarScrolling(Window *w)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the item we want to move to and make sure it's inside bounds. */
|
/* Find the item we want to move to. SetPosition will make sure it's inside bounds. */
|
||||||
int pos = std::min(RoundDivSU(std::max(0, i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size), std::max(0, sb->GetCount() - sb->GetCapacity()));
|
int pos = RoundDivSU((i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size);
|
||||||
if (rtl) pos = std::max(0, sb->GetCount() - sb->GetCapacity() - pos);
|
if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos;
|
||||||
if (pos != sb->GetPosition()) {
|
if (sb->SetPosition(pos)) w->SetDirty();
|
||||||
sb->SetPosition(pos);
|
|
||||||
w->SetDirty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue