egui_graph
A general-purpose node graph widget for egui.
Build interactive node-based editors with nodes connected by edges for visual programming interfaces, shader editors, DSP graphs, or any graph-based UI.
Note: This library is the basis for nannou-org/gantz. For a more sophisticated example of what can be built with egui_graph, check out gantz.
Key Design Philosophy
One of the core design decisions of egui_graph is to avoid requiring that
users model their graph with any particular data structure. The library provides
immediate-mode widgets for rendering and interacting with graphs, but leaves
the underlying data model up to you. Store your graph however makes sense for
your application - whether that's an adjacency list, entity-component system,
or any other representation.
Features
- Interactive Nodes: Drag, select, and delete nodes with intuitive controls
- Edge Creation: Connect nodes via input/output sockets with bezier curve edges
- Multi-Selection: Rectangle selection and Ctrl+click for selecting multiple nodes
- Automatic Layout: Optional graph layout using the
layout-rscrate - Customizable: Configure node flow direction, socket/frame appearance, and more
- Zoom & Pan: Navigate large graphs with mouse controls
- Model-Agnostic: No prescribed graph data structure - use whatever fits your needs
Quick Start
use ;
// Create a view to store node and "camera" positions.
let mut view = default;
// Show the graph widget
new
.show;
Visit the demo.rs example for a more thorough, up-to-date example.
Core Components
Graph Widget
The main widget that contains all nodes and edges:
new
.background // Enable background
.dot_grid // Show dot grid
.zoom_range // Set zoom limits
.center_view // Center the camera
.show
Nodes
Nodes are containers with input/output sockets:
new
.inputs // Number of input sockets
.outputs // Number of output sockets
.flow // Socket arrangement
.socket_color
.socket_radius
.show
Edges
Connect nodes with bezier curve edges:
new
.distance_per_point // Curve sampling distance
.show
Automatic Layout
With the layout feature enabled:
use layout;
let positions = layout;
view.layout = positions;
Controls
Mouse Controls
- Left Click: Select node/edge
- Ctrl + Left Click: Toggle selection
- Shift + Left Click: Clear selection
- Left Drag on Background: Rectangle selection
- Left Drag on Node: Move selected nodes
- Middle Mouse Drag: Pan view
- Scroll Wheel: Zoom in/out
Keyboard Controls
- Delete/Backspace: Remove selected nodes/edges
Socket Interaction
- Click Output Socket: Start edge creation
- Drag to Input Socket: Preview connection
- Release on Input: Create edge
- ESC: Cancel edge creation
Examples
Run the included demo:
The demo showcases:
- Multiple node types (labels, buttons, sliders)
- Dynamic node creation and deletion
- Edge creation between nodes
- Automatic layout
- Configuration options
Architecture
The library follows egui's immediate-mode paradigm while maintaining necessary state for graph interactions. Internal state includes:
- Node sizes
- Selection state for nodes and edges
- Active edge creation
- Socket positions for edge rendering
State is stored in egui's data store and accessed through the widget APIs.