1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-06 03:45:35 +00:00

Select first widget if we can't find the current widget

This commit is contained in:
scrawl 2017-09-26 19:37:33 +02:00
parent 475ac46f3e
commit 41fe16013b

View file

@ -152,19 +152,8 @@ bool KeyboardNavigation::injectKeyPress(MyGUI::KeyCode key, unsigned int text)
}
}
bool KeyboardNavigation::switchFocus(int direction, bool wrap)
bool selectFirstWidget()
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if ((focus && focus->getTypeName().find("Button") == std::string::npos) && direction != D_Prev && direction != D_Next)
return false;
if (focus && (direction == D_Prev || direction == D_Next) && focus->getUserString("AcceptTab") == "true")
return false;
if ((!focus || !focus->getNeedKeyFocus()) && (direction == D_Next || direction == D_Prev))
{
// if nothing is selected, select the first widget
MyGUI::VectorWidgetPtr keyFocusList;
MyGUI::EnumeratorWidgetPtr enumerator = MyGUI::Gui::getInstance().getEnumerator();
while (enumerator.next())
@ -175,6 +164,24 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(keyFocusList[0]);
return true;
}
return false;
}
bool KeyboardNavigation::switchFocus(int direction, bool wrap)
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if ((focus && focus->getTypeName().find("Button") == std::string::npos) && direction != D_Prev && direction != D_Next)
return false;
bool isCycle = (direction == D_Prev || direction == D_Next);
if (focus && isCycle && focus->getUserString("AcceptTab") == "true")
return false;
if ((!focus || !focus->getNeedKeyFocus()) && isCycle)
{
// if nothing is selected, select the first widget
return selectFirstWidget();
}
if (!focus)
return false;
@ -190,7 +197,12 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
MyGUI::VectorWidgetPtr::iterator found = std::find(keyFocusList.begin(), keyFocusList.end(), focus);
if (found == keyFocusList.end())
{
if (isCycle)
return selectFirstWidget();
else
return false;
}
bool forward = (direction == D_Next || direction == D_Right || direction == D_Down);