mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +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:
@@ -863,20 +863,10 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
|
|||||||
|
|
||||||
void CSDL_Ext::startTextInput(SDL_Rect * where)
|
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
|
#ifdef VCMI_APPLE
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
|
||||||
// TODO ios: looks like SDL bug actually, try fixing there
|
// TODO ios: looks like SDL bug actually, try fixing there
|
||||||
auto renderer = SDL_GetRenderer(mainWindow);
|
auto renderer = SDL_GetRenderer(mainWindow);
|
||||||
float scaleX, scaleY;
|
float scaleX, scaleY;
|
||||||
@@ -884,17 +874,26 @@ void CSDL_Ext::startTextInput(SDL_Rect * where)
|
|||||||
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
||||||
SDL_RenderGetViewport(renderer, &viewport);
|
SDL_RenderGetViewport(renderer, &viewport);
|
||||||
|
|
||||||
|
#ifdef VCMI_IOS
|
||||||
const auto nativeScale = iOS_utils::screenScale();
|
const auto nativeScale = iOS_utils::screenScale();
|
||||||
auto rectInScreenCoordinates = *where;
|
|
||||||
rectInScreenCoordinates.x = (viewport.x + rectInScreenCoordinates.x) * scaleX / nativeScale;
|
scaleX /= nativeScale;
|
||||||
rectInScreenCoordinates.y = (viewport.y + rectInScreenCoordinates.y) * scaleY / nativeScale;
|
scaleY /= nativeScale;
|
||||||
rectInScreenCoordinates.w = rectInScreenCoordinates.w * scaleX / nativeScale;
|
|
||||||
rectInScreenCoordinates.h = rectInScreenCoordinates.h * scaleY / nativeScale;
|
|
||||||
impl(&rectInScreenCoordinates);
|
|
||||||
#else
|
|
||||||
impl(where);
|
|
||||||
#endif
|
#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
|
#ifdef VCMI_APPLE
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user