Skip to main content

egui_charts/config/drawing_tool/
interaction_mode.rs

1//! Drawing interaction mode.
2//!
3//! Defines how mouse/pointer input is translated into point capture for each
4//! drawing tool type. The [`DrawingInteractionMode`] determines the UX flow
5//! for creating a drawing, and the drawing manager
6//! uses it to decide when a drawing is considered complete.
7
8/// How a drawing tool captures points from mouse/pointer input.
9///
10/// Every [`DrawingToolType`](super::DrawingToolType) maps to exactly one
11/// interaction mode via
12/// [`DrawingToolType::interaction_mode()`](super::DrawingToolType::interaction_mode).
13/// The mode governs the full creation flow: how many clicks are needed, whether
14/// dragging is involved, and when the drawing is marked as complete.
15///
16/// # Example
17///
18/// ```
19/// use egui_charts::config::{DrawingToolType, DrawingInteractionMode};
20///
21/// assert_eq!(
22///     DrawingToolType::TrendLine.interaction_mode(),
23///     DrawingInteractionMode::ClickClick,
24/// );
25/// assert_eq!(
26///     DrawingToolType::Rect.interaction_mode(),
27///     DrawingInteractionMode::DragToDraw,
28/// );
29/// ```
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum DrawingInteractionMode {
32    /// Click once to place (e.g., `HorizontalLine`, `TextLabel`, arrow markers).
33    ///
34    /// The drawing is created and completed with a single click. Only one
35    /// `ChartPoint` is captured.
36    SingleClick,
37    /// Click to set the first point, move, then click to set the second point
38    /// (e.g., `TrendLine`, `Ray`, `ExtendedLine`).
39    ///
40    /// A preview line follows the cursor between the first and second clicks.
41    ClickClick,
42    /// Press the mouse button to set the first point, drag to the second point,
43    /// and release to complete (e.g., `Rect`, `Circle`, `FibonacciRetracement`).
44    DragToDraw,
45    /// Hold the mouse button and draw a freehand path; release to complete
46    /// (e.g., `Brush`, `Highlighter`).
47    ///
48    /// Points are continuously appended while the button is held.
49    ContinuousDraw,
50    /// Click to add points one at a time; double-click or press Enter to finish
51    /// (e.g., `Polyline`, `XABCDPattern`, `ElliottImpulse`).
52    ///
53    /// The number of required points varies by tool (see
54    /// [`DrawingToolType::required_points()`](super::DrawingToolType::required_points)).
55    /// Some tools (like `Polyline`) have no fixed limit.
56    MultiPoint,
57    /// Not a drawing tool -- cursor/interaction modes only
58    /// (e.g., `CrossCursor`, `Eraser`).
59    ///
60    /// These tools modify the cursor or provide utility functions but do not
61    /// create `Drawing` objects.
62    NotDrawing,
63}