pub struct ViewportState {
pub zoom: f32,
pub pan: Vec2,
pub mode: ViewportMode,
pub image_size: Vec2,
pub viewport_size: Vec2,
pub scrubber: ViewportScrubber,
pub rmb_tool_drag_active: bool,
pub last_rendered_epoch: u64,
pub last_rendered_frame: Option<i32>,
}Expand description
Viewport state for pan/zoom
Fields§
§zoom: f32§pan: Vec2§mode: ViewportMode§image_size: Vec2§viewport_size: Vec2§scrubber: ViewportScrubber§rmb_tool_drag_active: boolTrue while RMB tool drag is active (latched on press inside viewport). Used by viewport UI to implement “no-aim” transform drags without relying on hover_pos, which may be None during drags depending on platform/backend.
last_rendered_epoch: u64Last rendered cache epoch (0 = needs refresh)
last_rendered_frame: Option<i32>Last rendered frame number (for detecting frame changes)
Implementations§
Source§impl ViewportState
impl ViewportState
pub fn new() -> Self
Sourcepub fn request_refresh(&mut self)
pub fn request_refresh(&mut self)
Request viewport to refresh current frame (resets tracking to force re-render)
Sourcepub fn draw(&self, ui: &Ui, panel_rect: Rect)
pub fn draw(&self, ui: &Ui, panel_rect: Rect)
Draw all viewport overlays (scrubber, guides, safe zones, etc.)
Sourcepub fn set_viewport_size(&mut self, size: Vec2)
pub fn set_viewport_size(&mut self, size: Vec2)
Update viewport size (called when window resizes)
Sourcepub fn set_image_size(&mut self, size: Vec2)
pub fn set_image_size(&mut self, size: Vec2)
Update image size (called when new image loads)
Sourcepub fn set_mode_fit(&mut self)
pub fn set_mode_fit(&mut self)
Set AutoFit mode and apply fit
Sourcepub fn set_mode_100(&mut self)
pub fn set_mode_100(&mut self)
Set Auto100 mode and apply 100% zoom
Sourcepub fn handle_zoom(&mut self, zoom_delta: f32, cursor_pos: Vec2)
pub fn handle_zoom(&mut self, zoom_delta: f32, cursor_pos: Vec2)
Handle zoom with center-on-cursor (switches to Manual mode)
Sourcepub fn handle_pan(&mut self, delta: Vec2)
pub fn handle_pan(&mut self, delta: Vec2)
Handle pan (switches to Manual mode)
Sourcepub fn get_image_screen_bounds(&self) -> Rect
pub fn get_image_screen_bounds(&self) -> Rect
Get image bounds in screen space
Sourcepub fn is_point_over_image(&self, screen_pos: Vec2) -> bool
pub fn is_point_over_image(&self, screen_pos: Vec2) -> bool
Check if screen position is over the image
Sourcepub fn image_to_screen(&self, image_pos: Vec2) -> Vec2
pub fn image_to_screen(&self, image_pos: Vec2) -> Vec2
Convert image space coordinates (0..image_size) to screen space. Uses frame space (centered, pixel coords) as intermediate — matches space.rs.
Sourcepub fn screen_to_image(&self, screen_pos: Vec2) -> Option<Vec2>
pub fn screen_to_image(&self, screen_pos: Vec2) -> Option<Vec2>
Convert screen space coordinates to image space (0..image_size). Returns None if position is outside the image bounds.
Sourcepub fn handle_scrubbing(
&mut self,
response: &Response,
panel_rect: Rect,
double_clicked: bool,
play_start: i32,
play_end: i32,
) -> Option<i32>
pub fn handle_scrubbing( &mut self, response: &Response, panel_rect: Rect, double_clicked: bool, play_start: i32, play_end: i32, ) -> Option<i32>
High-level scrubbing handler. Returns Some(frame_idx) when scrubbing requests a new frame, or None if nothing changed. Maps mouse X from image bounds directly to [play_start, play_end] frame range.
§Coordinate System
panel_rectis in screen coordinates (absolute)response.interact_pointer_pos()returns screen coordinatesget_image_screen_bounds()returns local coordinates (relative to viewport panel)
We convert mouse_pos to local coords by subtracting panel_rect.min.
Sourcepub fn render_state(&self) -> ViewportRenderState
pub fn render_state(&self) -> ViewportRenderState
Snapshot render-only matrices for GL callbacks.
Sourcepub fn get_model_matrix(&self) -> [[f32; 4]; 4]
pub fn get_model_matrix(&self) -> [[f32; 4]; 4]
Get model matrix for shader (scales normalized quad to image pixel size).
Sourcepub fn get_view_matrix(&self) -> [[f32; 4]; 4]
pub fn get_view_matrix(&self) -> [[f32; 4]; 4]
Get view matrix for shader (zoom + pan only, matches gizmo).
Sourcepub fn get_projection_matrix(&self) -> [[f32; 4]; 4]
pub fn get_projection_matrix(&self) -> [[f32; 4]; 4]
Get orthographic projection matrix for shader
Trait Implementations§
Source§impl Clone for ViewportState
impl Clone for ViewportState
Source§fn clone(&self) -> ViewportState
fn clone(&self) -> ViewportState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for ViewportState
impl Default for ViewportState
Source§impl<'de> Deserialize<'de> for ViewportState
impl<'de> Deserialize<'de> for ViewportState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ViewportState
impl RefUnwindSafe for ViewportState
impl Send for ViewportState
impl Sync for ViewportState
impl Unpin for ViewportState
impl UnwindSafe for ViewportState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().