Skip to content

Commit

Permalink
use scale factor for touches in UI focus (#16522)
Browse files Browse the repository at this point in the history
# Objective

- Fix the issue mentioned on iOS in
#16363 (comment)
- touch on the button in the mobile example are not detected

## Solution

- UI focus now uses the window scale factor for touches
  • Loading branch information
mockersf authored Nov 26, 2024
1 parent 6ce566c commit 98d433a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 98d433a

Please sign in to comment.