Browse Source

remove focus from active text input after keyboard is closed

allows focusing same text input again
kambala-decapitator/vcmi#4 kambala-decapitator/vcmi#10
Andrey Filipenkov 4 years ago
parent
commit
44d0e19c71
4 changed files with 49 additions and 4 deletions
  1. 21 0
      client/CFocusableHelper.cpp
  2. 11 0
      client/CFocusableHelper.h
  3. 10 2
      client/CMakeLists.txt
  4. 7 2
      client/SDL_uikit_main.mm

+ 21 - 0
client/CFocusableHelper.cpp

@@ -0,0 +1,21 @@
+/*
+ * CFocusableHelper.cpp, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#include "CFocusableHelper.h"
+#include "../Global.h"
+#include "widgets/TextControls.h"
+
+void removeFocusFromActiveInput()
+{
+    if(CFocusable::inputWithFocus == nullptr)
+        return;
+    CFocusable::inputWithFocus->focus = false;
+    CFocusable::inputWithFocus->redraw();
+    CFocusable::inputWithFocus = nullptr;
+}

+ 11 - 0
client/CFocusableHelper.h

@@ -0,0 +1,11 @@
+/*
+ * CFocusableHelper.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+
+void removeFocusFromActiveInput();

+ 10 - 2
client/CMakeLists.txt

@@ -145,6 +145,16 @@ set(client_HEADERS
 		SDLRWwrapper.h
 )
 
+if(APPLE_IOS)
+	set(client_SRCS ${client_SRCS}
+		SDL_uikit_main.mm
+		CFocusableHelper.cpp
+	)
+	set(client_HEADERS ${client_HEADERS}
+		CFocusableHelper.h
+	)
+endif()
+
 assign_source_group(${client_SRCS} ${client_HEADERS} VCMI_client.rc)
 
 if(ANDROID) # android needs client/server to be libraries, not executables, so we can't reuse the build part of this script
@@ -153,8 +163,6 @@ endif()
 
 if(WIN32)
 	set(client_ICON "VCMI_client.rc")
-elseif(APPLE_IOS)
-	set(client_SRCS ${client_SRCS} SDL_uikit_main.m)
 endif()
 
 if(ENABLE_DEBUG_CONSOLE)

+ 7 - 2
client/SDL_uikit_main.m → client/SDL_uikit_main.mm

@@ -8,9 +8,11 @@
 #include <SDL_events.h>
 #include <SDL_render.h>
 
-@import UIKit;
+#include "../Global.h"
+#include "CMT.h"
+#include "CFocusableHelper.h"
 
-extern SDL_Window * mainWindow;
+#import <UIKit/UIKit.h>
 
 
 @interface SDLViewObserver : NSObject
@@ -89,6 +91,9 @@ main(int argc, char *argv[])
         [NSNotificationCenter.defaultCenter addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
             [UIApplication.sharedApplication.keyWindow.rootViewController addObserver:observer forKeyPath:NSStringFromSelector(@selector(view)) options:NSKeyValueObservingOptionNew context:NULL];
         }];
+        [NSNotificationCenter.defaultCenter addObserverForName:UIKeyboardDidHideNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
+            removeFocusFromActiveInput();
+        }];
         return SDL_UIKitRunApp(argc, argv, SDL_main);
     }
 }