Skip to content

Commit

Permalink
feat: IME Support
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Jan 7, 2024
1 parent 1cd0d37 commit 3668bb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/renderer/src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use freya_elements::events::keyboard::{
use torin::geometry::CursorPoint;
use winit::event::{
ElementState, Event, KeyboardInput, ModifiersState, MouseScrollDelta, StartCause, Touch,
TouchPhase, VirtualKeyCode, WindowEvent,
TouchPhase, VirtualKeyCode, WindowEvent, Ime,
};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};

Expand Down Expand Up @@ -83,6 +83,19 @@ pub fn run_event_loop<State: Clone>(
}
Event::WindowEvent { event, .. } if app.on_window_event(&event) => {
match event {
WindowEvent::Ime(e) => {
match e {
Ime::Commit(text) => {
app.send_event(FreyaEvent::Keyboard {
name: "keydown".to_string(),
key: Key::Character(text),
code: last_code,
modifiers: get_modifiers(modifiers_state),
});
}
_ => {}
}
}
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
WindowEvent::MouseInput { state, button, .. } => {
let event_name = match state {
Expand Down
2 changes: 2 additions & 0 deletions crates/renderer/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ impl<T: Clone> WindowEnv<T> {
if let Some(on_setup) = on_setup {
(on_setup)(self.window_mut())
}

self.window.set_ime_allowed(true);
}

/// Run the `on_exit` callback that was passed to the launch function
Expand Down

0 comments on commit 3668bb8

Please sign in to comment.