Browse Source

IME for chinese (#4436)

* Completed.

* Closes #4430

IME for chinese
pull/4482/head
rustbasic 6 months ago
committed by GitHub
parent
commit
a9efbcff36
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 42
      crates/egui-winit/src/lib.rs

42
crates/egui-winit/src/lib.rs

@ -342,20 +342,12 @@ impl State {
// We use input_method_editor_started to manually insert CompositionStart
// between Commits.
match ime {
winit::event::Ime::Enabled => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Enabled));
self.has_sent_ime_enabled = true;
winit::event::Ime::Enabled => {}
winit::event::Ime::Preedit(_, None) => {
self.ime_event_enable();
}
winit::event::Ime::Preedit(_, None) => {}
winit::event::Ime::Preedit(text, Some(_cursor)) => {
if !self.has_sent_ime_enabled {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Enabled));
self.has_sent_ime_enabled = true;
}
self.ime_event_enable();
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Preedit(text.clone())));
@ -364,16 +356,10 @@ impl State {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Commit(text.clone())));
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Disabled));
self.has_sent_ime_enabled = false;
self.ime_event_disable();
}
winit::event::Ime::Disabled => {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Disabled));
self.has_sent_ime_enabled = false;
self.ime_event_disable();
}
};
@ -492,6 +478,22 @@ impl State {
}
}
pub fn ime_event_enable(&mut self) {
if !self.has_sent_ime_enabled {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Enabled));
self.has_sent_ime_enabled = true;
}
}
pub fn ime_event_disable(&mut self) {
self.egui_input
.events
.push(egui::Event::Ime(egui::ImeEvent::Disabled));
self.has_sent_ime_enabled = false;
}
pub fn on_mouse_motion(&mut self, delta: (f64, f64)) {
self.egui_input.events.push(egui::Event::MouseMoved(Vec2 {
x: delta.0 as f32,

Loading…
Cancel
Save