Tool Infrastructure & Gizmos
Relevant source files
The following files were used as context for generating this wiki page:
- editor/src/messages/tool/tool_message_handler.rs
- editor/src/messages/tool/common_functionality/gizmos/gizmo_manager.rs
- editor/src/messages/tool/common_functionality/snapping/snapping.rs
- website/content/volunteer/guide/codebase-overview/_index.md
- website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md
- website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
The Tool Infrastructure in Graphite provides the architectural foundation for interactive editing, bridging user input from the frontend to the backend's business logic. This system manages the state and behavior of various tools—such as the Pen, Path, and Select tools—while providing common utilities like snapping and visual gizmos to assist the artist.
Gizmos serve as the visual interface for manipulation, offering on-canvas handles and overlays that represent document data like anchor points or bounding boxes. These are managed by a centralized Gizmo Manager that coordinates their visibility and interaction state.
Sources: website/content/volunteer/guide/codebase-overview/_index.md, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Tool Message System Architecture
Graphite utilizes a message-based architecture where user interactions are translated into messages. The ToolMessageHandler acts as the primary dispatcher, routing input events to the currently active tool and managing transitions between different tool states.
Message Flow
When a user interacts with the canvas, the frontend sends a message that eventually reaches the ToolMessageHandler. This handler maintains the tool_state, including the active tool and its specific data.
The message system ensures that logic remains decoupled from the UI, allowing the editor to run as a pure state machine.
Sources: website/content/volunteer/guide/codebase-overview/_index.md, editor/src/messages/tool/tool_message_handler.rs
Gizmo Management
Gizmos are transient visual elements used to manipulate or highlight document content. The GizmoManager handles the creation, updating, and deletion of these elements, ensuring they reflect the current state of the selected layers or points.
Gizmo Types and Usage
Gizmos are used for various purposes across different tools:
- Selection Gizmos: Bounding boxes and pivot points for the Select tool.
- Path Gizmos: Anchor points and Bezier handles for the Pen and Path tools.
- Viewport Gizmos: Grid lines and artboard labels.
| Component | Description |
|---|---|
| GizmoManager | Tracks active gizmos and manages their lifecycle. |
| Overlay System | The underlying rendering layer where gizmos are drawn to avoid polluting document data. |
| State Tracking | Gizmos are updated based on messages like UpdateSubpathVisuals. |
Sources: editor/src/messages/tool/common_functionality/gizmos/gizmo_manager.rs, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Snapping Infrastructure
The snapping system provides precision by aligning tool interactions to significant points in the document. This system was overhauled in early 2024 to support both rectangular and isometric grids.
Snapping Logic and Types
Snapping is calculated dynamically based on the mouse position and the proximity to "snap targets." These targets include:
- Grid Snapping: Aligning to customizable rectangular or isometric grid lines.
- Geometry Snapping: Aligning to midpoints, endpoints, or intersections of existing paths.
- Document Snapping: Aligning to artboard edges or centers.
Users can customize snapping behavior through a popover menu that offers fine-grained control over which targets are active.
Sources: editor/src/messages/tool/common_functionality/snapping/snapping.rs, website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Common Tool Functionality
Many tools share underlying logic for viewport navigation and path manipulation. Recent updates have moved more of this interaction logic from the frontend to the backend to enable features like autopanning.
Key Interactive Features
- Autopanning: The viewport automatically pans when a tool's cursor extends past the edge during a drag operation.
- Point Insertion: The Path tool supports sliding to insert points on path segments.
- Undo/Redo Integration: Tools like the Pen support point-by-point undo without discarding the entire shape.
Sources: website/content/blog/2024-05-09-graphite-progress-report-q1-2024.md, website/content/blog/2024-07-31-graphite-progress-report-q2-2024.md
Conclusion
The tool infrastructure and gizmo systems in Graphite are designed to provide a responsive, professional editing experience. By centralizing gizmo management and snapping logic, the architecture allows for highly precise interactions while maintaining a clean separation between the interactive "overlay" state and the persistent document data. This infrastructure supports Graphite's mission to offer a modern, nondestructive graphics workflow that scales from simple vector shapes to complex procedural designs.