1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merge pull request #1453 from vcmi/android-fix-input-position-for-keyboard

Fix android UI shift when keyboard appears
This commit is contained in:
Andrii Danylchenko 2023-01-18 09:23:46 +02:00 committed by GitHub
commit 226668c428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -863,20 +863,10 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
void CSDL_Ext::startTextInput(SDL_Rect * where)
{
auto impl = [](SDL_Rect * where)
{
if (SDL_IsTextInputActive() == SDL_FALSE)
{
SDL_StartTextInput();
}
SDL_SetTextInputRect(where);
};
#ifdef VCMI_APPLE
dispatch_async(dispatch_get_main_queue(), ^{
#endif
#ifdef VCMI_IOS
// TODO ios: looks like SDL bug actually, try fixing there
auto renderer = SDL_GetRenderer(mainWindow);
float scaleX, scaleY;
@ -884,17 +874,26 @@ void CSDL_Ext::startTextInput(SDL_Rect * where)
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
SDL_RenderGetViewport(renderer, &viewport);
#ifdef VCMI_IOS
const auto nativeScale = iOS_utils::screenScale();
auto rectInScreenCoordinates = *where;
rectInScreenCoordinates.x = (viewport.x + rectInScreenCoordinates.x) * scaleX / nativeScale;
rectInScreenCoordinates.y = (viewport.y + rectInScreenCoordinates.y) * scaleY / nativeScale;
rectInScreenCoordinates.w = rectInScreenCoordinates.w * scaleX / nativeScale;
rectInScreenCoordinates.h = rectInScreenCoordinates.h * scaleY / nativeScale;
impl(&rectInScreenCoordinates);
#else
impl(where);
scaleX /= nativeScale;
scaleY /= nativeScale;
#endif
auto rectInScreenCoordinates = *where;
rectInScreenCoordinates.x = (viewport.x + rectInScreenCoordinates.x) * scaleX;
rectInScreenCoordinates.y = (viewport.y + rectInScreenCoordinates.y) * scaleY;
rectInScreenCoordinates.w = rectInScreenCoordinates.w * scaleX;
rectInScreenCoordinates.h = rectInScreenCoordinates.h * scaleY;
SDL_SetTextInputRect(&rectInScreenCoordinates);
if (SDL_IsTextInputActive() == SDL_FALSE)
{
SDL_StartTextInput();
}
#ifdef VCMI_APPLE
});
#endif