pub struct GraphLogic;Expand description
Helper functions for graph operations
Implementations§
Source§impl GraphLogic
impl GraphLogic
Sourcepub fn find_links_connected_to_node<I, L, N>(
node_id: i32,
links: I,
cache: &GeometryCache<N>,
) -> Vec<i32>
pub fn find_links_connected_to_node<I, L, N>( node_id: i32, links: I, cache: &GeometryCache<N>, ) -> Vec<i32>
Find all links connected to a specific node
§Arguments
node_id- The ID of the node being deleted/queriedlinks- Iterator over the linkscache- Geometry cache to look up pin ownership
Sourcepub fn normalize_link_direction<N>(
pin_a: i32,
pin_b: i32,
cache: &GeometryCache<N>,
output_type: i32,
) -> Option<(i32, i32)>where
N: NodeGeometry + Copy,
pub fn normalize_link_direction<N>(
pin_a: i32,
pin_b: i32,
cache: &GeometryCache<N>,
output_type: i32,
) -> Option<(i32, i32)>where
N: NodeGeometry + Copy,
Normalize a link so (start, end) is always (Output, Input)
Returns (output_pin_id, input_pin_id), or None if either pin is missing. Callers must validate direction compatibility first.
Sourcepub fn commit_drag<T>(
model: &VecModel<T>,
dragged_id: i32,
delta_x: f32,
delta_y: f32,
)where
T: MovableNode,
pub fn commit_drag<T>(
model: &VecModel<T>,
dragged_id: i32,
delta_x: f32,
delta_y: f32,
)where
T: MovableNode,
Commit a finished drag of dragged_id into a node model.
A row moves if it is the dragged node itself, or if it is selected and
draggable. That one rule covers every case
without a second source of truth to consult:
- Dragging a node that is part of a multi-selection moves every draggable row of the selection, because the editor selects an unselected node before it starts dragging it. A selected row that is not draggable stays where it is.
- A host that wires no selection at all has no selected rows, so only the dragged node moves.
- Splitting nodes across several models composes: the dragged node lives in exactly one of them and always moves, and selected rows in every model move with it. Call this once per model.
Sourcepub fn duplicate_link_exists<I, L>(
start_pin: i32,
end_pin: i32,
links: I,
) -> boolwhere
I: IntoIterator<Item = L>,
L: LinkModel,
pub fn duplicate_link_exists<I, L>(
start_pin: i32,
end_pin: i32,
links: I,
) -> boolwhere
I: IntoIterator<Item = L>,
L: LinkModel,
Check if a link with the given direction already exists
Prevents duplicate connections between the same pins.
§Arguments
start_pin- Start pin IDend_pin- End pin IDlinks- Iterator over existing links
Sourcepub fn find_node_by_id<T, F>(
model: &impl Model<Data = T>,
id: i32,
predicate: F,
) -> Option<(usize, T)>
pub fn find_node_by_id<T, F>( model: &impl Model<Data = T>, id: i32, predicate: F, ) -> Option<(usize, T)>
Find a node by ID in a VecModel using a predicate function
Useful for searching multiple node models when IDs need to be matched against specific fields.
§Arguments
model- The VecModel containing nodesid- The ID to search forpredicate- Function that extracts ID from a node
§Example
use slint::VecModel;
use slint_node_editor::GraphLogic;
#[derive(Clone)]
struct Node { id: i32 }
let nodes_model = VecModel::from(vec![Node { id: 42 }]);
let (index, node) = GraphLogic::find_node_by_id(
&nodes_model,
42,
|n| n.id,
).unwrap();Auto Trait Implementations§
impl Freeze for GraphLogic
impl RefUnwindSafe for GraphLogic
impl Send for GraphLogic
impl Sync for GraphLogic
impl Unpin for GraphLogic
impl UnsafeUnpin for GraphLogic
impl UnwindSafe for GraphLogic
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
Mutably borrows from an owned value. Read more