Skip to main content

LinkManager

Struct LinkManager 

Source
pub struct LinkManager<L, N = SimpleNodeGeometry> { /* private fields */ }
Expand description

Manages links and their visual paths for the node editor.

LinkManager maintains a collection of links and automatically computes their bezier path representations for rendering.

§Auto-Sync Mode

Use bind_model to enable automatic synchronization to a Slint VecModel. After binding, every call to update_paths automatically updates the Slint model.

This fragment assumes the generated LinkRow and window types from the host’s Slint UI; the complete binding is application-specific.

let mut links = LinkManager::new(cache);
links.add(SimpleLink::new(1, start_pin, end_pin, color));

// Bind once - auto-syncs on every update_paths call
let model = Rc::new(VecModel::<LinkRow>::default());
links.bind_model(model.clone(), |id, path, color, line_width, status| LinkRow { id, path_commands: path, color, line_width, status });
window.set_link_paths(ModelRc::from(model));

// Now just call update_paths - model syncs automatically
links.update_paths(zoom);

§Type Parameters

  • L: The link data type, must implement LinkModel
  • N: The node geometry type used by the cache (default: SimpleNodeGeometry)

Implementations§

Source§

impl<L, N> LinkManager<L, N>
where L: LinkModel, N: NodeGeometry + Copy,

Source

pub fn new(cache: Rc<RefCell<GeometryCache<N>>>) -> Self

Create a new LinkManager with the given geometry cache.

§Arguments
  • cache - Reference to the geometry cache for pin position lookups
Source

pub fn bind_model<P, F>(&mut self, model: Rc<VecModel<P>>, constructor: F)
where P: Clone + 'static, F: Fn(i32, SharedString, Color, f32, i32) -> P + 'static,

Bind to a Slint model for automatic synchronization.

After binding, every call to Self::update_paths automatically updates the Slint model.

§Arguments
  • model - The VecModel to sync to
  • constructor - Function to create path items from (id, path_commands, color, line_width, status)
Source

pub fn add(&mut self, link: L)

Add a link to the manager.

The link’s visual path will be computed on the next call to Self::update_paths.

Source

pub fn remove(&mut self, id: i32) -> bool

Remove a link by ID.

Returns true if a link was removed.

Source

pub fn clear(&mut self)

Remove all links.

Source

pub fn len(&self) -> usize

Get the number of links.

Source

pub fn is_empty(&self) -> bool

Check if there are no links.

Get a reference to the links.

Get a mutable reference to the links.

Source

pub fn set_bezier_offset(&mut self, offset: f32)

Set the bezier curve offset (default: 50.0).

This controls how curved the link paths are.

Source

pub fn update_paths(&mut self, zoom: f32)

Update all link paths based on current pin positions.

Call this whenever:

  • Pin positions change (node moved)
  • Zoom level changes
  • Links are added/removed
§Arguments
  • zoom - Current viewport zoom level
Source

pub fn ids(&self) -> impl Iterator<Item = i32> + '_

Get an iterator over link IDs.

Source

pub fn find(&self, id: i32) -> Option<&L>

Find a link by ID.

Source

pub fn find_mut(&mut self, id: i32) -> Option<&mut L>

Find a link by ID (mutable).

Auto Trait Implementations§

§

impl<L, N = SimpleNodeGeometry> !RefUnwindSafe for LinkManager<L, N>

§

impl<L, N = SimpleNodeGeometry> !Send for LinkManager<L, N>

§

impl<L, N = SimpleNodeGeometry> !Sync for LinkManager<L, N>

§

impl<L, N = SimpleNodeGeometry> !UnwindSafe for LinkManager<L, N>

§

impl<L, N> Freeze for LinkManager<L, N>

§

impl<L, N> Unpin for LinkManager<L, N>

§

impl<L, N> UnsafeUnpin for LinkManager<L, N>

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.