From caf23dcb1835c53d964e1285c5d6cc84bc463bb2 Mon Sep 17 00:00:00 2001 From: Ilia Agafonov Date: Sun, 19 Jul 2026 23:41:20 +0700 Subject: [PATCH] Add window::set_text_input_enabled() and is_text_input_enabled() --- src/platform/window_sdl.rs | 13 +++++++++++++ src/window.rs | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/platform/window_sdl.rs b/src/platform/window_sdl.rs index 2252e76..d6e1532 100644 --- a/src/platform/window_sdl.rs +++ b/src/platform/window_sdl.rs @@ -485,6 +485,19 @@ impl Window { let sdl_keycode = Keycode::from_scancode(sdl_scancode, SDL_KMOD_NONE, false)?; from_sdl_keycode(sdl_keycode) } + + pub fn set_text_input_enabled(&mut self, text_input_enabled: bool) { + let text_input = self.video_sys.text_input(); + if text_input_enabled { + text_input.start(&self.sdl_window); + } else { + text_input.stop(&self.sdl_window); + } + } + + pub fn is_text_input_enabled(&self) -> bool { + self.video_sys.text_input().is_active(&self.sdl_window) + } } pub fn handle_events(ctx: &mut Context, state: &mut S) -> result::Result<(), E> diff --git a/src/window.rs b/src/window.rs index 70ae770..4d703c8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -446,6 +446,21 @@ pub fn is_key_repeat_enabled(ctx: &Context) -> bool { ctx.window.is_key_repeat_enabled() } +/// Sets whether or not text input is enabled. +/// +/// When enabled, typing fires [`TextInput`](crate::Event::TextInput) events carrying the +/// composed text (and, on platforms with an IME, activates it). When disabled, keystrokes +/// still fire [`KeyPressed`](crate::Event::KeyPressed)/[`KeyReleased`](crate::Event::KeyReleased) +/// but produce no `TextInput`. +pub fn set_text_input_enabled(ctx: &mut Context, text_input_enabled: bool) { + ctx.window.set_text_input_enabled(text_input_enabled); +} + +/// Returns whether or not text input is currently enabled. +pub fn is_text_input_enabled(ctx: &Context) -> bool { + ctx.window.is_text_input_enabled() +} + /// Represents the position of a window on the screen. #[non_exhaustive] #[derive(Debug, Clone, Copy, PartialEq, Eq)]