Drawing Tools
The DrawingTools trait manages the active drawing tool and undo/redo history on any chart view. Both ChartView and ChartView implement this trait, enabling tool and history management to be written once and used with either view.
Import
use navi_chart::{ChartView, ChartView, DrawingTools, DrawingToolId};Usage
use navi_chart::{DrawingTools, DrawingToolId};
fn activate_tool<C>(cv: &C, id: DrawingToolId)
where
C: DrawingTools,
{
cv.set_tool(id);
}
fn handle_keyboard_shortcut<C>(cv: &C, key: &str)
where
C: DrawingTools,
{
match key {
"z" => { if cv.can_undo() { cv.undo(); } }
"y" => { if cv.can_redo() { cv.redo(); } }
"Escape" => cv.cancel_drawing(),
_ => {}
}
}The tool is identified by the [DrawingToolId] enum, so unknown names are rejected at compile time and set_tool returns true for every valid variant.
Method Reference
| Method | Description |
|---|---|
undo() | Undo the last annotation creation, deletion, or modification. No-op if the history is empty. |
redo() | Redo the last undone action. No-op if there is nothing to redo. |
can_undo() | Return true if there is at least one action to undo. |
can_redo() | Return true if there is at least one action to redo. |
finalize_pending_drawing() | Force-complete an in-progress multi-point drawing (e.g. a polyline or Elliott wave) at the current number of points. Has no effect if no drawing is in progress. |
cancel_drawing() | Cancel the current in-progress drawing without creating an annotation. Resets the tool to pointer mode unless sticky mode is active. |
set_tool(id) | Activate the [DrawingToolId] variant. Pass DrawingToolId::Pointer to return to selection mode. Returns true after the switch is queued. |
active_tool() | Return the [DrawingToolId] of the currently active tool. |
set_sticky_tool(sticky) | Enable or disable sticky mode. When true, the tool stays active after each drawing is finalised — useful for placing multiple copies of the same shape without re-selecting the tool. |
is_sticky_tool() | Return true if sticky mode is enabled. |
Tool IDs
DrawingToolId enumerates every tool the chart view can host.
| Category | Variant | Description |
|---|---|---|
| Mode | Pointer | Default pan / zoom / select mode |
TextEditing | Inline text editor (entered automatically; rarely set by hand) | |
| Lines | Trendline | Trend line |
Ray | Half-line extending past p1 | |
ExtendedLine | Infinite line through two points | |
Hline | Horizontal line at a fixed price | |
Hray | Horizontal ray from p0 rightward | |
Vline | Vertical line at a fixed time | |
Crossline | Horizontal + vertical cross | |
InfoLine | Trend line with Δprice / % / angle info | |
TrendAngle | Trend line with angle arc | |
| Shapes | Rect | Axis-aligned rectangle |
Circle | Circle | |
Ellipse | Ellipse | |
Triangle | Three-point triangle | |
RotatedRect | Free-angle rectangle | |
Polyline | Multi-point polyline (double-click to finish) | |
| Arrows | Arrow | Line with arrowhead |
ArrowMarkUp | Upward arrow marker | |
ArrowMarkDown | Downward arrow marker | |
ArrowMarker | Free-rotating arrow marker | |
| Channels | ParallelChannel | Two parallel trend lines |
FlatTopBottom | Two horizontal lines | |
DisjointChannel | Two independent trend lines | |
RegressionTrend | Linear regression channel | |
| Text & Labels | Text | Editable text label |
Note | Text bubble | |
Callout | Speech callout | |
PriceNote | Text with price-axis label | |
PriceLabel | Alias for PriceNote accepted by the parser | |
Emoji | Emoji / glyph marker | |
| Fibonacci | FibRetracement | Fibonacci retracement levels |
FibExtension | Fibonacci extension levels | |
FibChannel | Fibonacci channel | |
FibTimezone | Fibonacci time zones | |
FibFan | Fibonacci fan rays | |
FibCircles | Fibonacci circles | |
FibArcs | Fib speed resistance arcs | |
FibTrendBasedExtension | Trend-based Fibonacci extension | |
FibWedge | Fibonacci wedge | |
FibSpiral | Fibonacci spiral | |
| Pitchfork | Pitchfork | Andrews' pitchfork |
SchiffPitchfork | Schiff pitchfork | |
ModifiedSchiffPitchfork | Modified Schiff pitchfork | |
InsidePitchfork | Inside pitchfork | |
| Gann | GannBox | Gann box |
GannSquare | Gann square | |
GannSquareFixed | Gann square (fixed aspect ratio) | |
GannFan | Gann fan | |
| Measurement | PriceRange | Price range ruler |
DateRange | Date range ruler | |
DateAndPriceRange | Combined ruler | |
| Brushes | Brush | Free-hand brush stroke |
Highlighter | Semi-transparent highlight | |
| Position | LongPosition | Long risk/reward box |
ShortPosition | Short risk/reward box | |
PositionForecast | Forecast cone | |
| Cycles | CyclicLines | Equally-spaced vertical lines |
TimeCycles | Semicircular arc series | |
SineLine | Sine wave | |
| Chart Patterns | XabcdPattern, CypherPattern, AbcdPattern, HeadAndShoulders, TrianglePattern, ThreeDrivesPattern | Harmonic and chart patterns |
| Elliott Waves | ElliottImpulseWave, ElliottCorrectiveWave, ElliottTriangleWave, ElliottDoubleCombo, ElliottTripleCombo | Elliott wave counts |
| Volume Profile | AnchoredVwap, VolumeProfileFixedRange, VolumeProfileAnchored | Volume analysis tools |
| Curves | Path, Arc, Curve, DoubleCurve | Multi-point curves (path is double-click to finish) |
| Misc | BarPattern, GhostFeed, Sector | Miscellaneous tools |
Sticky Mode
In sticky mode the tool remains active after each drawing is finalised, so the user can place multiple annotations of the same kind consecutively without re-selecting the tool:
// Enable sticky mode before activating a tool
cv.set_sticky_tool(true);
cv.set_tool(DrawingToolId::Trendline);
// The tool stays as Trendline after each line is drawn.
// Revert to normal single-shot mode:
cv.set_sticky_tool(false);Undo / Redo Integration
Wire undo and redo to keyboard shortcuts and toolbar buttons:
use navi_chart::DrawingTools;
fn build_toolbar_state<C>(cv: &C) -> ToolbarState
where
C: DrawingTools,
{
ToolbarState {
undo_enabled: cv.can_undo(),
redo_enabled: cv.can_redo(),
active_tool: cv.active_tool(),
sticky: cv.is_sticky_tool(),
}
}
fn on_undo_click<C>(cv: &C)
where
C: DrawingTools,
{
cv.undo();
// Rebuild toolbar state to reflect updated can_undo / can_redo
}Every add_annotation, update_annotation, remove_annotation, clear_annotations, and selection-mutation call (e.g. delete_selected_annotation) is tracked in the undo history automatically — no extra wiring is needed.