Bläddra i källkod

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

Fix android UI shift when keyboard appears
Andrii Danylchenko 2 år sedan
förälder
incheckning
226668c428
1 ändrade filer med 17 tillägg och 18 borttagningar
  1. 17 18
      client/gui/SDL_Extensions.cpp

+ 17 - 18
client/gui/SDL_Extensions.cpp

@@ -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