Add neutral None variant to InputMethod

This commit is contained in:
Héctor Ramón Jiménez 2025-02-02 21:06:50 +01:00
parent ae10adda74
commit db990b77e4
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 19 additions and 9 deletions

View file

@ -6,6 +6,8 @@ use std::ops::Range;
/// The input method strategy of a widget. /// The input method strategy of a widget.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum InputMethod<T = String> { pub enum InputMethod<T = String> {
/// No input method strategy has been specified.
None,
/// No input method is allowed. /// No input method is allowed.
Disabled, Disabled,
/// Input methods are allowed, but not open yet. /// Input methods are allowed, but not open yet.
@ -73,7 +75,7 @@ impl InputMethod {
/// ``` /// ```
pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) { pub fn merge<T: AsRef<str>>(&mut self, other: &InputMethod<T>) {
match other { match other {
InputMethod::Disabled => {} InputMethod::None => {}
InputMethod::Open { InputMethod::Open {
position, position,
purpose, purpose,
@ -88,10 +90,15 @@ impl InputMethod {
.map(str::to_owned), .map(str::to_owned),
}; };
} }
InputMethod::Allowed if matches!(self, Self::Disabled) => { InputMethod::Allowed
if matches!(self, Self::None | Self::Disabled) =>
{
*self = Self::Allowed; *self = Self::Allowed;
} }
InputMethod::Allowed => {} InputMethod::Disabled if matches!(self, Self::None) => {
*self = Self::Disabled;
}
_ => {}
} }
} }
} }

View file

@ -27,7 +27,7 @@ impl<'a, Message> Shell<'a, Message> {
redraw_request: window::RedrawRequest::Wait, redraw_request: window::RedrawRequest::Wait,
is_layout_invalid: false, is_layout_invalid: false,
are_widgets_invalid: false, are_widgets_invalid: false,
input_method: InputMethod::Disabled, input_method: InputMethod::None,
} }
} }

View file

@ -189,7 +189,7 @@ where
let mut outdated = false; let mut outdated = false;
let mut redraw_request = window::RedrawRequest::Wait; let mut redraw_request = window::RedrawRequest::Wait;
let mut input_method = InputMethod::Disabled; let mut input_method = InputMethod::None;
let mut manual_overlay = ManuallyDrop::new( let mut manual_overlay = ManuallyDrop::new(
self.root self.root

View file

@ -203,10 +203,13 @@ where
} }
pub fn request_input_method(&mut self, input_method: InputMethod) { pub fn request_input_method(&mut self, input_method: InputMethod) {
self.raw.set_ime_allowed(match input_method { match input_method {
InputMethod::Disabled => false, InputMethod::None => {}
InputMethod::Allowed | InputMethod::Open { .. } => true, InputMethod::Disabled => self.raw.set_ime_allowed(false),
}); InputMethod::Allowed | InputMethod::Open { .. } => {
self.raw.set_ime_allowed(true)
}
}
if let InputMethod::Open { if let InputMethod::Open {
position, position,