Make Tab work if selected widget is marked as not needing keyfocus

new-script-api
scrawl 7 years ago
parent ad8d0c5302
commit c035548f37

@ -63,12 +63,6 @@ void KeyboardNavigation::_unlinkWidget(MyGUI::Widget *widget)
w.second = nullptr; w.second = nullptr;
} }
bool isButtonFocus()
{
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
return focus->getTypeName().find("Button") != std::string::npos;
}
enum Direction enum Direction
{ {
D_Left, D_Left,
@ -106,7 +100,13 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
{ {
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget(); MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if (!focus && (direction == D_Next || direction == D_Prev)) 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 // if nothing is selected, select the first widget
MyGUI::VectorWidgetPtr keyFocusList; MyGUI::VectorWidgetPtr keyFocusList;
@ -120,20 +120,12 @@ bool KeyboardNavigation::switchFocus(int direction, bool wrap)
return true; return true;
} }
} }
if (!focus) if (!focus)
return false; return false;
if (!isButtonFocus() && direction != D_Prev && direction != D_Next) MyGUI::Widget* window = focus;
return false; while (window && window->getParent())
if ((direction == D_Prev || direction == D_Next) && focus->getUserString("AcceptTab") == "true")
return false;
MyGUI::Widget* window = MyGUI::InputManager::getInstance().getKeyFocusWidget();
while (window->getParent())
window = window->getParent(); window = window->getParent();
MyGUI::VectorWidgetPtr keyFocusList; MyGUI::VectorWidgetPtr keyFocusList;
getKeyFocusWidgets(window, keyFocusList); getKeyFocusWidgets(window, keyFocusList);

Loading…
Cancel
Save