pub struct NodeCanvas { /* private fields */ }Expand description
Node-graph canvas navigation, coordinate mapping, and hit tests.
Caller-owned; passed to crate::ui::Ui::node_canvas_grid to render the
background grid. Pan/zoom mutations cancel any running fit animation;
fit_to_view starts one that step_animation advances.
Donor: oa::NodeCanvas.
Implementations§
Source§impl NodeCanvas
impl NodeCanvas
pub const ZOOM_MIN: f32 = 0.05
pub const ZOOM_MAX: f32 = 8.0
pub fn new() -> Self
Sourcepub const fn state(&self) -> &NodeCanvasState
pub const fn state(&self) -> &NodeCanvasState
Access the current canvas state.
Sourcepub const fn is_animating(&self) -> bool
pub const fn is_animating(&self) -> bool
Return whether a fit animation is still running.
Sourcepub fn set_state(&mut self, state: NodeCanvasState) -> Result<()>
pub fn set_state(&mut self, state: NodeCanvasState) -> Result<()>
Replace the complete canvas state and cancel any animation.
§Errors
Returns an error for non-finite pan/view state, a zoom outside
Self::ZOOM_MIN..=Self::ZOOM_MAX, or a non-positive view size.
Sourcepub fn set_view_size(&mut self, w: f32, h: f32) -> Result<()>
pub fn set_view_size(&mut self, w: f32, h: f32) -> Result<()>
Set the canvas view size (called once when the viewport is known).
§Errors
Returns an error for non-finite or non-positive dimensions.
Sourcepub fn world_to_screen(&self, world: [f32; 2]) -> [f32; 2]
pub fn world_to_screen(&self, world: [f32; 2]) -> [f32; 2]
Convert a world-space position to screen-space pixels.
Sourcepub fn screen_to_world(&self, screen: [f32; 2]) -> [f32; 2]
pub fn screen_to_world(&self, screen: [f32; 2]) -> [f32; 2]
Convert screen-space pixels to world-space coordinates.
Sourcepub fn visible_world_rect(&self) -> WorldAabb
pub fn visible_world_rect(&self) -> WorldAabb
Return the world-space rectangle currently visible through the view.
Sourcepub fn hit_test(
&self,
screen: [f32; 2],
items: &[NodeCanvasHitItem],
) -> Result<Option<NodeCanvasHit>>
pub fn hit_test( &self, screen: [f32; 2], items: &[NodeCanvasHitItem], ) -> Result<Option<NodeCanvasHit>>
Find the topmost enabled item under a screen-space point.
Items are tested in order; on overlapping hits the item with the highest layer wins, with later items breaking ties.
§Errors
Returns an error for invalid canvas state, a non-finite screen point, zero item IDs, or invalid item bounds.
Sourcepub fn grid(
&self,
minimum_screen_spacing: f32,
base_world_step: f32,
major_every: u32,
super_major_every: u32,
) -> Result<NodeCanvasGrid>
pub fn grid( &self, minimum_screen_spacing: f32, base_world_step: f32, major_every: u32, super_major_every: u32, ) -> Result<NodeCanvasGrid>
Resolve the visible minor grid tier and its major cadences.
The donor preserves a Maya-style decimal hierarchy: zooming out
promotes the minor tier by whole decades; zooming in never invents a
sub-base grid. Donor call defaults are 8.0 minimum screen spacing,
10.0 base world step, 10 major, and 100 super-major.
§Errors
Returns an error for invalid canvas state, non-finite or out-of-range spacing, or undivisible major/super-major tiers.
Sourcepub fn pan(&mut self, delta_screen: [f32; 2]) -> Result<()>
pub fn pan(&mut self, delta_screen: [f32; 2]) -> Result<()>
Pan by a screen-space delta.
§Errors
Returns an error for invalid canvas state, a non-finite delta, or a
result outside the finite f32 range.
Sourcepub fn zoom_at(&mut self, factor: f32, focus_screen: [f32; 2]) -> Result<()>
pub fn zoom_at(&mut self, factor: f32, focus_screen: [f32; 2]) -> Result<()>
Zoom by factor, keeping the world point under focus_screen fixed.
§Errors
Returns an error for invalid canvas state, a non-positive or non-finite factor, a non-finite focus, or an out-of-range result.