SDL_SetTextInputRect() has been renamed to SDL_SetTextInputArea()

The new function includes the cursor position so IME UI elements can be placed relative to the cursor, as well as having the whole text area available so on-screen keyboards can avoid it.
This commit is contained in:
Sam Lantinga
2024-06-28 13:17:04 -07:00
parent e324c7d692
commit bdd531986b
35 changed files with 201 additions and 148 deletions

View File

@@ -361,14 +361,14 @@ static int keyboard_startStopTextInput(void *arg)
return TEST_COMPLETED;
}
/* Internal function to test SDL_SetTextInputRect */
static void testSetTextInputRect(SDL_Window *window, SDL_Rect refRect)
/* Internal function to test SDL_SetTextInputArea */
static void testSetTextInputArea(SDL_Window *window, SDL_Rect refRect)
{
SDL_Rect testRect;
testRect = refRect;
SDL_SetTextInputRect(window, &testRect);
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%d,y:%d,w:%d,h:%d)", refRect.x, refRect.y, refRect.w, refRect.h);
SDL_SetTextInputArea(window, &testRect, 0);
SDLTest_AssertPass("Call to SDL_SetTextInputArea with refRect(x:%d,y:%d,w:%d,h:%d)", refRect.x, refRect.y, refRect.w, refRect.h);
SDLTest_AssertCheck(
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
"Check that input data was not modified, expected: x:%d,y:%d,w:%d,h:%d, got: x:%d,y:%d,w:%d,h:%d",
@@ -377,11 +377,11 @@ static void testSetTextInputRect(SDL_Window *window, SDL_Rect refRect)
}
/**
* Check call to SDL_SetTextInputRect
* Check call to SDL_SetTextInputArea
*
* \sa SDL_SetTextInputRect
* \sa SDL_SetTextInputArea
*/
static int keyboard_setTextInputRect(void *arg)
static int keyboard_setTextInputArea(void *arg)
{
SDL_Window *window = SDL_GetKeyboardFocus();
SDL_Rect refRect;
@@ -391,77 +391,77 @@ static int keyboard_setTextInputRect(void *arg)
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* Normal visible refRect, origin 0,0 */
refRect.x = 0;
refRect.y = 0;
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* 1Pixel refRect */
refRect.x = SDLTest_RandomIntegerInRange(10, 50);
refRect.y = SDLTest_RandomIntegerInRange(10, 50);
refRect.w = 1;
refRect.h = 1;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 1;
refRect.h = 0;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 1;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* 0pixel refRect */
refRect.x = 1;
refRect.y = 1;
refRect.w = 0;
refRect.h = 0;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* 0pixel refRect */
refRect.x = 0;
refRect.y = 0;
refRect.w = 0;
refRect.h = 0;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* negative refRect */
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);
refRect.w = 50;
refRect.h = 50;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* oversized refRect */
refRect.x = SDLTest_RandomIntegerInRange(1, 50);
refRect.y = SDLTest_RandomIntegerInRange(1, 50);
refRect.w = 5000;
refRect.h = 5000;
testSetTextInputRect(window, refRect);
testSetTextInputArea(window, refRect);
/* NULL refRect */
SDL_SetTextInputRect(window, NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
SDL_SetTextInputArea(window, NULL, 0);
SDLTest_AssertPass("Call to SDL_SetTextInputArea(NULL)");
return TEST_COMPLETED;
}
/**
* Check call to SDL_SetTextInputRect with invalid data
* Check call to SDL_SetTextInputArea with invalid data
*
* \sa SDL_SetTextInputRect
* \sa SDL_SetTextInputArea
*/
static int keyboard_setTextInputRectNegative(void *arg)
static int keyboard_setTextInputAreaNegative(void *arg)
{
/* Some platforms set also an error message; prepare for checking it */
#if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_ANDROID) || defined(SDL_VIDEO_DRIVER_COCOA)
@@ -473,8 +473,8 @@ static int keyboard_setTextInputRectNegative(void *arg)
#endif
/* NULL refRect */
SDL_SetTextInputRect(SDL_GetKeyboardFocus(), NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
SDL_SetTextInputArea(SDL_GetKeyboardFocus(), NULL, 0);
SDLTest_AssertPass("Call to SDL_SetTextInputArea(NULL)");
/* Some platforms set also an error message; so check it */
#if defined(SDL_VIDEO_DRIVER_WINDOWS) || defined(SDL_VIDEO_DRIVER_ANDROID) || defined(SDL_VIDEO_DRIVER_COCOA)
@@ -666,11 +666,11 @@ static const SDLTest_TestCaseReference keyboardTest7 = {
};
static const SDLTest_TestCaseReference keyboardTest8 = {
(SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED
(SDLTest_TestCaseFp)keyboard_setTextInputArea, "keyboard_setTextInputArea", "Check call to SDL_SetTextInputArea", TEST_ENABLED
};
static const SDLTest_TestCaseReference keyboardTest9 = {
(SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED
(SDLTest_TestCaseFp)keyboard_setTextInputAreaNegative, "keyboard_setTextInputAreaNegative", "Check call to SDL_SetTextInputArea with invalid data", TEST_ENABLED
};
static const SDLTest_TestCaseReference keyboardTest10 = {