From 83e8a597e30143ce12a1b9927ba75bf3c7876e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Tue, 26 Nov 2024 21:30:55 +0100 Subject: [PATCH] use scale factor for touches in UI focus --- crates/bevy_ui/src/focus.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index a2eb37ee31989..cc1d68526a648 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -197,16 +197,19 @@ pub fn ui_focus_system( else { return None; }; + let window = windows.get(window_ref.entity()).ok()?; let viewport_position = camera .physical_viewport_rect() .map(|rect| rect.min.as_vec2()) .unwrap_or_default(); - windows - .get(window_ref.entity()) - .ok() - .and_then(Window::physical_cursor_position) - .or_else(|| touches_input.first_pressed_position()) + window + .physical_cursor_position() + .or_else(|| { + touches_input + .first_pressed_position() + .map(|pos| pos * window.scale_factor()) + }) .map(|cursor_position| (entity, cursor_position - viewport_position)) }) .collect();