-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
typst_basic.rs
165 lines (140 loc) · 5.54 KB
/
typst_basic.rs
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
fn main() {}
// use bevy::prelude::*;
// use bevy_motiongfx::prelude::*;
// use bevy_motiongfx::typst::{TypstCompiler, TypstCompilerPlugin};
// fn main() {
// App::new()
// // Bevy plugins
// .add_plugins(DefaultPlugins)
// // Custom plugins
// .add_plugins((
// MotionGfxPlugin,
// MotionGfxVelloPlugin,
// TypstCompilerPlugin::new(Vec::new()),
// ))
// .add_systems(Startup, (setup, typst_basic))
// .add_systems(Update, timeline_movement)
// .run();
// }
// fn typst_basic(
// mut commands: Commands,
// mut typst_compiler: ResMut<TypstCompiler>,
// mut scenes: ResMut<Assets<VelloScene>>,
// ) {
// let content = String::from(
// r###"
// #set page(width: 1120pt, margin: 8pt)
// #set raw(theme: "themes/Monokai Pro.tmTheme")
// #set text(size: 24pt, fill: rgb("#FCFCFA"))
// #box()[
// #text(fill: gradient.linear(rgb("#13A8C1"), rgb("#21C0AA")))[= Typst]
// ]
// $ frac(a^2, 2) $
// $ vec(1, 2, delim: "[") $
// $ mat(1, 2; 3, 4) $
// $ lim_x = op("lim", limits: #true)_x $
// ```rs
// fn main() {
// println!("Hello from Typst!");
// }
// ```
// "###,
// );
// match typst_compiler.compile_flatten(&mut commands, &mut scenes, content) {
// Ok(tree) => {
// commands
// .entity(tree.root_entity)
// .insert(Transform::from_xyz(-500.0, 300.0, 0.0));
// // Motion
// let path_len = tree.paths.len();
// let path_ids = Vec::with_capacity(path_len);
// let mut transforms = Vec::with_capacity(path_len);
// let mut fill_motions = Vec::with_capacity(path_len);
// let mut stroke_motions = Vec::with_capacity(path_len);
// // tree.paths.iter().map();
// for p in 0..path_len {
// let path = &tree.paths[p];
// path_ids.push(path.entity);
// transforms.push(path.transform);
// if let Some(fill) = &path.fill {
// fill_motions.push(Some(FillStyleMotion::new(path.entity, fill.clone())));
// } else {
// fill_motions.push(None);
// }
// if let Some(stroke) = &path.stroke {
// stroke_motions.push(Some(StrokeStyleMotion::new(path.entity, stroke.clone())));
// } else {
// stroke_motions.push(None);
// }
// }
// // Animations
// let mut setup_seqs = Vec::with_capacity(path_len);
// let mut animate_seqs = Vec::with_capacity(path_len);
// let transform_offset = Vec3::Y * 24.0;
// for p in 0..path_len {
// let path = &tree.paths[p];
// if let Some(motion) = &mut fill_motions[p] {
// setup_seqs.push(commands.play(motion.brush_to(Color::NONE), 0.0));
// }
// if let Some(motion) = &mut stroke_motions[p] {
// setup_seqs.push(commands.play(motion.brush_to(Color::NONE), 0.0));
// }
// animate_seqs.push(all(&[
// commands.play(transforms[p].translate_add(transform_offset), 1.0),
// {
// if let Some(motion) = &mut fill_motions[p] {
// let brush = path.fill.as_ref().unwrap().brush.clone();
// commands.play(motion.brush_to(brush), 1.0)
// } else {
// commands.sleep(1.0)
// }
// },
// {
// if let Some(motion) = &mut stroke_motions[p] {
// let brush = path.stroke.as_ref().unwrap().brush.clone();
// commands.play(motion.brush_to(brush), 1.0)
// } else {
// commands.sleep(1.0)
// }
// },
// ]));
// }
// let sequence = all(&[all(&setup_seqs), flow(0.1, &animate_seqs)])
// .with_ease(ease::expo::ease_in_out);
// commands.spawn(SequencePlayerBundle {
// sequence,
// ..default()
// });
// }
// Err(err) => {
// println!("{:#?}", err);
// }
// }
// }
// fn setup(mut commands: Commands) {
// commands.spawn(Camera2dBundle::default());
// }
// fn timeline_movement(
// mut q_timelines: Query<(&mut SequencePlayer, &mut SequenceController)>,
// keys: Res<ButtonInput<KeyCode>>,
// time: Res<Time>,
// ) {
// for (mut sequence_player, mut sequence_time) in q_timelines.iter_mut() {
// if keys.pressed(KeyCode::KeyD) {
// sequence_time.target_time += time.delta_seconds();
// }
// if keys.pressed(KeyCode::KeyA) {
// sequence_time.target_time -= time.delta_seconds();
// }
// if keys.just_pressed(KeyCode::Space) {
// if keys.pressed(KeyCode::ShiftLeft) {
// sequence_player.time_scale = -1.0;
// } else {
// sequence_player.time_scale = 1.0;
// }
// }
// if keys.just_pressed(KeyCode::Escape) {
// sequence_player.time_scale = 0.0;
// }
// }
// }