From 96041323503696bbca3aee0674bb164c3a77510d Mon Sep 17 00:00:00 2001 From: stolen <2026438995@qq.com> Date: Fri, 1 Dec 2023 08:42:45 +0800 Subject: [PATCH] feat(ime): add Input Method Support (#121) Co-authored-by: juvenile --- crates/bootstrap/src/lib.rs | 3 +++ crates/yakui-winit/src/lib.rs | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/crates/bootstrap/src/lib.rs b/crates/bootstrap/src/lib.rs index ba853d83..8a4a2457 100644 --- a/crates/bootstrap/src/lib.rs +++ b/crates/bootstrap/src/lib.rs @@ -79,6 +79,8 @@ async fn run(body: impl ExampleBody) { .build(&event_loop) .unwrap(); + window.set_ime_allowed(true); + // yakui_app has a helper for setting up winit and wgpu. let mut app = yakui_app::Graphics::new(&window).await; @@ -124,6 +126,7 @@ async fn run(body: impl ExampleBody) { FontSettings::default(), ) .unwrap(); + fonts.add(font, Some("monospace")); // Set up some default state that we'll modify later. diff --git a/crates/yakui-winit/src/lib.rs b/crates/yakui-winit/src/lib.rs index 19b70890..8430b2ce 100644 --- a/crates/yakui-winit/src/lib.rs +++ b/crates/yakui-winit/src/lib.rs @@ -178,6 +178,16 @@ impl YakuiWinit { false } } + + WinitEvent::WindowEvent { + event: WindowEvent::Ime(winit::event::Ime::Commit(text)), + .. + } => { + for c in text.chars() { + state.handle_event(Event::TextInput(c)); + } + true + } _ => false, } }