From 10c8ffa543e16c7e4fcac22d3be57fe9e7969709 Mon Sep 17 00:00:00 2001 From: sumibi-yakitori Date: Sat, 6 Nov 2021 18:33:43 +0900 Subject: [PATCH] Fix to limit X position of text agent to client width (#870) --- egui_web/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index 698dedb649b..fa82d838a1e 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -1217,13 +1217,13 @@ fn move_text_cursor(cursor: &Option, canvas_id: &str) -> Option<()> if is_mobile() == Some(false) { cursor.as_ref().and_then(|&egui::Pos2 { x, y }| { let canvas = canvas_element(canvas_id)?; - let y = (y + (canvas.scroll_top() + canvas.offset_top()) as f32).min( - canvas.client_height() as f32 - - text_agent().get_bounding_client_rect().height() as f32, - ); + let bounding_rect = text_agent().get_bounding_client_rect(); + let y = (y + (canvas.scroll_top() + canvas.offset_top()) as f32) + .min(canvas.client_height() as f32 - bounding_rect.height() as f32); let x = x + (canvas.scroll_left() + canvas.offset_left()) as f32; // Canvas is translated 50% horizontally in html. - let x = x - canvas.offset_width() as f32 / 2.0; + let x = (x - canvas.offset_width() as f32 / 2.0) + .min(canvas.client_width() as f32 - bounding_rect.width() as f32); style.set_property("position", "absolute").ok()?; style.set_property("top", &(y.to_string() + "px")).ok()?; style.set_property("left", &(x.to_string() + "px")).ok()