drafftink_core/widget/handles.rs
1//! Handle definitions for widget manipulation.
2
3use kurbo::Point;
4
5/// A manipulation handle on a widget.
6#[derive(Debug, Clone)]
7pub struct Handle {
8 /// The kind of handle (determines behavior).
9 pub kind: HandleKind,
10 /// Position in world coordinates.
11 pub position: Point,
12 /// Visual shape of the handle.
13 pub shape: HandleShape,
14}
15
16/// The kind of handle - determines what manipulation it performs.
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub enum HandleKind {
19 // Corner handles (for rectangles, ellipses, images)
20 TopLeft,
21 TopRight,
22 BottomLeft,
23 BottomRight,
24 // Edge handles (for resizing)
25 Top,
26 Bottom,
27 Left,
28 Right,
29 // Endpoint handles (for lines, arrows)
30 Start,
31 End,
32 // Control point handles (for curves)
33 Control(usize),
34 // Rotation handle
35 Rotate,
36}
37
38/// Visual shape of a handle.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
40pub enum HandleShape {
41 /// Square handle (default for corners).
42 #[default]
43 Square,
44 /// Circular handle (for line endpoints).
45 Circle,
46 /// Diamond handle (for control points).
47 Diamond,
48}
49
50impl Handle {
51 /// Create a new handle.
52 pub fn new(kind: HandleKind, position: Point) -> Self {
53 Self {
54 kind,
55 position,
56 shape: HandleShape::default(),
57 }
58 }
59
60 /// Set the handle shape.
61 pub fn with_shape(mut self, shape: HandleShape) -> Self {
62 self.shape = shape;
63 self
64 }
65}