1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

remove focus from active text input after keyboard is closed

allows focusing same text input again
kambala-decapitator/vcmi#4 kambala-decapitator/vcmi#10
This commit is contained in:
Andrey Filipenkov 2021-03-21 17:30:34 +03:00
parent 27b7cb8f1f
commit 44d0e19c71
4 changed files with 49 additions and 4 deletions

View File

@ -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
client/CFocusableHelper.h Normal file
View File

@ -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();

View File

@ -145,6 +145,16 @@ set(client_HEADERS
SDLRWwrapper.h 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) 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 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) if(WIN32)
set(client_ICON "VCMI_client.rc") set(client_ICON "VCMI_client.rc")
elseif(APPLE_IOS)
set(client_SRCS ${client_SRCS} SDL_uikit_main.m)
endif() endif()
if(ENABLE_DEBUG_CONSOLE) if(ENABLE_DEBUG_CONSOLE)

View File

@ -8,9 +8,11 @@
#include <SDL_events.h> #include <SDL_events.h>
#include <SDL_render.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 @interface SDLViewObserver : NSObject
@ -89,6 +91,9 @@ main(int argc, char *argv[])
[NSNotificationCenter.defaultCenter addObserverForName:UIWindowDidBecomeKeyNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [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]; [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); return SDL_UIKitRunApp(argc, argv, SDL_main);
} }
} }