Skip to content

Commit

Permalink
Tweaking the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sumibi-yakitori committed Nov 1, 2021
1 parent b999d9f commit f99b0b8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions egui_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,13 +1221,14 @@ fn is_mobile() -> Option<bool> {
// On mobile devices, there is no need to do that.
fn move_text_cursor(cursor: &Option<egui::Pos2>, canvas_id: &str) -> Option<()> {
let style = text_agent().style();
let rect = text_agent().get_bounding_client_rect();
// Note: movint agent on mobile devices will lead to unpredictable scroll.
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 - rect.height() as f32);
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 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;
Expand Down

0 comments on commit f99b0b8

Please sign in to comment.