Skip to main content

NodeEditorController

Struct NodeEditorController 

Source
pub struct NodeEditorController { /* private fields */ }
Expand description

Controller that manages node editor state and provides callback implementations.

This provides a high-level API that handles:

  • Geometry caching (node rects, pin positions) in world space
  • Link path computation (world→screen conversion done internally)
  • Hit testing facades (screen-space input, world-space internals)
  • Viewport/zoom/pan tracking
  • Drag tracking

The cache stores node rects in world coordinates, which are invariant to zoom/pan changes. This eliminates the O(N) viewport resync loop that was previously needed when zoom or pan changed.

Clone this controller to share it across callbacks.

Implementations§

Source§

impl NodeEditorController

Source

pub fn new() -> Self

Create a new controller with default settings.

Source

pub fn set_bezier_offset(&self, offset: f32)

Set the bezier curve offset for link paths (default: 50.0).

Source

pub fn bezier_offset(&self) -> f32

Get the bezier curve offset used for rendered link paths.

Source

pub fn set_grid_spacing(&self, spacing: f32)

Set the grid spacing (default: 24.0).

Source

pub fn grid_spacing(&self) -> f32

Get the grid spacing used by grid generation.

Source

pub fn zoom(&self) -> f32

Get the current zoom level.

Source

pub fn screen_distance_to_world(&self, screen_distance: f32) -> f32

Convert a screen-space distance in pixels to world-space units.

Source

pub fn cache(&self) -> Rc<RefCell<GeometryCache>>

Get access to the geometry cache.

Source

pub fn dragged_node_id(&self) -> i32

Get the ID of the node currently being dragged (0 if none).

Source

pub fn dragged_group_id(&self) -> i32

Get the ID of the group whose sheet is being dragged (0 if none).

Returns a callback for compute-link-path.

Computes bezier paths for use inside a scaled container at origin. Positions are calculated so that after transform-scale, links appear at correct screen position.

make_path receives box-relative commands and the box, and builds the LinkPath the callback expects — see CubicBezier::to_link_path for why the type is not named here. A link whose pins are not in the cache yet yields T::default(), an empty path at the origin.

Source

pub fn node_drag_started_callback(&self) -> impl Fn(i32)

Returns a callback for node-drag-started.

Source

pub fn handle_node_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)

Update cached node rectangle (world coordinates).

Source

pub fn handle_pin_position( &self, pid: i32, nid: i32, ptype: i32, x: f32, y: f32, )

Handle a world-space pin geometry report by updating the cache.

The Slint Pin component reports rel_x/rel_y as world-space offsets relative to the node origin. The Pin component divides by zoom internally (center-x: (self.x + self.width / 2) / zoom), so the values received here are already zoom-invariant.

Source

pub fn handle_pin_position_with_hit_testable( &self, pid: i32, nid: i32, ptype: i32, x: f32, y: f32, hit_testable: bool, )

Update cached pin geometry and its pin-picking eligibility.

Source

pub fn seed_node_world_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)

Seed a node’s world-space rect directly, bypassing screen→world conversion.

Use this to pre-populate the geometry cache for nodes that haven’t been rendered by Slint yet (e.g. off-screen nodes whose link endpoints are visible). The coordinates must be in world space. Direct seeding bypasses the component geometry-reporting lifecycle; after seeding a batch, call NodeEditor.refresh-links() once to invalidate existing route bindings.

Source

pub fn handle_node_drag_started(&self, node_id: i32)

Handle node-drag-started: track the dragged node.

Source

pub fn handle_group_drag_started(&self, group_id: i32)

Handle start-group-drag: track the dragged sheet.

Source

pub fn handle_node_drag_finished(&self)

Clear controller state after a node or group drag ends or is cancelled.

Source

pub fn handle_group_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)

Update a group sheet’s displayed rectangle (world coordinates).

Source

pub fn remove_group(&self, group_id: i32) -> bool

Retire a group sheet’s rectangle and any drag of it.

Source

pub fn set_node_hidden(&self, node_id: i32, hidden: bool)

Record that a node is hidden (by a collapsed group) or visible again.

Source

pub fn set_zoom(&self, zoom: f32)

👎Deprecated since 0.2.0:

Use set_viewport() which also updates pan state

Set the zoom level (called from update-viewport).

Source

pub fn set_viewport(&self, zoom: f32, pan_x: f32, pan_y: f32)

Set viewport state: zoom, pan_x, pan_y. Invalid updates (nonfinite values or nonpositive zoom) are ignored atomically.

Since the cache stores world-space coordinates, changing zoom/pan requires no per-node updates.

Register a link for hit testing. Idempotent: re-registering the same ID updates the pin pair.

Unregister a link by ID.

Clear all registered links.

Source

pub fn remove_pin(&self, pin_id: i32) -> bool

Remove a pin and any registered hit-test links incident on it.

Source

pub fn remove_node(&self, node_id: i32) -> Vec<i32>

Remove a node, its pins, and registered hit-test links using those pins.

Source

pub fn reset_graph(&self)

Reset geometry and controller-owned topology for a graph switch.

Source

pub fn clear_geometry(&self)

Clear only the geometry cache (node rects and pin positions).

Use Self::reset_graph when switching graphs so registered hit-test links and drag state are retired as well.

Compute link path for given pins (screen-space output from world-space cache).

Source

pub fn generate_grid( &self, width: f32, height: f32, pan_x: f32, pan_y: f32, ) -> SharedString

Generate grid commands for current viewport.

Source

pub fn generate_current_grid(&self, width: f32, height: f32) -> SharedString

Generate grid commands from the controller’s current viewport and spacing.

Source

pub fn generate_initial_grid(&self, width: f32, height: f32) -> SharedString

Generate initial grid commands (zoom=1, pan=0).

Find the link closest to the given world-space position.

Returns the link ID, or -1 if no link is within world_hover_distance. The route is the same zoom-independent world curve produced by the standard renderer callback.

Find the link closest to the given screen-space position.

Returns the link ID, or -1 if no link is within the screen-pixel screen_hover_distance. Converts the point and tolerance to world space once, then tests the same world curve used for rendering.

Source

pub fn find_pin_at_screen( &self, mouse_x: f32, mouse_y: f32, hit_radius: f32, ) -> i32

Find the pin closest to the given screen-space position.

Returns the nearest hit-testable pin ID, or 0 if no pin is within hit_radius. Exact distance ties choose the lowest pin ID.

Source

pub fn nodes_in_selection_box_screen( &self, sx: f32, sy: f32, sw: f32, sh: f32, ) -> Vec<i32>

Find all nodes whose world-space rect intersects the given screen-space selection box.

Converts the selection box from screen→world and performs AABB intersection.

Find all links that have at least one endpoint inside the given world-space selection box.

Find all links that have at least one endpoint inside the given screen-space selection box.

Converts the box from screen→world and delegates to links_in_selection_box_world.

Trait Implementations§

Source§

impl Clone for NodeEditorController

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 Default for NodeEditorController

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<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<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<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> 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.