use scale factor for touches in UI focus (#16522)

# Objective

- Fix the issue mentioned on iOS in
https://github.com/bevyengine/bevy/issues/16363#issuecomment-2499766031
- touch on the button in the mobile example are not detected

## Solution

- UI focus now uses the window scale factor for touches
This commit is contained in:
François Mockers 2024-11-26 22:23:12 +01:00 committed by GitHub
parent 6ce566cb07
commit 98d433a174
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -197,16 +197,19 @@ pub fn ui_focus_system(
else { else {
return None; return None;
}; };
let window = windows.get(window_ref.entity()).ok()?;
let viewport_position = camera let viewport_position = camera
.physical_viewport_rect() .physical_viewport_rect()
.map(|rect| rect.min.as_vec2()) .map(|rect| rect.min.as_vec2())
.unwrap_or_default(); .unwrap_or_default();
windows window
.get(window_ref.entity()) .physical_cursor_position()
.ok() .or_else(|| {
.and_then(Window::physical_cursor_position) touches_input
.or_else(|| touches_input.first_pressed_position()) .first_pressed_position()
.map(|pos| pos * window.scale_factor())
})
.map(|cursor_position| (entity, cursor_position - viewport_position)) .map(|cursor_position| (entity, cursor_position - viewport_position))
}) })
.collect(); .collect();