From a3e76f64721b247b93cfa8ca8d4c4f15087ab96d Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 4 Jan 2024 17:08:05 -0800 Subject: [PATCH] Calling set_ime_cursor_location Currently passing the entire input area because it's easy. Not closing the issue because the correct thing to do would be to constrain the location to a smaller area on the current line (or the current line). Refs #122 --- Cargo.lock | 4 ++-- Cargo.toml | 2 ++ src/widgets/input.rs | 1 + src/window.rs | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e83ec8..4203424 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,9 +738,9 @@ dependencies = [ [[package]] name = "figures" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "813f0f9e0ba0d378a8e2cd51df24dd724ba8fbc07baa3dd192813eeba407ea86" +checksum = "2c59ceec98cdba2db23e28e753cf7ff1e7e726d8655f3dce45f0e40820ae075e" dependencies = [ "bytemuck", "euclid", diff --git a/Cargo.toml b/Cargo.toml index 504993e..0e6e906 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,8 @@ image = { version = "0.24.7", features = ["png"] } # kludgine = { path = "../kludgine" } # [patch."https://github.com/khonsulabs/appit"] # appit = { path = "../appit" } +# [patch."https://github.com/khonsulabs/figures"] +# figures = { path = "../figures" } [profile.dev.package."*"] opt-level = 2 diff --git a/src/widgets/input.rs b/src/widgets/input.rs index 515bdc0..0aec7fe 100644 --- a/src/widgets/input.rs +++ b/src/widgets/input.rs @@ -1057,6 +1057,7 @@ where if context.focused(false) { context.set_ime_allowed(true); + context.set_ime_location(context.gfx.region()); context.set_ime_purpose(if info.masked { ImePurpose::Password } else { diff --git a/src/window.rs b/src/window.rs index b93a7dd..710e712 100644 --- a/src/window.rs +++ b/src/window.rs @@ -120,6 +120,15 @@ pub trait PlatformWindowImplementation { winit.set_ime_allowed(allowed); } } + /// Sets the location of the cursor. + fn set_ime_location(&self, location: Rect) { + if let Some(winit) = self.winit() { + winit.set_ime_cursor_area( + PhysicalPosition::from(location.origin), + PhysicalSize::from(location.size), + ); + } + } /// Sets the current [`Ime`] purpose. /// @@ -220,6 +229,8 @@ pub trait PlatformWindow { /// Sets the current cursor icon to `cursor`. fn set_cursor_icon(&mut self, cursor: CursorIcon); + /// Sets the location of the cursor. + fn set_ime_location(&self, location: Rect); /// Sets whether [`Ime`] events should be enabled. fn set_ime_allowed(&self, allowed: bool); /// Sets the current [`Ime`] purpose. @@ -422,6 +433,10 @@ where fn request_inner_size(&mut self, inner_size: Size) { self.window.request_inner_size(inner_size); } + + fn set_ime_location(&self, location: Rect) { + self.window.set_ime_location(location); + } } /// The attributes of a Cushy window.