summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-12 08:46:35 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2025-02-12 08:46:35 +0100
commit7979125ed793918dd4a0e5a1ddec8d17bffbd5bf (patch)
tree6633f5f9bf45d4c7378afb1480617a7a247d0a89 /core
parent97f1db3783dca5a4f60a9f89668613de4dfe9edd (diff)
downloadiced-7979125ed793918dd4a0e5a1ddec8d17bffbd5bf.tar.gz
iced-7979125ed793918dd4a0e5a1ddec8d17bffbd5bf.tar.bz2
iced-7979125ed793918dd4a0e5a1ddec8d17bffbd5bf.zip
Simplify `InputMethod` API with only two states
Co-authored-by: rhysd <lin90162@yahoo.co.jp> Co-authored-by: KENZ <KENZ.gelsoft@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/src/input_method.rs44
-rw-r--r--core/src/shell.rs2
2 files changed, 14 insertions, 32 deletions
diff --git a/core/src/input_method.rs b/core/src/input_method.rs
index 9c83b083..cd8d459d 100644
--- a/core/src/input_method.rs
+++ b/core/src/input_method.rs
@@ -6,14 +6,10 @@ use std::ops::Range;
/// The input method strategy of a widget.
#[derive(Debug, Clone, PartialEq)]
pub enum InputMethod<T = String> {
- /// No input method strategy has been specified.
- None,
- /// No input method is allowed.
+ /// Input method is disabled.
Disabled,
- /// Input methods are allowed, but not open yet.
- Allowed,
- /// Input method is open.
- Open {
+ /// Input method is enabled.
+ Enabled {
/// The position at which the input method dialog should be placed.
position: Point,
/// The [`Purpose`] of the input method.
@@ -91,13 +87,13 @@ impl InputMethod {
/// # use iced_core::input_method::{InputMethod, Purpose, Preedit};
/// # use iced_core::Point;
///
- /// let open = InputMethod::Open {
+ /// let open = InputMethod::Enabled {
/// position: Point::ORIGIN,
/// purpose: Purpose::Normal,
/// preedit: Some(Preedit { content: "1".to_owned(), selection: None, text_size: None }),
/// };
///
- /// let open_2 = InputMethod::Open {
+ /// let open_2 = InputMethod::Enabled {
/// position: Point::ORIGIN,
/// purpose: Purpose::Secure,
/// preedit: Some(Preedit { content: "2".to_owned(), selection: None, text_size: None }),
@@ -105,12 +101,6 @@ impl InputMethod {
///
/// let mut ime = InputMethod::Disabled;
///
- /// ime.merge(&InputMethod::<String>::Allowed);
- /// assert_eq!(ime, InputMethod::Allowed);
- ///
- /// ime.merge(&InputMethod::<String>::Disabled);
- /// assert_eq!(ime, InputMethod::Allowed);
- ///
/// ime.merge(&open);
/// assert_eq!(ime, open);
///
@@ -118,22 +108,16 @@ impl InputMethod {
/// assert_eq!(ime, open);
/// ```
pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) {
- match (&self, other) {
- (InputMethod::Open { .. }, _)
- | (
- InputMethod::Allowed,
- InputMethod::None | InputMethod::Disabled,
- )
- | (InputMethod::Disabled, InputMethod::None) => {}
- _ => {
- *self = other.to_owned();
- }
+ if let InputMethod::Enabled { .. } = self {
+ return;
}
+
+ *self = other.to_owned();
}
/// Returns true if the [`InputMethod`] is open.
- pub fn is_open(&self) -> bool {
- matches!(self, Self::Open { .. })
+ pub fn is_enabled(&self) -> bool {
+ matches!(self, Self::Enabled { .. })
}
}
@@ -144,14 +128,12 @@ impl<T> InputMethod<T> {
T: AsRef<str>,
{
match self {
- Self::None => InputMethod::None,
Self::Disabled => InputMethod::Disabled,
- Self::Allowed => InputMethod::Allowed,
- Self::Open {
+ Self::Enabled {
position,
purpose,
preedit,
- } => InputMethod::Open {
+ } => InputMethod::Enabled {
position: *position,
purpose: *purpose,
preedit: preedit.as_ref().map(Preedit::to_owned),
diff --git a/core/src/shell.rs b/core/src/shell.rs
index 509e3822..56250e2e 100644
--- a/core/src/shell.rs
+++ b/core/src/shell.rs
@@ -27,7 +27,7 @@ impl<'a, Message> Shell<'a, Message> {
redraw_request: window::RedrawRequest::Wait,
is_layout_invalid: false,
are_widgets_invalid: false,
- input_method: InputMethod::None,
+ input_method: InputMethod::Disabled,
}
}