eframe web: Position the IME input position in the middle of the cursor

This commit is contained in:
Emil Ernerfeldt 2024-07-01 16:08:20 +02:00
parent d271718065
commit 051b90bfc7
1 changed files with 5 additions and 4 deletions

View File

@ -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(())
}