From fed2ab5df3c0c92c9b18cd5ab80785302bcaf275 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Tue, 29 Apr 2025 20:07:39 +1000 Subject: [PATCH] feat: Add `Scene::sense` option for customising how `Scene` should respond to user input (#5893) Allows for specifying how the `Scene` should respond to user input. With #5892, closes #5891. --- Edit: Failing tests unrelated and appear on master: https://github.com/emilk/egui/actions/runs/14330259861/job/40164414607. --------- Co-authored-by: Lucas Meurer --- crates/egui/src/containers/scene.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/containers/scene.rs b/crates/egui/src/containers/scene.rs index e5a35032..aaca3729 100644 --- a/crates/egui/src/containers/scene.rs +++ b/crates/egui/src/containers/scene.rs @@ -45,6 +45,7 @@ fn fit_to_rect_in_scene( #[must_use = "You should call .show()"] pub struct Scene { zoom_range: Rangef, + sense: Sense, max_inner_size: Vec2, drag_pan_buttons: DragPanButtons, } @@ -76,6 +77,7 @@ impl Default for Scene { fn default() -> Self { Self { zoom_range: Rangef::new(f32::EPSILON, 1.0), + sense: Sense::click_and_drag(), max_inner_size: Vec2::splat(1000.0), drag_pan_buttons: DragPanButtons::all(), } @@ -88,6 +90,17 @@ impl Scene { Default::default() } + /// Specify what type of input the scene should respond to. + /// + /// The default is `Sense::click_and_drag()`. + /// + /// Set this to `Sense::hover()` to disable panning via clicking and dragging. + #[inline] + pub fn sense(mut self, sense: Sense) -> Self { + self.sense = sense; + self + } + /// Set the allowed zoom range. /// /// The default zoom range is `0.0..=1.0`, @@ -184,7 +197,7 @@ impl Scene { UiBuilder::new() .layer_id(scene_layer_id) .max_rect(Rect::from_min_size(Pos2::ZERO, self.max_inner_size)) - .sense(Sense::click_and_drag()), + .sense(self.sense), ); let mut pan_response = local_ui.response();