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 <lucasmeurer96@gmail.com>
This commit is contained in:
parent
8d9e42413a
commit
fed2ab5df3
|
|
@ -45,6 +45,7 @@ fn fit_to_rect_in_scene(
|
||||||
#[must_use = "You should call .show()"]
|
#[must_use = "You should call .show()"]
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
zoom_range: Rangef,
|
zoom_range: Rangef,
|
||||||
|
sense: Sense,
|
||||||
max_inner_size: Vec2,
|
max_inner_size: Vec2,
|
||||||
drag_pan_buttons: DragPanButtons,
|
drag_pan_buttons: DragPanButtons,
|
||||||
}
|
}
|
||||||
|
|
@ -76,6 +77,7 @@ impl Default for Scene {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
zoom_range: Rangef::new(f32::EPSILON, 1.0),
|
zoom_range: Rangef::new(f32::EPSILON, 1.0),
|
||||||
|
sense: Sense::click_and_drag(),
|
||||||
max_inner_size: Vec2::splat(1000.0),
|
max_inner_size: Vec2::splat(1000.0),
|
||||||
drag_pan_buttons: DragPanButtons::all(),
|
drag_pan_buttons: DragPanButtons::all(),
|
||||||
}
|
}
|
||||||
|
|
@ -88,6 +90,17 @@ impl Scene {
|
||||||
Default::default()
|
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.
|
/// Set the allowed zoom range.
|
||||||
///
|
///
|
||||||
/// The default zoom range is `0.0..=1.0`,
|
/// The default zoom range is `0.0..=1.0`,
|
||||||
|
|
@ -184,7 +197,7 @@ impl Scene {
|
||||||
UiBuilder::new()
|
UiBuilder::new()
|
||||||
.layer_id(scene_layer_id)
|
.layer_id(scene_layer_id)
|
||||||
.max_rect(Rect::from_min_size(Pos2::ZERO, self.max_inner_size))
|
.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();
|
let mut pan_response = local_ui.response();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue