summaryrefslogtreecommitdiffstats
path: root/winit
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 /winit
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 'winit')
-rw-r--r--winit/src/program/window_manager.rs98
1 files changed, 56 insertions, 42 deletions
diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs
index d5b334df..25d3ad9c 100644
--- a/winit/src/program/window_manager.rs
+++ b/winit/src/program/window_manager.rs
@@ -75,6 +75,7 @@ where
mouse_interaction: mouse::Interaction::None,
redraw_at: None,
preedit: None,
+ ime_state: None,
},
);
@@ -166,6 +167,7 @@ where
pub renderer: P::Renderer,
pub redraw_at: Option<Instant>,
preedit: Option<Preedit<P::Renderer>>,
+ ime_state: Option<(Point, input_method::Purpose)>,
}
impl<P, C> Window<P, C>
@@ -206,52 +208,39 @@ where
pub fn request_input_method(&mut self, input_method: InputMethod) {
match input_method {
- InputMethod::None => {}
InputMethod::Disabled => {
- self.raw.set_ime_allowed(false);
+ self.disable_ime();
}
- InputMethod::Allowed | InputMethod::Open { .. } => {
- self.raw.set_ime_allowed(true);
- }
- }
-
- if let InputMethod::Open {
- position,
- purpose,
- preedit,
- } = input_method
- {
- self.raw.set_ime_cursor_area(
- LogicalPosition::new(position.x, position.y),
- LogicalSize::new(10, 10), // TODO?
- );
-
- self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
-
- if let Some(preedit) = preedit {
- if preedit.content.is_empty() {
- self.preedit = None;
- } else if let Some(overlay) = &mut self.preedit {
- overlay.update(
- position,
- &preedit,
- self.state.background_color(),
- &self.renderer,
- );
- } else {
- let mut overlay = Preedit::new();
- overlay.update(
- position,
- &preedit,
- self.state.background_color(),
- &self.renderer,
- );
-
- self.preedit = Some(overlay);
+ InputMethod::Enabled {
+ position,
+ purpose,
+ preedit,
+ } => {
+ self.enable_ime(position, purpose);
+
+ if let Some(preedit) = preedit {
+ if preedit.content.is_empty() {
+ self.preedit = None;
+ } else if let Some(overlay) = &mut self.preedit {
+ overlay.update(
+ position,
+ &preedit,
+ self.state.background_color(),
+ &self.renderer,
+ );
+ } else {
+ let mut overlay = Preedit::new();
+ overlay.update(
+ position,
+ &preedit,
+ self.state.background_color(),
+ &self.renderer,
+ );
+
+ self.preedit = Some(overlay);
+ }
}
}
- } else {
- self.preedit = None;
}
}
@@ -268,6 +257,31 @@ where
);
}
}
+
+ fn enable_ime(&mut self, position: Point, purpose: input_method::Purpose) {
+ if self.ime_state.is_none() {
+ self.raw.set_ime_allowed(true);
+ }
+
+ if self.ime_state != Some((position, purpose)) {
+ self.raw.set_ime_cursor_area(
+ LogicalPosition::new(position.x, position.y),
+ LogicalSize::new(10, 10), // TODO?
+ );
+ self.raw.set_ime_purpose(conversion::ime_purpose(purpose));
+
+ self.ime_state = Some((position, purpose));
+ }
+ }
+
+ fn disable_ime(&mut self) {
+ if self.ime_state.is_some() {
+ self.raw.set_ime_allowed(false);
+ self.ime_state = None;
+ }
+
+ self.preedit = None;
+ }
}
struct Preedit<Renderer>