Skip to main content

GeometryTracker

Struct GeometryTracker 

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

Convenience wrapper for GeometryCache that provides ready-to-use Slint callbacks.

This eliminates the boilerplate of creating a cache, wrapping it in Rc<RefCell<_>>, and manually wiring up the position tracking callbacks.

§Type Parameter

  • N: The node geometry type. Defaults to SimpleNodeGeometry which stores basic rectangle data (x, y, width, height). For custom node data, implement NodeGeometry and use GeometryTracker::<MyNodeGeometry>::new().

§Example

use slint_node_editor::GeometryTracker;

// Create tracker with default SimpleNodeGeometry
let tracker = GeometryTracker::new();

let report_node = tracker.node_rect_callback();
let report_pin = tracker.pin_position_callback();
report_node(1, 10.0, 20.0, 100.0, 60.0);
report_pin(3, 1, 2, 100.0, 30.0);

// Access the cache for hit testing, path computation, etc.
let cache = tracker.cache();
let pin_id = cache.borrow().find_pin_at(110.0, 50.0, 10.0);
assert_eq!(pin_id, 3);

Implementations§

Source§

impl<N> GeometryTracker<N>

Source

pub fn new() -> Self

Create a new geometry tracker with an empty cache.

Source

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

Create a tracker wrapping an existing cache.

Useful when you need to initialize the cache with data before connecting callbacks.

Source

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

Get a clone of the internal cache reference.

Use this to access the cache for hit testing, path computation, and other operations.

Source§

impl<N> GeometryTracker<N>
where N: NodeGeometry + Copy,

Source

pub fn pin_position_callback(&self) -> impl Fn(i32, i32, i32, f32, f32) + Clone

Get a callback for pin position updates.

The returned closure accepts world-space pin data:

use slint_node_editor::GeometryTracker;
let tracker: GeometryTracker = GeometryTracker::new();
let report = tracker.pin_position_callback();
report(3, 1, 2, 100.0, 30.0);

The callback signature matches Slint’s generated callback: (pin_id: i32, node_id: i32, pin_type: i32, rel_x: f32, rel_y: f32)

Source§

impl GeometryTracker<SimpleNodeGeometry>

Source

pub fn node_rect_callback(&self) -> impl Fn(i32, f32, f32, f32, f32) + Clone

Get a callback for node rectangle updates.

The returned closure accepts a world-space node rectangle:

use slint_node_editor::GeometryTracker;
let tracker = GeometryTracker::new();
let report = tracker.node_rect_callback();
report(1, 10.0, 20.0, 100.0, 60.0);

The callback signature matches Slint’s generated callback: (id: i32, x: f32, y: f32, width: f32, height: f32)

§Note

This method is only available for GeometryTracker<SimpleNodeGeometry>. For custom node types, use Self::node_rect_callback_with instead.

Source§

impl<N> GeometryTracker<N>
where N: NodeGeometry + Copy,

Source

pub fn node_rect_callback_with<F>( &self, convert: F, ) -> impl Fn(i32, f32, f32, f32, f32) + Clone
where F: Fn(i32, f32, f32, f32, f32) -> N + Clone + 'static,

Get a callback for node rectangle updates with a custom conversion function.

Use this when your cache uses a custom NodeGeometry type instead of SimpleNodeGeometry.

§Example
use slint_node_editor::{GeometryTracker, NodeGeometry};

#[derive(Clone, Copy)]
struct MyNodeGeometry {
    id: i32,
    bounds: (f32, f32, f32, f32),
    collapsed: bool,
}

impl NodeGeometry for MyNodeGeometry {
    fn id(&self) -> i32 { self.id }
    fn rect(&self) -> (f32, f32, f32, f32) { self.bounds }
}

let tracker = GeometryTracker::<MyNodeGeometry>::new();
let report = tracker.node_rect_callback_with(|id, x, y, w, h| {
    MyNodeGeometry {
        id,
        bounds: (x, y, w, h),
        collapsed: false,
    }
});
report(1, 10.0, 20.0, 100.0, 60.0);

Trait Implementations§

Source§

impl<N> Default for GeometryTracker<N>

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