Skip to main content

GraphLogic

Struct GraphLogic 

Source
pub struct GraphLogic;
Expand description

Helper functions for graph operations

Implementations§

Source§

impl GraphLogic

Find all links connected to a specific node

§Arguments
  • node_id - The ID of the node being deleted/queried
  • links - Iterator over the links
  • cache - Geometry cache to look up pin ownership

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.

Source

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.

Check if a link with the given direction already exists

Prevents duplicate connections between the same pins.

§Arguments
  • start_pin - Start pin ID
  • end_pin - End pin ID
  • links - Iterator over existing links
Source

pub fn find_node_by_id<T, F>( model: &impl Model<Data = T>, id: i32, predicate: F, ) -> Option<(usize, T)>
where T: Clone + 'static, F: Fn(&T) -> i32,

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 nodes
  • id - The ID to search for
  • predicate - 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§

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