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:
parent
475ac46f3e
commit
41fe16013b
1 changed files with 25 additions and 13 deletions
|
@ -152,6 +152,21 @@ bool KeyboardNavigation::injectKeyPress(MyGUI::KeyCode key, unsigned int text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool selectFirstWidget()
|
||||||
|
{
|
||||||
|
MyGUI::VectorWidgetPtr keyFocusList;
|
||||||
|
MyGUI::EnumeratorWidgetPtr enumerator = MyGUI::Gui::getInstance().getEnumerator();
|
||||||
|
while (enumerator.next())
|
||||||
|
getKeyFocusWidgets(enumerator.current(), keyFocusList);
|
||||||
|
|
||||||
|
if (!keyFocusList.empty())
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(keyFocusList[0]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool KeyboardNavigation::switchFocus(int direction, bool wrap)
|
bool KeyboardNavigation::switchFocus(int direction, bool wrap)
|
||||||
{
|
{
|
||||||
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||||
|
@ -159,22 +174,14 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
|
||||||
if ((focus && focus->getTypeName().find("Button") == std::string::npos) && direction != D_Prev && direction != D_Next)
|
if ((focus && focus->getTypeName().find("Button") == std::string::npos) && direction != D_Prev && direction != D_Next)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (focus && (direction == D_Prev || direction == D_Next) && focus->getUserString("AcceptTab") == "true")
|
bool isCycle = (direction == D_Prev || direction == D_Next);
|
||||||
|
if (focus && isCycle && focus->getUserString("AcceptTab") == "true")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((!focus || !focus->getNeedKeyFocus()) && (direction == D_Next || direction == D_Prev))
|
if ((!focus || !focus->getNeedKeyFocus()) && isCycle)
|
||||||
{
|
{
|
||||||
// if nothing is selected, select the first widget
|
// if nothing is selected, select the first widget
|
||||||
MyGUI::VectorWidgetPtr keyFocusList;
|
return selectFirstWidget();
|
||||||
MyGUI::EnumeratorWidgetPtr enumerator = MyGUI::Gui::getInstance().getEnumerator();
|
|
||||||
while (enumerator.next())
|
|
||||||
getKeyFocusWidgets(enumerator.current(), keyFocusList);
|
|
||||||
|
|
||||||
if (!keyFocusList.empty())
|
|
||||||
{
|
|
||||||
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(keyFocusList[0]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!focus)
|
if (!focus)
|
||||||
return false;
|
return false;
|
||||||
|
@ -190,7 +197,12 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
|
||||||
|
|
||||||
MyGUI::VectorWidgetPtr::iterator found = std::find(keyFocusList.begin(), keyFocusList.end(), focus);
|
MyGUI::VectorWidgetPtr::iterator found = std::find(keyFocusList.begin(), keyFocusList.end(), focus);
|
||||||
if (found == keyFocusList.end())
|
if (found == keyFocusList.end())
|
||||||
return false;
|
{
|
||||||
|
if (isCycle)
|
||||||
|
return selectFirstWidget();
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool forward = (direction == D_Next || direction == D_Right || direction == D_Down);
|
bool forward = (direction == D_Next || direction == D_Right || direction == D_Down);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue