1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! # `canvist_canvas`
//!
//! The headless interaction core of canvist's canvas. Everything a design
//! tool's canvas does between input and pixels, with no UI:
//!
//! - a [`Camera`] that pans, zooms about a point, coasts with [`Inertia`],
//! and pinches;
//! - a [`SceneIndex`] of world transforms, sizes (auto-sized text, hugging
//! frames, auto-layout), outlines, and an R-tree, updated per commit;
//! - exact [`hit_test`]s on fills, strokes, and curves, selection targets,
//! and [`marquee`] selection;
//! - transform [`handles`] that resize, rotate, and skew, with constraints
//! and size kept separate from transform;
//! - [`Snapper`] smart guides and ruler [`ticks`];
//! - [`Tool`]s as typed extensions, commands, and inspectors as data;
//! - an [`OverlayItem`] list: the chrome, as data, for the host to draw.
//!
//! # Example
//!
//! ```
//! use std::sync::Arc;
//!
//! use canvist_canvas::Canvas;
//! use canvist_canvas::Input;
//! use canvist_canvas::PointerEvent;
//! use canvist_canvas::Phase;
//! use canvist_canvas::Shapes;
//! use canvist_canvas::TextLayouts;
//! use canvist_layout::FixedMeasurer;
//! use canvist_layout::Theme;
//! use canvist_scene::Scene;
//! use kurbo::Point;
//!
//! let mut builder = Canvas::builder();
//! let shapes = builder.add(Shapes);
//! let scene = Scene::new(builder.schema()?, 1)?;
//! let texts = TextLayouts::new(Arc::new(Theme::starter_kit()), FixedMeasurer::new());
//! let mut canvas = builder.build(scene, texts)?;
//!
//! // Drag out a rectangle with the rectangle tool.
//! canvas.set_tool(shapes.rectangle);
//! for (phase, x, y) in [(Phase::Down, 10.0, 10.0), (Phase::Move, 110.0, 60.0), (Phase::Up, 110.0, 60.0)] {
//! canvas.input(&Input::Pointer(PointerEvent::mouse(phase, Point::new(x, y), 0.0)))?;
//! }
//!
//! let rect = canvas.state().selection().nodes()[0];
//! let size = canvas.state().index().get(rect).map(|geometry| geometry.size);
//! assert_eq!(size, Some(kurbo::Vec2::new(100.0, 50.0)));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
pub use Camera;
pub use Inertia;
pub use MAX_ZOOM;
pub use MIN_ZOOM;
pub use Pinch;
pub use Canvas;
pub use CanvasBuilder;
pub use CanvasExtension;
pub use Command;
pub use CommandFn;
pub use Registration;
pub use ToolId;
pub use TypedCanvasExtension;
pub use Handle;
pub use HandleStyle;
pub use MarqueeMode;
pub use hit_test;
pub use marquee;
pub use paint_order;
pub use selection_target;
pub use NodeGeometry;
pub use SceneIndex;
pub use Input;
pub use KeyEvent;
pub use Modifiers;
pub use Phase;
pub use PointerEvent;
pub use PointerKind;
pub use WheelEvent;
pub use DesignKit;
pub use DesignKitHandle;
pub use Frames;
pub use FramesHandle;
pub use Images;
pub use ImagesHandle;
pub use Shapes;
pub use ShapesHandle;
pub use Texts;
pub use TextsHandle;
pub use Cursor;
pub use OutlineKind;
pub use OverlayItem;
pub use PointKind;
pub use Tick;
pub use ticks;
pub use Frame;
pub use Selection;
pub use TextSession;
pub use Axis;
pub use Guide;
pub use Snap;
pub use Snapper;
pub use CanvasError;
pub use CanvasState;
pub use LocalCommit;
pub use TextFrameLayout;
pub use TextLayouts;
pub use Outcome;
pub use Tool;
pub use Original;
pub use Originals;