Draft input_method support

This commit is contained in:
KENZ 2025-01-10 07:12:31 +09:00 committed by Héctor Ramón Jiménez
parent 599d8b560b
commit 7db5256b72
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
13 changed files with 420 additions and 27 deletions

View file

@ -4,7 +4,7 @@ use crate::core::{Color, Size};
use crate::graphics::Viewport;
use crate::program::Program;
use winit::event::{Touch, WindowEvent};
use winit::event::{Ime, Touch, WindowEvent};
use winit::window::Window;
use std::fmt::{Debug, Formatter};
@ -22,6 +22,7 @@ where
modifiers: winit::keyboard::ModifiersState,
theme: P::Theme,
style: theme::Style,
preedit: String,
}
impl<P: Program> Debug for State<P>
@ -73,6 +74,7 @@ where
modifiers: winit::keyboard::ModifiersState::default(),
theme,
style,
preedit: String::default(),
}
}
@ -136,6 +138,11 @@ where
self.style.text_color
}
/// TODO
pub fn preedit(&self) -> String {
self.preedit.clone()
}
/// Processes the provided window event and updates the [`State`] accordingly.
pub fn update(
&mut self,
@ -179,6 +186,11 @@ where
WindowEvent::ModifiersChanged(new_modifiers) => {
self.modifiers = new_modifiers.state();
}
WindowEvent::Ime(ime) => {
if let Ime::Preedit(text, _) = ime {
self.preedit = text.clone();
}
}
#[cfg(feature = "debug")]
WindowEvent::KeyboardInput {
event: