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
impl NodeEditorController
Sourcepub fn set_bezier_offset(&self, offset: f32)
pub fn set_bezier_offset(&self, offset: f32)
Set the bezier curve offset for link paths (default: 50.0).
Sourcepub fn bezier_offset(&self) -> f32
pub fn bezier_offset(&self) -> f32
Get the bezier curve offset used for rendered link paths.
Sourcepub fn set_grid_spacing(&self, spacing: f32)
pub fn set_grid_spacing(&self, spacing: f32)
Set the grid spacing (default: 24.0).
Sourcepub fn grid_spacing(&self) -> f32
pub fn grid_spacing(&self) -> f32
Get the grid spacing used by grid generation.
Sourcepub fn screen_distance_to_world(&self, screen_distance: f32) -> f32
pub fn screen_distance_to_world(&self, screen_distance: f32) -> f32
Convert a screen-space distance in pixels to world-space units.
Sourcepub fn cache(&self) -> Rc<RefCell<GeometryCache>>
pub fn cache(&self) -> Rc<RefCell<GeometryCache>>
Get access to the geometry cache.
Sourcepub fn dragged_node_id(&self) -> i32
pub fn dragged_node_id(&self) -> i32
Get the ID of the node currently being dragged (0 if none).
Sourcepub fn dragged_group_id(&self) -> i32
pub fn dragged_group_id(&self) -> i32
Get the ID of the group whose sheet is being dragged (0 if none).
Sourcepub fn compute_link_path_callback<T: Default>(
&self,
make_path: impl Fn(String, f32, f32, f32, f32) -> T,
) -> impl Fn(i32, i32, i32) -> T
pub fn compute_link_path_callback<T: Default>( &self, make_path: impl Fn(String, f32, f32, f32, f32) -> T, ) -> impl Fn(i32, i32, i32) -> T
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.
Sourcepub fn node_drag_started_callback(&self) -> impl Fn(i32)
pub fn node_drag_started_callback(&self) -> impl Fn(i32)
Returns a callback for node-drag-started.
Sourcepub fn handle_node_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)
pub fn handle_node_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)
Update cached node rectangle (world coordinates).
Sourcepub fn handle_pin_position(
&self,
pid: i32,
nid: i32,
ptype: i32,
x: f32,
y: f32,
)
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.
Sourcepub fn handle_pin_position_with_hit_testable(
&self,
pid: i32,
nid: i32,
ptype: i32,
x: f32,
y: f32,
hit_testable: bool,
)
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.
Sourcepub fn seed_node_world_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)
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.
Sourcepub fn handle_node_drag_started(&self, node_id: i32)
pub fn handle_node_drag_started(&self, node_id: i32)
Handle node-drag-started: track the dragged node.
Sourcepub fn handle_group_drag_started(&self, group_id: i32)
pub fn handle_group_drag_started(&self, group_id: i32)
Handle start-group-drag: track the dragged sheet.
Sourcepub fn handle_node_drag_finished(&self)
pub fn handle_node_drag_finished(&self)
Clear controller state after a node or group drag ends or is cancelled.
Sourcepub fn handle_group_rect(&self, id: i32, x: f32, y: f32, w: f32, h: f32)
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).
Sourcepub fn remove_group(&self, group_id: i32) -> bool
pub fn remove_group(&self, group_id: i32) -> bool
Retire a group sheet’s rectangle and any drag of it.
Record that a node is hidden (by a collapsed group) or visible again.
Sourcepub fn set_zoom(&self, zoom: f32)
👎Deprecated since 0.2.0: Use set_viewport() which also updates pan state
pub fn set_zoom(&self, zoom: f32)
Use set_viewport() which also updates pan state
Set the zoom level (called from update-viewport).
Sourcepub fn set_viewport(&self, zoom: f32, pan_x: f32, pan_y: f32)
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.
Sourcepub fn register_link(&self, id: i32, start_pin: i32, end_pin: i32)
pub fn register_link(&self, id: i32, start_pin: i32, end_pin: i32)
Register a link for hit testing. Idempotent: re-registering the same ID updates the pin pair.
Sourcepub fn unregister_link(&self, id: i32)
pub fn unregister_link(&self, id: i32)
Unregister a link by ID.
Sourcepub fn clear_links(&self)
pub fn clear_links(&self)
Clear all registered links.
Sourcepub fn remove_pin(&self, pin_id: i32) -> bool
pub fn remove_pin(&self, pin_id: i32) -> bool
Remove a pin and any registered hit-test links incident on it.
Sourcepub fn remove_node(&self, node_id: i32) -> Vec<i32>
pub fn remove_node(&self, node_id: i32) -> Vec<i32>
Remove a node, its pins, and registered hit-test links using those pins.
Sourcepub fn reset_graph(&self)
pub fn reset_graph(&self)
Reset geometry and controller-owned topology for a graph switch.
Sourcepub fn clear_geometry(&self)
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.
Sourcepub fn compute_link_path(&self, start_pin: i32, end_pin: i32) -> SharedString
pub fn compute_link_path(&self, start_pin: i32, end_pin: i32) -> SharedString
Compute link path for given pins (screen-space output from world-space cache).
Sourcepub fn generate_grid(
&self,
width: f32,
height: f32,
pan_x: f32,
pan_y: f32,
) -> SharedString
pub fn generate_grid( &self, width: f32, height: f32, pan_x: f32, pan_y: f32, ) -> SharedString
Generate grid commands for current viewport.
Sourcepub fn generate_current_grid(&self, width: f32, height: f32) -> SharedString
pub fn generate_current_grid(&self, width: f32, height: f32) -> SharedString
Generate grid commands from the controller’s current viewport and spacing.
Sourcepub fn generate_initial_grid(&self, width: f32, height: f32) -> SharedString
pub fn generate_initial_grid(&self, width: f32, height: f32) -> SharedString
Generate initial grid commands (zoom=1, pan=0).
Sourcepub fn find_link_at_world(
&self,
world_x: f32,
world_y: f32,
world_hover_distance: f32,
bezier_min_offset: f32,
hit_samples: usize,
) -> i32
pub fn find_link_at_world( &self, world_x: f32, world_y: f32, world_hover_distance: f32, bezier_min_offset: f32, hit_samples: usize, ) -> i32
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.
Sourcepub fn find_link_at_screen(
&self,
mouse_x: f32,
mouse_y: f32,
screen_hover_distance: f32,
bezier_min_offset: f32,
hit_samples: usize,
) -> i32
pub fn find_link_at_screen( &self, mouse_x: f32, mouse_y: f32, screen_hover_distance: f32, bezier_min_offset: f32, hit_samples: usize, ) -> i32
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.
Sourcepub fn find_pin_at_screen(
&self,
mouse_x: f32,
mouse_y: f32,
hit_radius: f32,
) -> i32
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.
Sourcepub fn nodes_in_selection_box_screen(
&self,
sx: f32,
sy: f32,
sw: f32,
sh: f32,
) -> Vec<i32>
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.
Sourcepub fn links_in_selection_box_world(
&self,
world_x: f32,
world_y: f32,
world_w: f32,
world_h: f32,
) -> Vec<i32>
pub fn links_in_selection_box_world( &self, world_x: f32, world_y: f32, world_w: f32, world_h: f32, ) -> Vec<i32>
Find all links that have at least one endpoint inside the given world-space selection box.
Sourcepub fn links_in_selection_box_screen(
&self,
sx: f32,
sy: f32,
sw: f32,
sh: f32,
) -> Vec<i32>
pub fn links_in_selection_box_screen( &self, sx: f32, sy: f32, sw: f32, sh: f32, ) -> Vec<i32>
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.