Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui scale fix #279

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion backends/bevy_picking_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use bevy_ui::{prelude::*, RelativeCursorPosition, UiStack};
use bevy_window::PrimaryWindow;

use bevy_picking_core::backend::prelude::*;
use bevy_picking_core::pointer::Location;

/// Commonly used imports for the [`bevy_picking_ui`](crate) crate.
pub mod prelude {
Expand Down Expand Up @@ -68,9 +69,11 @@ pub fn ui_picking(
cameras: Query<(Entity, &Camera, Option<&UiCameraConfig>)>,
primary_window: Query<Entity, With<PrimaryWindow>>,
ui_stack: Res<UiStack>,
ui_scale: Option<Res<UiScale>>,
mut node_query: Query<NodeQuery>,
mut output: EventWriter<PointerHits>,
) {
let ui_scale = ui_scale.map(|f| f.0).unwrap_or(1.0) as f32;
for (pointer, location) in pointers.iter().filter_map(|(pointer, pointer_location)| {
pointer_location
.location()
Expand All @@ -83,7 +86,16 @@ pub fn ui_picking(
}
false
})
.map(|loc| (pointer, loc))
.cloned()
.map(|loc| {
(
pointer,
Location {
position: loc.position / ui_scale,
..loc
},
)
})
}) {
let window_entity = primary_window.single();

Expand Down