@@ -56,7 +56,7 @@ path = "path/to/slint-node-editor"
5656
5757``` slint
5858// In your main .slint file
59- import { NodeEditor, BaseNode, Pin, Link, LinkData } from "@slint-node-editor/node-editor.slint";
59+ import { NodeEditor, BaseNode, Pin, Link, LinkData, PinTypes } from "@slint-node-editor/node-editor.slint";
6060```
6161
6262### 3. Configure build.rs
@@ -78,10 +78,14 @@ fn main() {
7878
7979``` slint
8080component Node inherits BaseNode {
81- Text { text: "My Node"; }
81+ Text { text: "My Node"; color: white; }
8282 Pin {
8383 pin-type: PinTypes.input;
84- node-id: root.id;
84+ node-id: root.node-id;
85+ // Pass required context for drag handling
86+ zoom: root.zoom;
87+ node-screen-x: root.screen-x;
88+ node-screen-y: root.screen-y;
8589 }
8690}
8791```
@@ -101,10 +105,14 @@ export component MainWindow inherits Window {
101105
102106 // Provide your node data as @children
103107 for node in nodes: Node {
104- id: node.id;
105- world-x: node.x;
106- world-y: node.y;
107- // ... other bindings
108+ node-id: node.id;
109+ world-x: node.x * 1px; // Convert float to length
110+ world-y: node.y * 1px;
111+
112+ // Pass viewport state for local coordinate calculation
113+ zoom: editor.zoom;
114+ pan-x: editor.pan-x;
115+ pan-y: editor.pan-y;
108116 }
109117
110118 // Implement callbacks (see Callbacks section below)
@@ -159,55 +167,56 @@ The library handles all transformations transparently.
159167
160168** Properties:**
161169``` slint
162- in-out property <float > pan-x; // Pan offset (x)
163- in-out property <float > pan-y; // Pan offset (y)
170+ in-out property <length > pan-x; // Pan offset (x)
171+ in-out property <length > pan-y; // Pan offset (y)
164172in-out property <float> zoom; // Zoom factor (1.0 = 100%)
165- in-out property <float> min-zoom: 0.1; // Minimum zoom level
166- in-out property <float> max-zoom: 5 .0; // Maximum zoom level
173+ in property <float> min-zoom: 0.1; // Minimum zoom level
174+ in property <float> max-zoom: 3 .0; // Maximum zoom level
167175
168176in property <length> grid-spacing: 24px; // Grid cell size
169177in property <bool> grid-snapping: true; // Enable snap-to-grid
170- in property <color> grid-color: #e0e0e0; // Grid line color
171- in property <color > background-color: #f5f5f5 ; // Background color
178+ in property <color> grid-color: #404040; // Grid line color
179+ in property <brush > background-color: #1a1a1a ; // Background color
172180
173- in property <float> link-hover-distance: 10.0; // Click tolerance for links
174- in property <int> link-hit-samples: 20; // Bezier samples for hit-testing
175- in property <float> bezier-min-offset: 50.0; // Min horizontal offset for curves
181+ in property <length> link-hover-distance: 8px; // Click tolerance for links
182+ in property <length> pin-hit-radius: 10px; // Hit radius for pins
183+ in property <int> link-hit-samples: 20; // Bezier samples for hit-testing
184+ in property <float> bezier-min-offset: 50.0; // Min horizontal offset for curves
176185
177186// Minimap
178187in property <bool> minimap-enabled: false;
179- in property <MinimapPosition> minimap-position: top -right;
188+ in property <MinimapPosition> minimap-position: bottom -right;
180189
181190// Data bindings
182191in property <[LinkData]> links; // Links to render
183192in-out property <[int]> selected-node-ids; // Selected nodes
184193in-out property <[int]> selected-link-ids; // Selected links
185- in property <[MinimapNode]> minimap-nodes; // Minimap data
186- in property <float > graph-min-x; // Graph bounds
187- in property <float > graph-max-x;
188- in property <float > graph-min-y;
189- in property <float > graph-max-y;
194+ in property <[MinimapNode]> minimap-nodes: []; // Minimap data
195+ in-out property <length > graph-min-x; // Graph bounds
196+ in-out property <length > graph-max-x;
197+ in-out property <length > graph-min-y;
198+ in-out property <length > graph-max-y;
190199
191200// State outputs (read-only)
192201out property <bool> is-selecting; // User is dragging selection box
193- out property <float > selection-x; // Selection box position
194- out property <float > selection-y;
195- out property <float > selection-width; // Selection box size
196- out property <float > selection-height;
202+ out property <length > selection-x; // Selection box position
203+ out property <length > selection-y;
204+ out property <length > selection-width; // Selection box size
205+ out property <length > selection-height;
197206
198207out property <bool> is-creating-link; // User is dragging to create link
199- out property <float > link-start-x; // Link preview start
200- out property <float > link-start-y;
201- out property <float > link-end-x; // Link preview end
202- out property <float > link-end-y;
208+ out property <length > link-start-x; // Link preview start
209+ out property <length > link-start-y;
210+ out property <length > link-end-x; // Link preview end
211+ out property <length > link-end-y;
203212out property <int> link-start-pin-id; // Which pin started the link
204213
205214out property <bool> is-dragging; // User is dragging nodes
206- out property <float > drag-offset-x; // Drag delta
207- out property <float > drag-offset-y;
215+ out property <length > drag-offset-x; // Drag delta
216+ out property <length > drag-offset-y;
208217
209- out property <int > context-menu-x; // Right-click position
210- out property <int > context-menu-y;
218+ out property <length > context-menu-x; // Right-click position
219+ out property <length > context-menu-y;
211220
212221out property <int> hovered-link-id; // Link under mouse
213222out property <int> selection-version; // Version counter for cache invalidation
@@ -219,21 +228,21 @@ All these callbacks delegate expensive operations to your Rust code:
219228
220229``` slint
221230/// Compute which pin is at screen position (x, y)
222- callback compute-pin-at(x: float , y: float ) -> int;
231+ callback compute-pin-at(x: length , y: length ) -> int;
223232
224233/// Compute which link is at screen position (x, y)
225- callback compute-link-at(x: float , y: float ) -> int;
234+ callback compute-link-at(x: length , y: length ) -> int;
226235
227236/// Find all nodes in a selection box (world coordinates)
228- callback compute-box-selection(x: float , y: float , w: float , h: float ) -> [int];
237+ callback compute-box-selection(x: length , y: length , w: length , h: length ) -> [int];
229238
230239/// Find all links in a selection box (world coordinates)
231- callback compute-link-box-selection(x: float , y: float , w: float , h: float ) -> [int];
240+ callback compute-link-box-selection(x: length , y: length , w: length , h: length ) -> [int];
232241
233242/// Generate SVG path for link preview (during drag-to-link)
234243callback compute-link-preview-path(
235- start-x: float , start-y: float ,
236- end-x: float , end-y: float
244+ start-x: length , start-y: length ,
245+ end-x: length , end-y: length
237246) -> string;
238247
239248/// Compute SVG path for a link between two pins
@@ -292,21 +301,21 @@ callback delete-selected();
292301callback add-node-requested();
293302
294303/// User right-clicked (context menu)
295- callback context-menu-requested(x: float, y: float );
304+ callback context-menu-requested();
296305
297306/// User finished dragging nodes
298307callback node-drag-ended(delta-x: float, delta-y: float);
299308
300309/// Node geometry changed (position or size)
301- callback node-rect-changed(id: int, x: float , y: float , w: float , h: float );
310+ callback node-rect-changed(id: int, x: length , y: length , w: length , h: length );
302311
303312/// Pin geometry changed (position relative to node)
304313callback pin-position-changed(
305314 pin-id: int,
306315 node-id: int,
307316 pin-type: int,
308- rel-x: float ,
309- rel-y: float
317+ rel-x: length ,
318+ rel-y: length
310319);
311320```
312321
@@ -316,12 +325,13 @@ Base component for creating custom nodes. Provides drag handling and selection.
316325
317326** Properties:**
318327``` slint
319- in property <int> id; // Unique node ID
320- in-out property <float> world-x; // X position in graph space
321- in-out property <float> world-y; // Y position in graph space
322- in property <float> width; // Node width
323- in property <float> height; // Node height
328+ in property <int> node-id; // Unique node ID
329+ in property <length> world-x; // X position in graph space
330+ in property <length> world-y; // Y position in graph space
324331in property <bool> selected: false; // Selection state
332+ in property <float> zoom; // Required for view calculation
333+ in property <length> pan-x; // Required for view calculation
334+ in property <length> pan-y; // Required for view calculation
325335```
326336
327337### Pin
@@ -330,12 +340,14 @@ Represents a connection point on a node.
330340
331341** Properties:**
332342``` slint
333- in property <int> id; // Pin ID (encoded by application)
334- in property <int> node-id; // Parent node ID
335- in property <int> pin-type; // PinTypes.input or .output (or custom)
336- in property <color> color: #999;
337- in property <float> rel-x; // Relative X (from node top-left)
338- in property <float> rel-y; // Relative Y (from node top-left)
343+ in property <int> pin-id; // Pin ID (encoded by application)
344+ in property <int> node-id; // Parent node ID
345+ in property <int> pin-type; // PinTypes.input or .output (or custom)
346+ in property <color> base-color: #888;
347+ in property <color> hover-color: #aaa;
348+ in property <float> zoom; // Required for scaling
349+ in property <length> node-screen-x; // Required for drag handling
350+ in property <length> node-screen-y; // Required for drag handling
339351```
340352
341353### Link
@@ -345,7 +357,8 @@ Renders a Bezier curve between two pins. Used internally by `NodeEditor` but can
345357** Properties:**
346358``` slint
347359in property <string> path-commands; // SVG path (e.g., "M 0 0 C 50 50 100 100")
348- in property <color> color: #666;
360+ in property <color> link-color: #888;
361+ in property <length> line-width: 2px;
349362in property <bool> selected: false;
350363in property <bool> hovered: false;
351364```
0 commit comments