Skip to main content

NodeCanvas

Struct NodeCanvas 

Source
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

Source

pub const ZOOM_MIN: f32 = 0.05

Source

pub const ZOOM_MAX: f32 = 8.0

Source

pub fn new() -> Self

Source

pub const fn state(&self) -> &NodeCanvasState

Access the current canvas state.

Source

pub const fn is_animating(&self) -> bool

Return whether a fit animation is still running.

Source

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.

Source

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.

Source

pub fn world_to_screen(&self, world: [f32; 2]) -> [f32; 2]

Convert a world-space position to screen-space pixels.

Source

pub fn screen_to_world(&self, screen: [f32; 2]) -> [f32; 2]

Convert screen-space pixels to world-space coordinates.

Source

pub fn visible_world_rect(&self) -> WorldAabb

Return the world-space rectangle currently visible through the view.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn fit_to_view( &mut self, bounds: &WorldAabb, padding_pixels: f32, ) -> Result<()>

Start a pan/zoom animation fitting bounds into the view.

§Errors

Returns an error for invalid canvas state, invalid bounds, or padding that leaves no usable view area.

Source

pub fn step_animation(&mut self, delta_ms: f32) -> Result<()>

Advance a running fit animation by delta_ms milliseconds.

A no-op when no animation is running. The donor eases with a smoothstep over a 200 ms duration.

§Errors

Returns an error for a non-finite or negative delta.

Trait Implementations§

Source§

impl Clone for NodeCanvas

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeCanvas

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NodeCanvas

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.