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

@ -1,4 +1,5 @@
//! Handle events of a user interface.
use crate::input_method;
use crate::keyboard;
use crate::mouse;
use crate::touch;
@ -23,6 +24,9 @@ pub enum Event {
/// A touch event
Touch(touch::Event),
/// A input method event
InputMethod(input_method::Event),
}
/// The status of an [`Event`] after being processed.

24
core/src/input_method.rs Normal file
View file

@ -0,0 +1,24 @@
//! Listen to input method events.
/// A input method event.
///
/// _**Note:** This type is largely incomplete! If you need to track
/// additional events, feel free to [open an issue] and share your use case!_
///
/// [open an issue]: https://github.com/iced-rs/iced/issues
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
// These events correspond to underlying winit ime events.
// https://docs.rs/winit/latest/winit/event/enum.Ime.html
/// the IME was enabled.
Enabled,
/// new composing text should be set at the cursor position.
Preedit(String, Option<(usize, usize)>),
/// text should be inserted into the editor widget.
Commit(String),
/// the IME was disabled.
Disabled,
}

View file

@ -17,6 +17,7 @@ pub mod event;
pub mod font;
pub mod gradient;
pub mod image;
pub mod input_method;
pub mod keyboard;
pub mod layout;
pub mod mouse;
@ -72,6 +73,7 @@ pub use renderer::Renderer;
pub use rotation::Rotation;
pub use settings::Settings;
pub use shadow::Shadow;
pub use shell::CaretInfo;
pub use shell::Shell;
pub use size::Size;
pub use svg::Svg;

View file

@ -1,6 +1,15 @@
use crate::event;
use crate::time::Instant;
use crate::window;
use crate::{event, Point};
/// TODO
#[derive(Clone, Copy, Debug)]
pub struct CaretInfo {
/// TODO
pub position: Point,
/// TODO
pub input_method_allowed: bool,
}
/// A connection to the state of a shell.
///
@ -15,6 +24,7 @@ pub struct Shell<'a, Message> {
redraw_request: Option<window::RedrawRequest>,
is_layout_invalid: bool,
are_widgets_invalid: bool,
caret_info: Option<CaretInfo>,
}
impl<'a, Message> Shell<'a, Message> {
@ -26,6 +36,7 @@ impl<'a, Message> Shell<'a, Message> {
redraw_request: None,
is_layout_invalid: false,
are_widgets_invalid: false,
caret_info: None,
}
}
@ -80,6 +91,16 @@ impl<'a, Message> Shell<'a, Message> {
self.redraw_request
}
/// TODO
pub fn update_caret_info(&mut self, caret_info: Option<CaretInfo>) {
self.caret_info = caret_info.or(self.caret_info);
}
/// TODO
pub fn caret_info(&self) -> Option<CaretInfo> {
self.caret_info
}
/// Returns whether the current layout is invalid or not.
pub fn is_layout_invalid(&self) -> bool {
self.is_layout_invalid
@ -130,6 +151,8 @@ impl<'a, Message> Shell<'a, Message> {
);
}
self.update_caret_info(other.caret_info());
self.is_layout_invalid =
self.is_layout_invalid || other.is_layout_invalid;