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
//! Interactive effects on 2D elements: glossy liquids that react to the
//! pointer, on buttons, figures and anything else with a shape.
//!
//! Three ideas, each a trait or a type you can add to:
//!
//! | | |
//! |---|---|
//! | [`Component`] | what an element *is*: its [`Shape`], its content, how it responds — [`Button`], [`Figure`] |
//! | [`Effect`] | what it *wears*: a behaviour that draws a [`Surface`] and paints detail — [`Venom`], [`Gloss`] |
//! | [`Stage`] | the elements together: layout, hit-testing and [`Event`]s, the scene quads, the paint order, one [`Cursor`] |
//!
//! Any component wears any effect, so a new component works with every
//! effect and a new effect with every component:
//!
//! ```no_run
//! use threers::fx::{Anchor, Backdrop, Button, Figure, Gloss, GlossStyle, Look, Shape, Stage, Venom, VenomStyle};
//! use threers::math::Vector2;
//! use threers::sketch::{sketch, Frame, SketchOptions};
//!
//! sketch(SketchOptions::new("fx"), |s| {
//! let mut stage = Stage::new();
//! stage.set_backdrop(s.scene, Backdrop::STUDIO);
//! let go = stage.add(s.scene, Button::new("let's go"), Venom::default());
//! let star = Shape::star(Vector2::ZERO, 5, 70.0, 30.0, 6.0);
//! stage.add(
//! s.scene,
//! Figure::new(star).at(Anchor::Fraction(Vector2::new(0.5, 0.25))),
//! Venom::new(VenomStyle::default().with_look(Look::GOLD)),
//! );
//! stage.add(s.scene, Figure::new(Shape::circle(Vector2::new(120.0, 120.0), 40.0)), Gloss::new(GlossStyle::default().with_look(Look::CHROME)));
//! move |f: &mut Frame| {
//! for event in stage.sketch_frame(f) {
//! if event.element == go && event.kind == threers::fx::EventKind::Click {
//! println!("clicked");
//! }
//! }
//! }
//! });
//! ```
//!
//! Everything is in **CSS pixels** — logical, top-left origin, y down — the
//! way a UI is laid out; the device pixel ratio converts at the edges.
//!
//! # Adding an effect
//!
//! Implement [`Effect`]: step in [`update`](Effect::update) from the
//! element's shape and the pointer, and return a [`Surface`] — the shape plus
//! whatever grows out of it (strands, spikes, droplets, a mound), shaded in a
//! [`Look`] — and optionally paint detail on the overlay or decorate the
//! [`Cursor`]. [`Outline`] walks any shape's edge by arc length, for effects
//! that root things on it. The surface renderer is shared, so a new effect
//! draws on every backend the existing ones do.
//!
//! # Adding a component
//!
//! Implement [`Component`]: lay out against the viewport, return a [`Shape`],
//! animate on hover and press, paint content. The stage does the
//! hit-testing and raises the events.
//!
//! # Backends
//!
//! Surfaces are [`ShaderMaterial`](crate::ShaderMaterial)s with their WGSL
//! built on [`crate::sdf::WGSL`], so they run on wgpu everywhere — Metal,
//! Vulkan, DX12, WebGPU, and WebGL2 through the preamble's texture fallback
//! for their arrays. threers' own Metal renderer, which runs no WGSL,
//! recognises them and draws them with its port of the shader. The overlay
//! detail is a CPU canvas and goes wherever the overlay does.
pub
use Any;
pub use ;
pub use ;
pub use ;
pub use Look;
pub use ;
pub use ;
pub use ;
use crateVector2;
use crateOverlay;
/// What an effect gets each frame.
/// A behaviour an element wears: it steps with the pointer and draws a
/// [`Surface`], and may paint detail over the element's content and decorate
/// the cursor. See the [module docs](self) for adding one.