Validation
One IsValidConnection predicate on the canvas decides which connections are allowed, and it is asked while you drag: every handle turns green or red, and a drop on a red one connects nothing. Use it for the rules of your own application - which node may feed which.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Drag from A's handle on the right: while you drag, the handle of every node that would accept the connection turns green and the others red.
- Release on the green handle to connect, or on the red one to see that nothing happens; the line beside the toolbar says how the attempt ended.
- Drag again from A to a node it is already connected to: that handle is red now too, because the canvas refuses duplicate edges before your rule is even asked.
- Drag the other way, from B's or C's handle back to A: the same rule decides, because the connection it is shown always runs from source to target.
- Change Accept connections into and drag again: the rule is asked afresh on every move, so the colours follow at once. Remove edges starts over.
How it works
IsValidConnectionon the canvas is aFunc<BlowConnection, bool>. It receives the connection completing would make -Source,Target,SourceHandle,TargetHandle, normalised soSourceis the source end - and false refuses it.- It runs for every handle on every frame of the drag, so keep it cheap. It is only asked about connections the built-in rules (handle types, duplicates, self-connections) already allow.
- While dragging, the canvas gives each handle
bit-blow-handle-valid(green, with a ring) orbit-blow-handle-invalid(red, dimmed); the handle the drag came from getsbit-blow-handle-connectingfrom. - The pale green and red at rest are this page's own hint, set through the handle's
--bit-blow-handle-bgcustom property in itsClass, so the live colours still win while a connection is dragged. OnConnectreports the connection that was made.OnConnectEndreports every attempt: whenIsValidis false,Rejectionsays why a handle refused -RejectedByRulefor this predicate - andIsDroppedtells a drop on empty space from a click or Escape.