Refactor and simplify input_method API
This commit is contained in:
parent
d5ee9c2795
commit
ae10adda74
19 changed files with 540 additions and 472 deletions
|
|
@ -141,6 +141,7 @@ pub fn window_event(
|
|||
scale_factor: f64,
|
||||
modifiers: winit::keyboard::ModifiersState,
|
||||
) -> Option<Event> {
|
||||
use winit::event::Ime;
|
||||
use winit::event::WindowEvent;
|
||||
|
||||
match event {
|
||||
|
|
@ -284,19 +285,15 @@ pub fn window_event(
|
|||
self::modifiers(new_modifiers.state()),
|
||||
)))
|
||||
}
|
||||
WindowEvent::Ime(ime) => {
|
||||
use winit::event::Ime;
|
||||
println!("ime event: {:?}", ime);
|
||||
Some(Event::InputMethod(match ime {
|
||||
Ime::Enabled => input_method::Event::Enabled,
|
||||
Ime::Preedit(s, size) => input_method::Event::Preedit(
|
||||
s,
|
||||
size.map(|(start, end)| (start..end)),
|
||||
),
|
||||
Ime::Commit(s) => input_method::Event::Commit(s),
|
||||
Ime::Disabled => input_method::Event::Disabled,
|
||||
}))
|
||||
}
|
||||
WindowEvent::Ime(event) => Some(Event::InputMethod(match event {
|
||||
Ime::Enabled => input_method::Event::Opened,
|
||||
Ime::Preedit(content, size) => input_method::Event::Preedit(
|
||||
content,
|
||||
size.map(|(start, end)| (start..end)),
|
||||
),
|
||||
Ime::Commit(content) => input_method::Event::Commit(content),
|
||||
Ime::Disabled => input_method::Event::Closed,
|
||||
})),
|
||||
WindowEvent::Focused(focused) => Some(Event::Window(if focused {
|
||||
window::Event::Focused
|
||||
} else {
|
||||
|
|
@ -1174,7 +1171,7 @@ pub fn resize_direction(
|
|||
}
|
||||
}
|
||||
|
||||
/// Converts some [`window::Icon`] into it's `winit` counterpart.
|
||||
/// Converts some [`window::Icon`] into its `winit` counterpart.
|
||||
///
|
||||
/// Returns `None` if there is an error during the conversion.
|
||||
pub fn icon(icon: window::Icon) -> Option<winit::window::Icon> {
|
||||
|
|
@ -1183,6 +1180,17 @@ pub fn icon(icon: window::Icon) -> Option<winit::window::Icon> {
|
|||
winit::window::Icon::from_rgba(pixels, size.width, size.height).ok()
|
||||
}
|
||||
|
||||
/// Convertions some [`input_method::Purpose`] to its `winit` counterpart.
|
||||
pub fn ime_purpose(
|
||||
purpose: input_method::Purpose,
|
||||
) -> winit::window::ImePurpose {
|
||||
match purpose {
|
||||
input_method::Purpose::Normal => winit::window::ImePurpose::Normal,
|
||||
input_method::Purpose::Secure => winit::window::ImePurpose::Password,
|
||||
input_method::Purpose::Terminal => winit::window::ImePurpose::Terminal,
|
||||
}
|
||||
}
|
||||
|
||||
// See: https://en.wikipedia.org/wiki/Private_Use_Areas
|
||||
fn is_private_use(c: char) -> bool {
|
||||
('\u{E000}'..='\u{F8FF}').contains(&c)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue