GUI: Implement setSelected in Grid and use it in launcher

This commit is contained in:
Le Philousophe 2022-05-29 18:38:46 +02:00 committed by Eugene Sandulenko
parent d2f327921c
commit b94ad4d8b8
3 changed files with 34 additions and 1 deletions

View File

@ -1540,8 +1540,18 @@ void LauncherGrid::updateListing() {
gridList.push_back(GridItemInfo(k++, engineid, gameid, iter->title, iter->description, Common::parseLanguage(language), Common::parsePlatform(platform)));
}
const int oldSel = _grid->getSelected();
_grid->setEntryList(&gridList);
groupEntries(attrs);
if (oldSel < (int)gridList.size() && oldSel >= 0)
_grid->setSelected(oldSel); // Restore the old selection
else if (oldSel != -1)
// Select the last entry if the list has been reduced
_grid->setSelected(gridList.size() - 1);
updateButtons();
// And fill out our structures
for (Common::Array<LauncherEntry>::const_iterator iter = domainList.begin(); iter != domainList.end(); ++iter) {
_domains.push_back(iter->key);
@ -1556,7 +1566,19 @@ void LauncherGrid::updateButtons() {
}
}
void LauncherGrid::selectTarget(const Common::String &target) {}
void LauncherGrid::selectTarget(const Common::String &target) {
if (!target.empty()) {
int itemToSelect = 0;
Common::StringArray::const_iterator iter;
for (iter = _domains.begin(); iter != _domains.end(); ++iter, ++itemToSelect) {
if (target == *iter) {
_grid->setSelected(itemToSelect);
break;
}
}
}
}
int LauncherGrid::getSelected() { return _grid->getSelected(); }
void LauncherGrid::build() {

View File

@ -947,4 +947,14 @@ void GridWidget::setFilter(const Common::U32String &filter) {
sortGroups();
}
void GridWidget::setSelected(int id) {
for (uint i = 0; i < _sortedEntryList.size(); ++i) {
if ((!_sortedEntryList[i]->isHeader) && (_sortedEntryList[i]->entryID == id)) {
_selectedEntry = _sortedEntryList[i];
scrollToEntry(id, false);
break;
}
}
}
} // End of namespace GUI

View File

@ -209,6 +209,7 @@ public:
void openTrayAtSelected();
void scrollBarRecalc();
void setSelected(int id);
void setFilter(const Common::U32String &filter);
};