-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new
Ime
event for desktop platforms
This commit brings new Ime event to account for preedit state of input method, also adding `Window::set_ime_allowed` to toggle IME input on the particular window. This commit implements API as designed in #1497 for desktop platforms. Co-authored-by: Artur Kovacs <[email protected]> Co-authored-by: Markus Siglreithmaier <[email protected]> Co-authored-by: Murarth <[email protected]> Co-authored-by: Yusuke Kominami <[email protected]> Co-authored-by: moko256 <[email protected]>
- Loading branch information
1 parent
b4175c1
commit f04fa5d
Showing
30 changed files
with
1,331 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use log::LevelFilter; | ||
use simple_logger::SimpleLogger; | ||
use winit::{ | ||
dpi::PhysicalPosition, | ||
event::{ElementState, Event, Ime, VirtualKeyCode, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
window::WindowBuilder, | ||
}; | ||
|
||
fn main() { | ||
SimpleLogger::new() | ||
.with_level(LevelFilter::Trace) | ||
.init() | ||
.unwrap(); | ||
|
||
println!("IME position will system default"); | ||
println!("Click to set IME position to cursor's"); | ||
println!("Press F2 to toggle IME. See the documentation of `set_ime_allowed` for more info"); | ||
|
||
let event_loop = EventLoop::new(); | ||
|
||
let window = WindowBuilder::new() | ||
.with_inner_size(winit::dpi::LogicalSize::new(256f64, 128f64)) | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
let mut ime_allowed = true; | ||
window.set_ime_allowed(ime_allowed); | ||
|
||
let mut may_show_ime = false; | ||
let mut cursor_position = PhysicalPosition::new(0.0, 0.0); | ||
let mut ime_pos = PhysicalPosition::new(0.0, 0.0); | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
*control_flow = ControlFlow::Wait; | ||
match event { | ||
Event::WindowEvent { | ||
event: WindowEvent::CloseRequested, | ||
.. | ||
} => *control_flow = ControlFlow::Exit, | ||
Event::WindowEvent { | ||
event: WindowEvent::CursorMoved { position, .. }, | ||
.. | ||
} => { | ||
cursor_position = position; | ||
} | ||
Event::WindowEvent { | ||
event: | ||
WindowEvent::MouseInput { | ||
state: ElementState::Released, | ||
.. | ||
}, | ||
.. | ||
} => { | ||
println!( | ||
"Setting ime position to {}, {}", | ||
cursor_position.x, cursor_position.y | ||
); | ||
ime_pos = cursor_position; | ||
if may_show_ime { | ||
window.set_ime_position(ime_pos); | ||
} | ||
} | ||
Event::WindowEvent { | ||
event: WindowEvent::Ime(event), | ||
.. | ||
} => { | ||
println!("{:?}", event); | ||
may_show_ime = event != Ime::Disabled; | ||
if may_show_ime { | ||
window.set_ime_position(ime_pos); | ||
} | ||
} | ||
Event::WindowEvent { | ||
event: WindowEvent::ReceivedCharacter(ch), | ||
.. | ||
} => { | ||
println!("ch: {:?}", ch); | ||
} | ||
Event::WindowEvent { | ||
event: WindowEvent::KeyboardInput { input, .. }, | ||
.. | ||
} => { | ||
println!("key: {:?}", input); | ||
|
||
if input.state == ElementState::Pressed | ||
&& input.virtual_keycode == Some(VirtualKeyCode::F2) | ||
{ | ||
ime_allowed = !ime_allowed; | ||
window.set_ime_allowed(ime_allowed); | ||
println!("\nIME: {}\n", ime_allowed); | ||
} | ||
} | ||
_ => (), | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.