summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar KENZ <KENZ.gelsoft@gmail.com>2025-01-10 07:12:31 +0900
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-02 17:44:13 +0100
commit7db5256b720c3ecbe7c1cce7a1b47fd03151e03a (patch)
treeccf08e3f76e27d0871185b786ece83f970dddc77 /core
parent599d8b560bec8036c5ddda62a7bf0a540bdec396 (diff)
downloadiced-7db5256b720c3ecbe7c1cce7a1b47fd03151e03a.tar.gz
iced-7db5256b720c3ecbe7c1cce7a1b47fd03151e03a.tar.bz2
iced-7db5256b720c3ecbe7c1cce7a1b47fd03151e03a.zip
Draft `input_method` support
Diffstat (limited to 'core')
-rw-r--r--core/src/event.rs4
-rw-r--r--core/src/input_method.rs24
-rw-r--r--core/src/lib.rs2
-rw-r--r--core/src/shell.rs25
4 files changed, 54 insertions, 1 deletions
diff --git a/core/src/event.rs b/core/src/event.rs
index b6cf321e..323c5ffd 100644
--- a/core/src/event.rs
+++ b/core/src/event.rs
@@ -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.
diff --git a/core/src/input_method.rs b/core/src/input_method.rs
new file mode 100644
index 00000000..ceda39c3
--- /dev/null
+++ b/core/src/input_method.rs
@@ -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,
+}
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 16b3aa0f..c7c38044 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -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;
diff --git a/core/src/shell.rs b/core/src/shell.rs
index 12ebbaa8..d2c1b9ec 100644
--- a/core/src/shell.rs
+++ b/core/src/shell.rs
@@ -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;