1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

Merge pull request #5009 from Laserlicht/scroll_fix

fix scrolling in search window
This commit is contained in:
Ivan Savenko 2024-12-02 13:13:23 +02:00 committed by GitHub
commit 304f6bbc90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1508,7 +1508,7 @@ CObjectListWindow::CObjectListWindow(const std::vector<int> & _items, std::share
itemsVisible = items;
init(titleWidget_, _title, _descr, searchBoxEnabled);
list->scrollTo(initialSelection - 4); // -4 is for centering (list have 9 elements)
list->scrollTo(std::min(static_cast<int>(initialSelection + 4), static_cast<int>(items.size() - 1))); // 4 is for centering (list have 9 elements)
}
CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, std::function<void(int)> Callback, size_t initialSelection, std::vector<std::shared_ptr<IImage>> images, bool searchBoxEnabled)
@ -1528,7 +1528,7 @@ CObjectListWindow::CObjectListWindow(const std::vector<std::string> & _items, st
itemsVisible = items;
init(titleWidget_, _title, _descr, searchBoxEnabled);
list->scrollTo(initialSelection - 4); // -4 is for centering (list have 9 elements)
list->scrollTo(std::min(static_cast<int>(initialSelection + 4), static_cast<int>(items.size() - 1))); // 4 is for centering (list have 9 elements)
}
void CObjectListWindow::init(std::shared_ptr<CIntObject> titleWidget_, std::string _title, std::string _descr, bool searchBoxEnabled)
@ -1653,7 +1653,7 @@ void CObjectListWindow::keyPressed(EShortcut key)
}
vstd::abetween<int>(sel, 0, itemsVisible.size()-1);
list->scrollTo(sel - 4); // -4 is for centering (list have 9 elements)
list->scrollTo(sel);
changeSelection(sel);
}