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 toSimpleNodeGeometrywhich stores basic rectangle data (x, y, width, height). For custom node data, implementNodeGeometryand useGeometryTracker::<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>
impl<N> GeometryTracker<N>
Sourcepub fn with_cache(cache: Rc<RefCell<GeometryCache<N>>>) -> Self
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.
Sourcepub fn cache(&self) -> Rc<RefCell<GeometryCache<N>>>
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,
impl<N> GeometryTracker<N>where
N: NodeGeometry + Copy,
Sourcepub fn pin_position_callback(&self) -> impl Fn(i32, i32, i32, f32, f32) + Clone
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>
impl GeometryTracker<SimpleNodeGeometry>
Sourcepub fn node_rect_callback(&self) -> impl Fn(i32, f32, f32, f32, f32) + Clone
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,
impl<N> GeometryTracker<N>where
N: NodeGeometry + Copy,
Sourcepub fn node_rect_callback_with<F>(
&self,
convert: F,
) -> impl Fn(i32, f32, f32, f32, f32) + Clone
pub fn node_rect_callback_with<F>( &self, convert: F, ) -> impl Fn(i32, f32, f32, f32, f32) + Clone
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);