fix scroll

This commit is contained in:
Stephen Adamson
2025-05-28 11:03:57 +01:00
parent e8d3f1bafb
commit 0def6af6e8
+6 -2
View File
@@ -82,6 +82,7 @@ pub fn spawn_panning_camera(mut commands: Commands) {
pub fn scroll_events(mut evr_scroll: EventReader<MouseWheel>, mut query: Query<&mut Projection>) { pub fn scroll_events(mut evr_scroll: EventReader<MouseWheel>, mut query: Query<&mut Projection>) {
const ZOOM_SENSITIVITY: f32 = 0.035; const ZOOM_SENSITIVITY: f32 = 0.035;
const PIXEL_SENSITIVITY: f32 = 0.001;
const MIN_SCALE: f32 = 0.2; const MIN_SCALE: f32 = 0.2;
const MAX_SCALE: f32 = 2.0; const MAX_SCALE: f32 = 2.0;
@@ -90,13 +91,16 @@ pub fn scroll_events(mut evr_scroll: EventReader<MouseWheel>, mut query: Query<&
let current_scale = match &*projection_component { let current_scale = match &*projection_component {
Projection::Orthographic(ortho_proj) => ortho_proj.scale, Projection::Orthographic(ortho_proj) => ortho_proj.scale,
Projection::Perspective(_) => 1.0, Projection::Perspective(_) => 1.0,
Projection::Custom(_custom_projection) => todo!(), Projection::Custom(_custom_projection) => {
continue;
}
}; };
let new_scale = match ev.unit { let new_scale = match ev.unit {
MouseScrollUnit::Line => current_scale + ev.y * ZOOM_SENSITIVITY, MouseScrollUnit::Line => current_scale + ev.y * ZOOM_SENSITIVITY,
MouseScrollUnit::Pixel => todo!(), MouseScrollUnit::Pixel => current_scale + ev.y * PIXEL_SENSITIVITY,
}; };
*projection_component = Projection::Orthographic(OrthographicProjection { *projection_component = Projection::Orthographic(OrthographicProjection {
scale: new_scale.max(MIN_SCALE).min(MAX_SCALE), scale: new_scale.max(MIN_SCALE).min(MAX_SCALE),
..OrthographicProjection::default_2d() ..OrthographicProjection::default_2d()