Skip to content

feat(keyboard): add text input properties and get text input area - #436

Open
ozongzi wants to merge 1 commit into
vhspace:masterfrom
ozongzi:feat/text-input-properties
Open

feat(keyboard): add text input properties and get text input area#436
ozongzi wants to merge 1 commit into
vhspace:masterfrom
ozongzi:feat/text-input-properties

Conversation

@ozongzi

@ozongzi ozongzi commented Aug 17, 2026

Copy link
Copy Markdown

Add wrappers for the text input APIs that were still missing:

  • SDL_StartTextInputWithPropertiesTextInputUtil::start_with_options
  • SDL_GetTextInputAreaTextInputUtil::rect (the missing half of set_rect)
  • SDL_TextInputTypeTextInputType
  • SDL_CapitalizationCapitalization
  • the five SDL_PROP_TEXTINPUT_* properties → TextInputOptions

Without these, a text field cannot tell the platform what is being entered, so on-screen keyboards cannot be specialized for e-mail, username or number input, and password fields cannot turn off the input method editor.

video_subsystem.text_input().start_with_options(
    &window,
    TextInputOptions {
        input_type: Some(TextInputType::Email),
        autocorrect: Some(false),
        ..Default::default()
    },
)?;

Notes on the design

  • Enum variants drop the redundant TEXT_ prefix, since TextInputType:: already qualifies them: Email, Username, PasswordHidden.
  • Every field of TextInputOptions is an Option, and None leaves the property unset so SDL applies its own default. This matters because the default capitalization depends on the input type (sentences for text, words for names, none for e-mail and usernames), so a plain non-optional field would have to guess a default and would override SDL's.
  • android_input_type is present on all platforms rather than #[cfg(target_os = "android")], so cross-platform code can construct the struct without cfg. It is documented as Android-only and SDL ignores the property elsewhere.
  • The property group is built with sys::properties directly rather than the Properties wrapper, which has no plain number/boolean setters and would leak PropertiesError into this API. The group is destroyed right after the call.
  • The existing start() is untouched. It discards the bool from SDL_StartTextInput, but changing that is a breaking change and does not belong here.

Testing

  • cargo build, cargo fmt --check and cargo clippy --all-targets are clean for the touched file
  • cargo test --doc keyboard passes, including the two new examples
  • Verified against a live SDL on macOS: start_with_options reports active, set_rect / rect round-trip the rectangle and cursor offset, Default::default() works, and stop deactivates

Add wrappers for:
- SDL_StartTextInputWithProperties (as TextInputUtil::start_with_options)
- SDL_GetTextInputArea (as TextInputUtil::rect)
- SDL_TextInputType, SDL_Capitalization and the five SDL_PROP_TEXTINPUT_*
  properties, exposed as TextInputType, Capitalization and TextInputOptions

Without these, a text field cannot tell the platform what is being entered,
so on-screen keyboards cannot be specialized for e-mail, username or number
input, and password fields cannot turn off the input method editor.

Every field of TextInputOptions is an Option so that leaving one unset keeps
SDL's own default, which for capitalization depends on the input type.
Copilot AI lite review requested due to automatic review settings August 17, 2026 15:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants