Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/platform/window_sdl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S, E>(ctx: &mut Context, state: &mut S) -> result::Result<(), E>
Expand Down
15 changes: 15 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Loading