fix(symbol): 9-slice guides switched off are kept and come back when switched on (M5)

This commit is contained in:
Tanish Manku committed 2026-11-11 14:00:10 -07:00
1 parent f4bc3eee6c
commit 54c27ef0d4
20 files changed
+83 -36

No files matched your search

+1 -1
View File
@@ -173,7 +173,7 @@ fn every_export_sees_the_pose() {
let mut k = Keyframe::new(0, 1);
k.elements.push(Arc::new(Element { id: ElementId(3), name: String::new(), transform: Affine::IDENTITY, color: ColorEffect::default(), kind: ElementKind::Shape(Shape::filled(Path::rect(0.0, -5.0, 100.0, 10.0), Paint::Solid(Rgba::BLACK))) }));
seg.keyframes = vec![Arc::new(k)];
d.library.push(Arc::new(Symbol { id: SEG, name: "Seg".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(seg)] } }));
d.library.push(Arc::new(Symbol { id: SEG, name: "Seg".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(seg)] } }));
d.timeline_mut(0).layers = vec![Arc::new(armature_layer(Easing::Linear))];
d.sanitize();
let dl = evaluate(&d, 10);
+1 -1
View File
@@ -141,7 +141,7 @@ fn the_camera_stays_on_top_alone_and_old_files_read_without_one() {
// A symbol's camera layer is a normal layer.
let mut sl = Layer::new(LayerId(80), "in symbol");
sl.kind = LayerKind::Camera;
d.library.push(Arc::new(Symbol { id: SymbolId(81), name: "S".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(sl)] } }));
d.library.push(Arc::new(Symbol { id: SymbolId(81), name: "S".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(sl)] } }));
d.sanitize();
assert_eq!(d.library[0].timeline.layers[0].kind, LayerKind::Normal);
// Depth round-trips, is left out when 0, and an old file reads at 0; hostile depths clamp.
+3 -3
View File
@@ -85,7 +85,7 @@ fn nested_symbols_compose_transforms_and_cycles_terminate() {
},
);
tl.layers.push(Arc::new(layer));
d.library.push(Arc::new(Symbol { id: sid, name: "loop".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: tl }));
d.library.push(Arc::new(Symbol { id: sid, name: "loop".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: tl }));
push(
layer0(&mut d),
0,
@@ -140,7 +140,7 @@ fn masks_inside_symbols_nest_in_the_instance_clip() {
// The main timeline's masked layer holds an instance of a symbol that has its own mask.
let mut d = mask_doc();
let sid = SymbolId(99);
d.library.push(Arc::new(Symbol { id: sid, name: "masked inside".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: mask_doc().timeline(0).clone() }));
d.library.push(Arc::new(Symbol { id: sid, name: "masked inside".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: mask_doc().timeline(0).clone() }));
let inst = Element {
id: ElementId(60),
name: String::new(),
@@ -295,7 +295,7 @@ fn movie_clips_play_their_own_timeline_graphics_keep_step_buttons_hold_up() {
})
.collect();
let mut d = Document::default();
d.library.push(Arc::new(Symbol { id: sid, name: "Clip".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(st)] } }));
d.library.push(Arc::new(Symbol { id: sid, name: "Clip".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(st)] } }));
// The same instance on two keyframes back to back (frames 0–4 and 5–11), moved on the second.
let inst = |x: f32| Element {
id: ElementId(60),
+8
View File
@@ -1025,6 +1025,10 @@ pub struct Symbol {
/// unscaled. `None`: the symbol scales as a whole.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scale_grid: Option<ScaleGrid>,
/// The guides as they were when 9-slice scaling was switched off (ADR 0057): switching it on
/// again brings them back where they were. Only kept, never drawn or applied.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scale_grid_kept: Option<ScaleGrid>,
pub timeline: Timeline,
}
@@ -1317,6 +1321,10 @@ impl Document {
if sym.scale_grid.as_ref().is_some_and(|g| g.check().is_err()) {
Arc::make_mut(sym).scale_grid = None;
}
// Kept guides (ADR 0057) only while 9-slice is off, and only usable ones.
if sym.scale_grid_kept.as_ref().is_some_and(|g| sym.scale_grid.is_some() || g.check().is_err()) {
Arc::make_mut(sym).scale_grid_kept = None;
}
let tl = &mut Arc::make_mut(sym).timeline;
for l in &mut tl.layers {
Arc::make_mut(l).normalize();
+1 -1
View File
@@ -388,7 +388,7 @@ impl Document {
let src = self.library.get(at)?.clone();
let new_id = SymbolId(self.alloc_id());
let timeline = fresh_ids(&src.timeline, &mut || self.alloc_id());
let copy = Symbol { id: new_id, name, kind: src.kind, linkage: None, scale_grid: src.scale_grid, timeline };
let copy = Symbol { id: new_id, name, kind: src.kind, linkage: None, scale_grid_kept: src.scale_grid_kept, scale_grid: src.scale_grid, timeline };
self.library.insert(at + 1, Arc::new(copy));
if let Some(f) = self.library_tree.placed.get(&LibraryItem::Symbol(id)).copied() {
Arc::make_mut(&mut self.library_tree).placed.insert(LibraryItem::Symbol(new_id), f);
+1 -1
View File
@@ -19,7 +19,7 @@ fn add_symbol(d: &mut Document, name: &str, inside: &[SymbolId]) -> SymbolId {
if let Some(k) = layer.keyframe_mut(0) {
k.elements = els;
}
d.library.push(Arc::new(Symbol { id, name: name.into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(layer)] } }));
d.library.push(Arc::new(Symbol { id, name: name.into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(layer)] } }));
id
}
+2 -2
View File
@@ -25,7 +25,7 @@ fn doc(xf: Affine, grid: Option<ScaleGrid>, extra: Vec<Element>) -> Document {
k.elements.extend(extra.into_iter().map(Arc::new));
let mut layer = Layer::new(LayerId(901), "art");
layer.keyframes = vec![Arc::new(k)];
d.library.push(Arc::new(Symbol { id: SYM, name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid: grid, timeline: Timeline { layers: vec![Arc::new(layer)] } }));
d.library.push(Arc::new(Symbol { id: SYM, name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid_kept: None, scale_grid: grid, timeline: Timeline { layers: vec![Arc::new(layer)] } }));
let mut k = Keyframe::new(0, 1);
k.elements.push(Arc::new(instance(SYM, xf)));
Arc::make_mut(&mut d.timeline_mut(0).layers[0]).keyframes = vec![Arc::new(k)];
@@ -147,7 +147,7 @@ fn unscaled_instances_and_nested_symbols_draw_as_they_are() {
k.elements.push(Arc::new(el(3, Affine::IDENTITY, ElementKind::Shape(Shape::filled(Path::rect(0.0, 0.0, 4.0, 4.0), Paint::Solid(Rgba::WHITE))))));
let mut l = Layer::new(LayerId(951), "dot");
l.keyframes = vec![Arc::new(k)];
d.library.push(Arc::new(Symbol { id: SymbolId(950), name: "Dot".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(l)] } }));
d.library.push(Arc::new(Symbol { id: SymbolId(950), name: "Dot".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(l)] } }));
let dl = evaluate(&d, 0);
let dot = dl.items.iter().find(|i| i.path.bounds().width() == 4.0).unwrap();
assert_eq!(dot.transform, Affine::scale(3.0, 3.0).mul(&Affine::translate(50.0, 20.0)));
+1 -1
View File
@@ -33,7 +33,7 @@ fn layer(id: u64, keys: Vec<Arc<Keyframe>>) -> Arc<Layer> {
}
fn symbol(id: u64, kind: SymbolKind, layers: Vec<Arc<Layer>>) -> Arc<Symbol> {
Arc::new(Symbol { id: SymbolId(id), name: format!("S{id}"), kind, linkage: None, scale_grid: None, timeline: Timeline { layers } })
Arc::new(Symbol { id: SymbolId(id), name: format!("S{id}"), kind, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers } })
}
fn doc(root: Vec<Arc<Layer>>, library: Vec<Arc<Symbol>>) -> Document {
+4 -4
View File
@@ -53,7 +53,7 @@ pub fn demo() -> Document {
.with_stroke(Rgba::hex(0x5a1410), 3.0);
let ball_el = el(&mut d, "ball body", Affine::IDENTITY, ElementKind::Shape(ball_shape));
let ball_layer = layer(d.alloc_id(), "body", 0x4fa3ff, vec![key(0, 1, vec![ball_el], None)]);
d.library.push(Arc::new(Symbol { id: ball_id, name: "Ball".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![ball_layer] } }));
d.library.push(Arc::new(Symbol { id: ball_id, name: "Ball".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![ball_layer] } }));
let star_id = SymbolId(d.alloc_id());
let star_shape = Shape::filled(Path::star(0.0, 0.0, 60.0, 26.0, 5), Paint::Solid(Rgba::hex(0xfff6a8))).with_stroke(Rgba::hex(0xe0a400), 2.5);
@@ -67,7 +67,7 @@ pub fn demo() -> Document {
})
.collect();
let star_layer = layer(d.alloc_id(), "spin", 0x4fa3ff, star_keys);
d.library.push(Arc::new(Symbol { id: star_id, name: "Star".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![star_layer] } }));
d.library.push(Arc::new(Symbol { id: star_id, name: "Star".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![star_layer] } }));
// --- main timeline (index 0 = top) ---------------------------------------------------
const LEN: u32 = 48;
@@ -161,7 +161,7 @@ pub fn interactive() -> Document {
let (up, over, down) = (face(&mut d, 0x3d8bfd), face(&mut d, 0x6aa8ff), face(&mut d, 0x2a64c0));
let hit_area = el(&mut d, "hit", Affine::IDENTITY, ElementKind::Shape(Shape::filled(Path::rect(-120.0, -50.0, 240.0, 100.0), solid(0x000000))));
let states = layer(d.alloc_id(), "states", 0x4fa3ff, vec![key(0, 1, up, None), key(1, 1, over, None), key(2, 1, down, None), key(3, 1, vec![hit_area], None)]);
d.library.push(Arc::new(Symbol { id: button_id, name: "Play Button".into(), kind: SymbolKind::Button, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![states] } }));
d.library.push(Arc::new(Symbol { id: button_id, name: "Play Button".into(), kind: SymbolKind::Button, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![states] } }));
// A movie clip that spins on its own timeline.
let spinner_id = SymbolId(d.alloc_id());
@@ -175,7 +175,7 @@ pub fn interactive() -> Document {
})
.collect();
let spin = layer(d.alloc_id(), "spin", 0xffd54a, spin_keys);
d.library.push(Arc::new(Symbol { id: spinner_id, name: "Spinner".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![spin] } }));
d.library.push(Arc::new(Symbol { id: spinner_id, name: "Spinner".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![spin] } }));
// Main timeline: actions on top, then the button (menu frame), the show, the backdrop.
let mut menu = key(0, 1, Vec::new(), None);
+1 -1
View File
@@ -565,7 +565,7 @@ impl<'a> Layout<'a> {
let enters = pa == s0 || (pa == st.l0 && st.enters);
self.looped(tl, g, (pa - s0) % len, n, len, enters, gain, depth);
}
// Buttons wait for the pointer: their sounds are not in this slice (ADR 0039).
// Buttons sound only under the pointer, in the interactive player (ADR 0057).
(SymbolKind::Button, _) => {}
}
}
+1 -1
View File
@@ -194,7 +194,7 @@ fn nested(kind: SymbolKind, len: u32, inner: &[(u32, u32, Option<FrameSound>)],
// Pad the symbol's timeline to `len` frames with a second, silent layer.
let mut pad = Layer::new(LayerId(11), "pad");
pad.keyframes = vec![Arc::new(Keyframe::new(0, len))];
d.library.push(Arc::new(Symbol { linkage: None, scale_grid: None, id: SymbolId(50), name: "S".into(), kind, timeline: Timeline { layers: vec![Arc::new(il), Arc::new(pad)] } }));
d.library.push(Arc::new(Symbol { linkage: None, scale_grid_kept: None, scale_grid: None, id: SymbolId(50), name: "S".into(), kind, timeline: Timeline { layers: vec![Arc::new(il), Arc::new(pad)] } }));
let mut l = Layer::new(LayerId(1), "outer");
l.keyframes = instances
.iter()
+10 -5
View File
@@ -39,7 +39,7 @@ pub fn specs() -> Vec<CommandSpec> {
"9-Slice Scaling",
"",
None,
"{symbol?: id (default: the symbol open for editing, else the selected instance's), on?: bool, left?, right?, top?, bottom? (guide positions in the symbol's space)} turns a symbol's guides for 9-slice scaling on or off, or moves them (ADR 0055). Turning them on puts them a quarter of the way in from each edge of the symbol's artwork; moving one turns them on. Scaled instances then keep the corners outside the guides unscaled, stretch the edges one way and the centre both ways → {symbol, scale_grid: {left, right, top, bottom} | null}",
"{symbol?: id (default: the symbol open for editing, else the selected instance's), on?: bool, left?, right?, top?, bottom? (guide positions in the symbol's space)} turns a symbol's guides for 9-slice scaling on or off, or moves them (ADR 0055). Turning them on brings back the guides it had when they were turned off (ADR 0057), else puts them a quarter of the way in from each edge of the symbol's artwork; moving one turns them on. Scaled instances then keep the corners outside the guides unscaled, stretch the edges one way and the centre both ways → {symbol, scale_grid: {left, right, top, bottom} | null}",
true,
set_scale_grid,
),
@@ -602,7 +602,8 @@ fn set_scale_grid(s: &mut Session, p: &Value) -> Result<Value> {
}
None
} else {
let start = sym.scale_grid.unwrap_or_else(|| {
// Switched on again, the guides come back where they were (ADR 0057).
let start = sym.scale_grid.or(sym.scale_grid_kept).unwrap_or_else(|| {
let b = anicraft_doc::symbol_box(&s.doc, sym);
ScaleGrid::inset(&if b.is_empty() { anicraft_geom::Rect::new(0.0, 0.0, 100.0, 100.0) } else { b })
});
@@ -611,10 +612,14 @@ fn set_scale_grid(s: &mut Session, p: &Value) -> Result<Value> {
g.check().map_err(EngineError::Param)?;
Some(g)
};
// Off, the guides are kept (only hidden), so switching back on finds them.
let kept = if grid.is_none() { sym.scale_grid.or(sym.scale_grid_kept) } else { None };
if let Some(sym) = s.doc.library.iter_mut().find(|x| x.id == id)
&& sym.scale_grid != grid
&& (sym.scale_grid != grid || sym.scale_grid_kept != kept)
{
Arc::make_mut(sym).scale_grid = grid;
let sym = Arc::make_mut(sym);
sym.scale_grid = grid;
sym.scale_grid_kept = kept;
}
Ok(json!({"symbol": id.0, "scale_grid": grid.map(|g| json!({"left": g.left, "right": g.right, "top": g.top, "bottom": g.bottom}))}))
}
@@ -767,7 +772,7 @@ pub(crate) fn convert_to_symbol(s: &mut Session, p: &Value) -> Result<Value> {
}
inner.push(Arc::new(layer));
}
s.doc.library.push(Arc::new(Symbol { id: sym_id, name: name.clone(), kind, linkage: None, scale_grid: None, timeline: Timeline { layers: inner } }));
s.doc.library.push(Arc::new(Symbol { id: sym_id, name: name.clone(), kind, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: inner } }));
if folder.is_some() {
s.doc.place_entry(LibraryEntry::Item(LibraryItem::Symbol(sym_id)), folder);
}
+1 -1
View File
@@ -215,7 +215,7 @@ impl Session {
/// at opacity `alpha` (a symbol added to `doc`, which is only drawn).
fn placed(doc: &mut Document, timeline: Timeline, transform: Affine, frame: u32, alpha: f32) -> Arc<Layer> {
let symbol = SymbolId(doc.alloc_id());
doc.library.push(Arc::new(Symbol { id: symbol, name: String::new(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline }));
doc.library.push(Arc::new(Symbol { id: symbol, name: String::new(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline }));
let mut k = Keyframe::new(0, 1);
k.elements.push(Arc::new(Element {
id: ElementId(doc.alloc_id()),
+39 -5
View File
@@ -38,13 +38,45 @@ fn turning_guides_on_puts_them_a_quarter_in_and_moving_one_keeps_the_rest() {
run(&mut s, "symbol.set_scale_grid", json!({"left": -40, "right": 40, "top": -10, "bottom": 10}));
run(&mut s, "symbol.set_scale_grid", json!({"top": -12}));
assert_eq!(grid(&s, id), Some(ScaleGrid { left: -40.0, right: 40.0, top: -12.0, bottom: 10.0 }));
// Off forgets them (as in Animate, turning them on again starts from the artwork).
// Off hides them: the symbol scales as a whole (ADR 0057).
let v = run(&mut s, "symbol.set_scale_grid", json!({"on": false}));
assert_eq!(v["scale_grid"], Value::Null);
assert_eq!(grid(&s, id), None);
// Moving a guide turns them on.
// Moving a guide turns them on, from where they were.
run(&mut s, "symbol.set_scale_grid", json!({"symbol": id.0, "left": -45}));
assert_eq!(grid(&s, id).map(|g| g.left), Some(-45.0));
assert_eq!(grid(&s, id), Some(ScaleGrid { left: -45.0, right: 40.0, top: -12.0, bottom: 10.0 }));
}
#[test]
fn guides_switched_off_and_on_again_come_back_where_they_were() {
let (mut s, id) = panel();
let moved = ScaleGrid { left: -40.0, right: 30.0, top: -12.0, bottom: 6.0 };
run(&mut s, "symbol.set_scale_grid", json!({"left": -40, "right": 30, "top": -12, "bottom": 6}));
run(&mut s, "symbol.set_scale_grid", json!({"on": false}));
let kept = |s: &Session| s.doc.symbol(id).and_then(|x| x.scale_grid_kept);
assert_eq!((grid(&s, id), kept(&s)), (None, Some(moved)), "kept, not applied");
// Off twice keeps them still; saved and opened, they are still there.
run(&mut s, "symbol.set_scale_grid", json!({"on": false}));
let file = crate::format::to_json(&s.doc).unwrap();
assert!(file.contains("scale_grid_kept"));
let mut s = Session::new(crate::format::from_json(&file).unwrap());
assert_eq!(kept(&s), Some(moved));
run(&mut s, "symbol.set_scale_grid", json!({"symbol": id.0, "on": true}));
assert_eq!((grid(&s, id), kept(&s)), (Some(moved), None), "on again: back where they were");
// Undo goes back to off with the guides kept.
s.undo().unwrap();
assert_eq!((grid(&s, id), kept(&s)), (None, Some(moved)));
// A kept grid that isn't usable, or kept beside guides that are on, is dropped on load.
let mut d = s.doc.clone();
let sym = std::sync::Arc::make_mut(&mut d.library[0]);
sym.scale_grid_kept = Some(ScaleGrid { left: 5.0, right: -5.0, top: 0.0, bottom: 1.0 });
let d = crate::format::from_json(&crate::format::to_json(&d).unwrap()).unwrap();
assert_eq!(d.library[0].scale_grid_kept, None);
let mut d = s.doc.clone();
let sym = std::sync::Arc::make_mut(&mut d.library[0]);
sym.scale_grid = Some(moved);
let d = crate::format::from_json(&crate::format::to_json(&d).unwrap()).unwrap();
assert_eq!((d.library[0].scale_grid, d.library[0].scale_grid_kept), (Some(moved), None));
}
#[test]
@@ -101,10 +133,12 @@ fn the_guides_survive_the_file_and_older_files_open_without_them() {
assert!(text.contains("\"scale_grid\""));
let back = crate::format::from_json(&text).unwrap();
assert_eq!(back.symbol(id).and_then(|x| x.scale_grid), grid(&s, id));
// A symbol without guides writes nothing for them, so older files read the same.
// A symbol whose guides are off keeps them apart (ADR 0057), and one that never had any
// writes nothing for them, so older files read the same.
run(&mut s, "symbol.set_scale_grid", json!({"on": false}));
let text = crate::format::to_json(&s.doc).unwrap();
assert!(!text.contains("scale_grid"));
assert!(!text.contains("\"scale_grid\"") && text.contains("\"scale_grid_kept\""));
assert!(!crate::format::to_json(&panel().0.doc).unwrap().contains("scale_grid"));
assert_eq!(crate::format::from_json(&text).unwrap().symbol(id).and_then(|x| x.scale_grid), None);
// Unusable guides in a file are dropped, not drawn.
let mut doc = s.doc.clone();
+1 -1
View File
@@ -31,7 +31,7 @@ pub(crate) fn three_bars() -> Session {
k.elements.push(Arc::new(Element { id: ElementId(3), name: String::new(), transform: Affine::IDENTITY, color: ColorEffect::default(), kind: ElementKind::Shape(Shape::filled(Path::rect(0.0, -5.0, 100.0, 10.0), Paint::Solid(Rgba::BLACK))) }));
k
});
d.library.push(Arc::new(Symbol { id: bar, name: "Bar".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(inner)] } }));
d.library.push(Arc::new(Symbol { id: bar, name: "Bar".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers: vec![Arc::new(inner)] } }));
let inst = |id: u64, x: f32| Arc::new(Element { id: ElementId(id), name: String::new(), transform: Affine::translate(x, 100.0), color: ColorEffect::default(), kind: ElementKind::Symbol { symbol: bar, loop_mode: LoopMode::Loop, first_frame: 0, blend: BlendMode::Normal, filters: Vec::new(), events: Vec::new() } });
let shape = Arc::new(Element { id: ElementId(SHAPE), name: String::new(), transform: Affine::translate(100.0, 250.0), color: ColorEffect::default(), kind: ElementKind::Shape(Shape::filled(Path::rect(0.0, 0.0, 20.0, 20.0), Paint::Solid(Rgba::BLACK))) });
let l = Arc::make_mut(&mut d.timeline_mut(0).layers[0]);
+1 -1
View File
@@ -308,7 +308,7 @@ fn sounds_inside_symbols_are_in_the_exported_soundtrack_at_their_offset_and_loop
let mut k = Keyframe::new(1, 3);
k.sound = Some(FrameSound::new(SoundId(id)));
inner.keyframes = vec![Arc::new(Keyframe::new(0, 1)), Arc::new(k)];
s.doc.library.push(Arc::new(Symbol { linkage: None, scale_grid: None, id: SymbolId(501), name: "Talk".into(), kind: SymbolKind::Graphic, timeline: Timeline { layers: vec![Arc::new(inner)] } }));
s.doc.library.push(Arc::new(Symbol { linkage: None, scale_grid_kept: None, scale_grid: None, id: SymbolId(501), name: "Talk".into(), kind: SymbolKind::Graphic, timeline: Timeline { layers: vec![Arc::new(inner)] } }));
let mut k = Keyframe::new(1, 8);
k.elements.push(Arc::new(Element { id: ElementId(502), name: String::new(), transform: Default::default(), color: Default::default(), kind: ElementKind::Symbol { symbol: SymbolId(501), loop_mode: LoopMode::Loop, first_frame: 0, blend: Default::default(), filters: Vec::new(), events: Vec::new() } }));
let mut outer = Layer::new(LayerId(503), "puppet");
+1 -1
View File
@@ -476,7 +476,7 @@ fn nine_slice_sample() -> anicraft_doc::Document {
k.elements.push(el(2, Affine::IDENTITY, ElementKind::Shape(shape)));
let mut l = Layer::new(LayerId(3), "art");
l.keyframes = vec![std::sync::Arc::new(k)];
d.library.push(std::sync::Arc::new(Symbol { id: SymbolId(4), name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid: Some(ScaleGrid { left: 8.0, right: 52.0, top: 8.0, bottom: 22.0 }), timeline: Timeline { layers: vec![std::sync::Arc::new(l)] } }));
d.library.push(std::sync::Arc::new(Symbol { id: SymbolId(4), name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid_kept: None, scale_grid: Some(ScaleGrid { left: 8.0, right: 52.0, top: 8.0, bottom: 22.0 }), timeline: Timeline { layers: vec![std::sync::Arc::new(l)] } }));
let inst = |id, xf| el(id, xf, ElementKind::Symbol { symbol: SymbolId(4), loop_mode: Default::default(), first_frame: 0, blend: Default::default(), filters: Vec::new(), events: Vec::new() });
let mut k = Keyframe::new(0, 1);
k.elements.push(inst(5, Affine::translate(10.0, 10.0).mul(&Affine::scale(4.5, 1.2))));
+4 -4
View File
@@ -36,7 +36,7 @@ fn layer(id: u64, keys: Vec<Arc<Keyframe>>) -> Arc<Layer> {
}
fn symbol(id: u64, kind: SymbolKind, layers: Vec<Arc<Layer>>) -> Arc<Symbol> {
Arc::new(Symbol { id: SymbolId(id), name: format!("S{id}"), kind, linkage: None, scale_grid: None, timeline: Timeline { layers } })
Arc::new(Symbol { id: SymbolId(id), name: format!("S{id}"), kind, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline { layers } })
}
fn this() -> Target {
@@ -463,7 +463,7 @@ fn frames_are_baked_and_stored_once() {
assert!(m.stats.paths < 40, "{:?}", m.stats);
// Unused library symbols stay out.
let mut d = doc.clone();
d.library.push(Arc::new(Symbol { id: SymbolId(999_999), name: "unused".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid: None, timeline: Timeline::default() }));
d.library.push(Arc::new(Symbol { id: SymbolId(999_999), name: "unused".into(), kind: SymbolKind::Graphic, linkage: None, scale_grid_kept: None, scale_grid: None, timeline: Timeline::default() }));
assert_eq!(movie(&d, &HtmlOptions::default()).json["symbols"], m.json["symbols"]);
}
@@ -608,8 +608,8 @@ fn sounds_carry_their_envelopes_and_volumes_and_start_in_graphics_and_clips_as_i
let inst = |id, symbol| Arc::new(Element { id: ElementId(id), name: String::new(), transform: Affine::IDENTITY, color: Default::default(), kind: ElementKind::Symbol { symbol: SymbolId(symbol), loop_mode: Default::default(), first_frame: 0, blend: Default::default(), filters: Vec::new(), events: Vec::new() } });
// A graphic with a fading sound on its frame 1 (of 2), a clip with a left-channel one on its
// frame 0 (of 3), both on a layer at half volume; a sound of the main timeline's own.
doc.library.push(Arc::new(Symbol { linkage: None, scale_grid: None, id: SymbolId(20), name: "g".into(), kind: SymbolKind::Graphic, timeline: Timeline { layers: vec![layer(21, vec![key(0, 1, None, vec![]), key(1, 1, snd(SoundSync::Event, SoundEffect::FadeOut), vec![])], 1.0)] } }));
doc.library.push(Arc::new(Symbol { linkage: None, scale_grid: None, id: SymbolId(30), name: "c".into(), kind: SymbolKind::MovieClip, timeline: Timeline { layers: vec![layer(31, vec![key(0, 3, snd(SoundSync::Stream, SoundEffect::LeftChannel), vec![])], 0.5)] } }));
doc.library.push(Arc::new(Symbol { linkage: None, scale_grid_kept: None, scale_grid: None, id: SymbolId(20), name: "g".into(), kind: SymbolKind::Graphic, timeline: Timeline { layers: vec![layer(21, vec![key(0, 1, None, vec![]), key(1, 1, snd(SoundSync::Event, SoundEffect::FadeOut), vec![])], 1.0)] } }));
doc.library.push(Arc::new(Symbol { linkage: None, scale_grid_kept: None, scale_grid: None, id: SymbolId(30), name: "c".into(), kind: SymbolKind::MovieClip, timeline: Timeline { layers: vec![layer(31, vec![key(0, 3, snd(SoundSync::Stream, SoundEffect::LeftChannel), vec![])], 0.5)] } }));
doc.timeline_mut(0).layers = vec![layer(1, vec![key(0, 6, snd(SoundSync::Event, SoundEffect::None), vec![])], 1.0), layer(2, vec![key(0, 6, None, vec![inst(40, 20), inst(41, 30)])], 0.5)];
let m = movie(&doc, &HtmlOptions::default());
// The fade's points span one play (half a second); the clip's span its 3 frames.
+1 -1
View File
@@ -16,7 +16,7 @@ fn panel(sx: f32, sy: f32, guides: bool) -> Document {
let mut l = Layer::new(LayerId(3), "art");
l.keyframes = vec![Arc::new(k)];
let grid = guides.then_some(ScaleGrid { left: 10.0, right: 90.0, top: 10.0, bottom: 30.0 });
d.library.push(Arc::new(Symbol { id: SymbolId(4), name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid: grid, timeline: Timeline { layers: vec![Arc::new(l)] } }));
d.library.push(Arc::new(Symbol { id: SymbolId(4), name: "Panel".into(), kind: SymbolKind::MovieClip, linkage: None, scale_grid_kept: None, scale_grid: grid, timeline: Timeline { layers: vec![Arc::new(l)] } }));
let inst = Element {
id: ElementId(5),
name: String::new(),
+1 -1
View File
@@ -824,7 +824,7 @@ impl<'a> Builder<'a> {
};
let short = name.rsplit('/').next().unwrap_or(&name).to_string();
let scale_grid = self.scale_grid(&item);
self.doc.library.push(Arc::new(Symbol { id, name: short, kind, linkage, scale_grid, timeline }));
self.doc.library.push(Arc::new(Symbol { id, name: short, kind, linkage, scale_grid, scale_grid_kept: None, timeline }));
self.place_in_folder(&name, anicraft_doc::LibraryItem::Symbol(id));
}
}