Add SetTextInputProperties to video device API and fix iOS handling

This commit is contained in:
Salman Alshamrani
2024-11-09 08:17:43 -05:00
committed by Sam Lantinga
parent 5d09656afa
commit 972c6d0b82
5 changed files with 30 additions and 1 deletions

View File

@@ -352,6 +352,7 @@ struct SDL_VideoDevice
bool (*HasScreenKeyboardSupport)(SDL_VideoDevice *_this);
void (*ShowScreenKeyboard)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
void (*HideScreenKeyboard)(SDL_VideoDevice *_this, SDL_Window *window);
void (*SetTextInputProperties)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
bool (*IsScreenKeyboardShown)(SDL_VideoDevice *_this, SDL_Window *window);
// Clipboard

View File

@@ -5299,6 +5299,10 @@ bool SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props
}
}
if (_this->SetTextInputProperties) {
_this->SetTextInputProperties(_this, window, props);
}
// Show the on-screen keyboard, if desired
if (AutoShowingScreenKeyboard() && !SDL_ScreenKeyboardShown(window)) {
if (_this->ShowScreenKeyboard) {

View File

@@ -99,6 +99,7 @@ static SDL_VideoDevice *UIKit_CreateDevice(void)
device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
device->StartTextInput = UIKit_StartTextInput;
device->StopTextInput = UIKit_StopTextInput;
device->SetTextInputProperties = UIKit_SetTextInputProperties;
device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
device->UpdateTextInputArea = UIKit_UpdateTextInputArea;
#endif

View File

@@ -90,6 +90,7 @@
bool UIKit_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
bool UIKit_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
bool UIKit_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window);
void UIKit_SetTextInputProperties(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
bool UIKit_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window);
bool UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window);
#endif

View File

@@ -470,6 +470,21 @@ static void SDLCALL SDL_HideHomeIndicatorHintChanged(void *userdata, const char
} else {
textField.enablesReturnKeyAutomatically = NO;
}
if (!textField.window) {
/* textField has not been added to the view yet,
we don't have to do anything. */
return;
}
// the text field needs to be re-added to the view in order to update correctly.
UIView *superview = textField.superview;
[textField removeFromSuperview];
[superview addSubview:textField];
if (SDL_TextInputActive(window)) {
[textField becomeFirstResponder];
}
}
/* requests the SDL text field to become focused and accept text input.
@@ -672,7 +687,6 @@ bool UIKit_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Proper
{
@autoreleasepool {
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
[vc setTextFieldProperties:props];
return [vc startTextInput];
}
}
@@ -685,6 +699,14 @@ bool UIKit_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
}
}
void UIKit_SetTextInputProperties(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
@autoreleasepool {
SDL_uikitviewcontroller *vc = GetWindowViewController(window);
[vc setTextFieldProperties:props];
}
}
bool UIKit_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {