Skip to main content

Canvas

Function Canvas 

Source
pub fn Canvas(_: CanvasProps) -> Element
Expand description

The pannable/zoomable surface every flow is drawn on.

Owns the FlowCore context, the container geometry, and the pane gestures: pan (drag or scroll), zoom (scroll or pinch), pane clicks, and the in-flight connection state machine that crate::Handles feed. Draws nothing itself: Flow passes its node/edge layers through the world slot, and an application using Canvas directly renders its own content there (in flow coordinates) and overlays as children (in screen coordinates).

An application-level gesture that starts on content inside the canvas can take the pointer away from the pane with FlowCore::claim_pointer; the pane then neither pans nor reports a pane click for that press.

§Props

For details, see the props struct definition.

  • min_zoom : f64
  • max_zoom : f64
  • pan_on_drag : bool

    Pan the canvas by dragging empty space.

  • zoom_on_scroll : bool

    Zoom with the mouse wheel / trackpad.

  • pan_on_scroll : bool

    Scrolling pans instead of zooming (shift swaps the axis, ctrl/meta — a trackpad pinch included — zooms about the pointer). Takes precedence over zoom_on_scroll.

  • nodes_draggable : bool

    Master switch for node dragging (read by Flow’s node layer).

  • drag_threshold : f64

    How far (screen px) a press on a node must travel before it moves the node, so a sloppy click never nudges one.

  • connection_radius : f64

    Snap radius (screen px) for completing a connection near a handle.

  • fit_view_padding : f64
  • id : Option<String>

    id attribute for the root element, so applications can find, focus, measure, or capture pointers to the canvas by id.

  • aria_label : String

    Accessible name for the canvas.

  • class : Option<String>

    Extra classes for the root element.

  • on_pane_press : Option<Callback<Event<PointerData>>>

    A primary press reaching the pane, before the pane decides to pan: the hook for application-level pane gestures (marquee selection, pulling a connection from a node border…). A handler that starts one claims the pointer with FlowCore::claim_pointer; the pane then leaves this press alone.

  • edges : Option<Signal<Vec<Edge>>>

    The caller’s edges, when it has any (the Flow layers and the default connect behavior read and write these through the core).

  • geoms : Option<Memo<Vec<NodeGeom>>>

    Node geometry snapshot, when the caller renders nodes (Flow passes its memo; standalone canvases leave it empty).

  • deselect_nodes : Option<Callback<()>>

    Type-erased “deselect all nodes” for pane clicks and edge selection, provided by Flow which knows the node type.

  • on_connect : Option<EventHandler<Connection>>

    Called when the user completes a connection between two handles. When absent, the edge is added to edges automatically.

  • on_connect_start : Option<EventHandler<HandleKey>>

    A connection drag has left a handle (started, not completed).

  • on_connect_end : Option<EventHandler<ConnectEnd>>

    A connection drag ended — wherever it ended. connection is None when the release was over nothing, and the point says where: the hook for “drop on empty canvas to create the node there”.

  • is_valid_connection : Option<Callback<Connection,bool>>

    The application’s say over which connections may complete. A target that fails is never offered as a snap and never completes.

  • on_node_drag_start : Option<EventHandler<Vec<Id>>>

    A node drag actually began (the press travelled past drag_threshold), with the ids being dragged: the moment to snapshot for undo.

  • on_node_drag_stop : Option<EventHandler<Vec<Id>>>

    A node drag ended, with the ids that were dragged. Positions are already final in the node list: the moment to snap, settle, persist.

  • on_pane_click : Option<EventHandler<Point>>

    Click on empty canvas; the point is in flow coordinates. Fires only when the press neither travelled nor was claimed by content.

  • on_pane_double_click : Option<EventHandler<Point>>

    Double-click on the canvas; the point is in flow coordinates. The pane cannot tell content from paper here — an application that must can hit-test the client point itself before acting.

  • on_canvas_key_down : Option<Callback<Event<KeyboardData>>>

    Keyboard events reaching the canvas root, after the canvas’s own Escape handling. Flow wires Delete/Backspace through this.

  • on_drag_move : Option<Callback<Point>>

    Pointer moves while a node drag is in flight, in flow coordinates. Flow applies the drag to its typed node list through this.

  • world : Option<Element>

    Content drawn inside the viewport transform, in flow coordinates.

  • children : Element

    Overlays drawn over the canvas in screen coordinates ([Background], [Controls], [MiniMap], or your own — they can call [use_flow]).

    [Background]: crate::Background [Controls]: crate::Controls [MiniMap]: crate::MiniMap [use_flow]: crate::use_flow