mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +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:
commit
226668c428
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user