mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 23:52:41 +00:00
GUI: Always try to show as many entries as possible in ListWidget.
In case there were less items in the list than on a page, it was possible that a "scrollTo" call scrolled items out of the view even though all could be displayed. This caused odd behavior in the load dialog in T7G. There the list contains 10 entries. In case the last one was loaded via the dialog, the next time it was brought up again it showed the 9th entry at the top of the view and effectively hiding all the others. It furthermore did not show the scroll bar because all entries would have fit onto one page. To prevent this odd behavior, a boundary check has been added to all places where the scroll position is set. This has been taken from "scrollToCurrent" which already tried to prevent this. This fixes the second issue described in bug #3610960 "T7G - savegame glitches".
This commit is contained in:
parent
f280789afe
commit
a41457e224
@ -206,6 +206,7 @@ void ListWidget::scrollTo(int item) {
|
||||
|
||||
if (_currentPos != item) {
|
||||
_currentPos = item;
|
||||
checkBounds();
|
||||
scrollBarRecalc();
|
||||
}
|
||||
}
|
||||
@ -467,6 +468,7 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
case kSetPositionCmd:
|
||||
if (_currentPos != (int)data) {
|
||||
_currentPos = data;
|
||||
checkBounds();
|
||||
draw();
|
||||
|
||||
// Scrollbar actions cause list focus (which triggers a redraw)
|
||||
@ -550,6 +552,13 @@ Common::Rect ListWidget::getEditRect() const {
|
||||
return r;
|
||||
}
|
||||
|
||||
void ListWidget::checkBounds() {
|
||||
if (_currentPos < 0 || _entriesPerPage > (int)_list.size())
|
||||
_currentPos = 0;
|
||||
else if (_currentPos + _entriesPerPage > (int)_list.size())
|
||||
_currentPos = _list.size() - _entriesPerPage;
|
||||
}
|
||||
|
||||
void ListWidget::scrollToCurrent() {
|
||||
// Only do something if the current item is not in our view port
|
||||
if (_selectedItem < _currentPos) {
|
||||
@ -560,11 +569,7 @@ void ListWidget::scrollToCurrent() {
|
||||
_currentPos = _selectedItem - _entriesPerPage + 1;
|
||||
}
|
||||
|
||||
if (_currentPos < 0 || _entriesPerPage > (int)_list.size())
|
||||
_currentPos = 0;
|
||||
else if (_currentPos + _entriesPerPage > (int)_list.size())
|
||||
_currentPos = _list.size() - _entriesPerPage;
|
||||
|
||||
checkBounds();
|
||||
_scrollBar->_currentPos = _currentPos;
|
||||
_scrollBar->recalc();
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ protected:
|
||||
|
||||
void receivedFocusWidget();
|
||||
void lostFocusWidget();
|
||||
void checkBounds();
|
||||
void scrollToCurrent();
|
||||
|
||||
int *_textWidth;
|
||||
|
Loading…
Reference in New Issue
Block a user