menue.cpp: add reverse search to find selectable item

This commit is contained in:
GetAway
2017-11-04 21:43:17 +01:00
committed by Thilo Graf
parent f855209de0
commit 002ef3a1c9

View File

@@ -1229,9 +1229,9 @@ void CMenuWidget::calcSize()
void CMenuWidget::initSelectable() void CMenuWidget::initSelectable()
{ {
int pos = 0; int pos = 0, npos = 0;
if (selected > 0 && selected < (int)items.size()) if (selected > 0 && selected < (int)items.size())
pos = selected; npos = pos = selected;
else else
selected = -1; selected = -1;
@@ -1240,7 +1240,15 @@ void CMenuWidget::initSelectable()
break; break;
pos++; pos++;
} }
selected = pos; if (pos == (int)items.size()) {
pos = npos;
while (pos > 1) {
if (items[pos]->isSelectable())
break;
pos--;
}
}
selected = (pos == 0) ? -1 : pos;
} }
void CMenuWidget::paint() void CMenuWidget::paint()