oa/viewer/live_source.rs
1//! `ViewerLiveSource` trait and capabilities. Donor: `oa/ui/viewer.h`.
2
3use crate::input::InputEvent;
4use crate::ui::{PixelRect, Ui};
5pub use crate::viewer::types::ViewerLiveCapabilities;
6use crate::{Result, Runtime, Texture};
7
8/// Non-owning live GPU producer attached to the Viewer lifecycle.
9///
10/// Donor: `oa::ViewerLiveSource`.
11pub trait ViewerLiveSource {
12 fn capabilities(&self) -> ViewerLiveCapabilities;
13
14 /// Called once when the Viewer obtains an `Runtime`.
15 fn open(&mut self, runtime: &Runtime) -> Result<()>;
16
17 /// Per-frame update. `delta_ms` is the frame time in milliseconds.
18 fn update(&mut self, delta_ms: f32) -> Result<()>;
19
20 /// Optional camera/image surface presented by the Viewer's shared GPU 2D
21 /// canvas. The Viewer owns navigation, fit, zoom, pan and channel selection;
22 /// `render` draws only the source's overlays when this is provided.
23 fn canvas_texture(&self) -> Option<&Texture> {
24 None
25 }
26
27 /// Source controls that own pointer gesture starts over the canvas. Motion
28 /// and release from an existing canvas drag still reach Navigation.
29 fn canvas_controls_rect(&self, _width: u32, _height: u32, _scale: f32) -> Option<PixelRect> {
30 None
31 }
32
33 /// Render domain-specific UI overlays into `ui`. Called every frame.
34 fn render(&mut self, ui: &mut Ui<'_>, width: u32, height: u32) -> Result<()>;
35
36 /// Raw platform event (only called when `receives_events` is true).
37 fn on_event(&mut self, _event: &InputEvent) -> Result<()> {
38 Ok(())
39 }
40
41 /// Called once when the Viewer is closing.
42 fn close(&mut self) -> Result<()>;
43}