From 051b90bfc7b702f6bce458fef4a1359f4ef77b39 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 1 Jul 2024 16:08:20 +0200 Subject: [PATCH] eframe web: Position the IME input position in the middle of the cursor --- crates/eframe/src/web/text_agent.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/web/text_agent.rs b/crates/eframe/src/web/text_agent.rs index 5ced0647..79f63ee0 100644 --- a/crates/eframe/src/web/text_agent.rs +++ b/crates/eframe/src/web/text_agent.rs @@ -119,13 +119,14 @@ impl TextAgent { let Some(ime) = ime else { return Ok(()) }; - let ime_pos = ime.cursor_rect.left_top(); let canvas_rect = super::canvas_content_rect(canvas); - let new_pos = canvas_rect.min + ime_pos.to_vec2(); + let cursor_rect = ime.cursor_rect.translate(canvas_rect.min.to_vec2()); let style = self.input.style(); - style.set_property("top", &format!("{}px", new_pos.y))?; - style.set_property("left", &format!("{}px", new_pos.x))?; + + // This is where the IME input will point to: + style.set_property("left", &format!("{}px", cursor_rect.center().x))?; + style.set_property("top", &format!("{}px", cursor_rect.center().y))?; Ok(()) }