From e049fff3605b40ff3c3956785b3812fc645b2a7c Mon Sep 17 00:00:00 2001
From: DominusExult <[EMAIL REDACTED]>
Date: Fri, 13 Feb 2026 15:09:33 +0100
Subject: [PATCH] Fix testime to pass window coordinates to
SDL_SetTextInputArea(). Also moved the area closer to the bottom so the
panning of the screen can be observed on Android and iOS.
---
test/testime.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/test/testime.c b/test/testime.c
index 205f96d701d77..e2945a2cf3081 100644
--- a/test/testime.c
+++ b/test/testime.c
@@ -473,7 +473,8 @@ static WindowState *GetWindowStateForWindowID(SDL_WindowID windowID)
static void InitInput(WindowState *ctx)
{
/* Prepare a rect for text input */
- ctx->textRect.x = ctx->textRect.y = 100.0f;
+ ctx->textRect.x = 100.0f;
+ ctx->textRect.y = 250.0f;
ctx->textRect.w = DEFAULT_WINDOW_WIDTH - 2 * ctx->textRect.x;
ctx->textRect.h = 50.0f;
ctx->markedRect = ctx->textRect;
@@ -659,12 +660,23 @@ static void DrawCandidates(WindowState *ctx, SDL_FRect *cursorRect)
static void UpdateTextInputArea(WindowState *ctx, const SDL_FRect *cursorRect)
{
SDL_Rect rect;
- int cursor_offset = (int)(cursorRect->x - ctx->textRect.x);
+ float x1, y1, x2, y2;
+
+ /* Convert render coordinates to window coordinates for SDL_SetTextInputArea */
+ SDL_RenderCoordinatesToWindow(ctx->renderer, ctx->textRect.x, ctx->textRect.y, &x1, &y1);
+ SDL_RenderCoordinatesToWindow(ctx->renderer, ctx->textRect.x + ctx->textRect.w, ctx->textRect.y + ctx->textRect.h, &x2, &y2);
+
+ rect.x = (int)x1;
+ rect.y = (int)y1;
+ rect.w = (int)(x2 - x1);
+ rect.h = (int)(y2 - y1);
+
+ /* cursor_offset also needs to be in window coordinates */
+ float cursor_x_render = cursorRect->x;
+ float cursor_x_window, dummy;
+ SDL_RenderCoordinatesToWindow(ctx->renderer, cursor_x_render, 0, &cursor_x_window, &dummy);
+ int cursor_offset = (int)(cursor_x_window - x1);
- rect.x = (int)ctx->textRect.x;
- rect.y = (int)ctx->textRect.y;
- rect.w = (int)ctx->textRect.w;
- rect.h = (int)ctx->textRect.h;
SDL_SetTextInputArea(ctx->window, &rect, cursor_offset);
}