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 {
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();