Skip to main content

volren_core/interaction/
mod.rs

1//! Abstract input events and interaction styles.
2//!
3//! The library is windowing-system agnostic. Consumers bridge their platform
4//! events (winit, SDL2, etc.) to the abstract types defined here.
5
6mod events;
7mod image_slice;
8mod trackball;
9
10pub use events::{
11    InteractionContext, InteractionResult, Key, KeyEvent, Modifiers, MouseButton, MouseEvent,
12    MouseEventKind,
13};
14pub use image_slice::ImageSliceStyle;
15pub use trackball::TrackballStyle;
16
17use crate::camera::Camera;
18
19/// An interaction style drives a [`Camera`] in response to abstract input events.
20///
21/// # VTK Equivalent
22/// `vtkInteractorStyle` — specifically `vtkInteractorStyleTrackballCamera`
23/// and `vtkInteractorStyleImage`.
24pub trait InteractionStyle: Send + Sync {
25    /// Handle a mouse event and potentially mutate the camera.
26    ///
27    /// Returns an [`InteractionResult`] describing what changed so the
28    /// consumer knows whether to trigger a re-render.
29    fn on_mouse_event(
30        &mut self,
31        event: &MouseEvent,
32        ctx: &InteractionContext,
33        camera: &mut Camera,
34    ) -> InteractionResult;
35
36    /// Handle a key event.
37    fn on_key_event(
38        &mut self,
39        event: &KeyEvent,
40        ctx: &InteractionContext,
41        camera: &mut Camera,
42    ) -> InteractionResult;
43}