Fix possible undismissed screen keyboard in iOS

This commit is contained in:
Benau 2020-07-17 19:10:53 +08:00
parent 31c1003912
commit f2b774d63a
5 changed files with 25 additions and 2 deletions

View File

@ -610,6 +610,8 @@ public:
//! reads an element //! reads an element
virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node) =0; virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node) =0;
virtual void removeHovered(IGUIElement* element) = 0;
}; };

View File

@ -1617,6 +1617,21 @@ IGUIElement* CGUIEnvironment::getNextElement(bool reverse, bool group)
} }
void CGUIEnvironment::removeHovered(IGUIElement* element)
{
if (Hovered && Hovered == element)
{
Hovered->drop();
Hovered = NULL;
if (HoveredNoSubelement)
{
HoveredNoSubelement->drop();
HoveredNoSubelement = NULL;
}
}
}
//! creates an GUI Environment //! creates an GUI Environment
IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs, IGUIEnvironment* createGUIEnvironment(io::IFileSystem* fs,
video::IVideoDriver* Driver, video::IVideoDriver* Driver,

View File

@ -256,6 +256,7 @@ public:
//! reads an element //! reads an element
virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node); virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* node);
virtual void removeHovered(IGUIElement* element);
private: private:
IGUIElement* getNextElement(bool reverse=false, bool group=false); IGUIElement* getNextElement(bool reverse=false, bool group=false);

View File

@ -242,7 +242,8 @@ CGUIEditBox::~CGUIEditBox()
GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard()) GUIEngine::ScreenKeyboard::hasSystemScreenKeyboard())
Android_toggleOnScreenKeyboard(false, 0, 0); Android_toggleOnScreenKeyboard(false, 0, 0);
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
SDL_StopTextInput(); if (SDL_IsTextInputActive())
SDL_StopTextInput();
#endif #endif
#endif #endif
@ -366,7 +367,8 @@ bool CGUIEditBox::OnEvent(const SEvent& event)
setTextMarkers(0,0); setTextMarkers(0,0);
} }
#if !defined(ANDROID) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_) #if !defined(ANDROID) && defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
SDL_StopTextInput(); if (SDL_IsTextInputActive())
SDL_StopTextInput();
#endif #endif
#ifdef ANDROID #ifdef ANDROID
// If using non touchscreen input in android dismiss text input // If using non touchscreen input in android dismiss text input

View File

@ -199,6 +199,9 @@ void TextBoxWidget::unfocused(const int playerID, Widget* new_focus)
void TextBoxWidget::elementRemoved() void TextBoxWidget::elementRemoved()
{ {
// If text box is destroyed without moving mouse out of its focus, the
// reference will be kept so we clear it manually
GUIEngine::getGUIEnv()->removeHovered(m_element);
// normally at this point normal widgets have been deleted by irrlicht already. // normally at this point normal widgets have been deleted by irrlicht already.
// but this is a custom widget and the gui env does not appear to want to // but this is a custom widget and the gui env does not appear to want to
// manage it. so we free it manually // manage it. so we free it manually