Compare commits

...
Author SHA1 Message Date
autocraft-bot[bot] 683df5a395 Merge main (078493b2) into the pull request
Resolved the conflict in crates/ui-egui/src/show/tests.rs. The file keep

Resolved the conflict in crates/ui-egui/src/show/tests.rs. The file keeps both the pull request's paragraph_animations_follow_the_order_their_triggers_were_clicked test and the default branch's a_slow_first_frame_does_not_use_up_the_transition test, each with its own #[test]. I added StepStamp, Timeline and TriggerPlay to the deckcraft_anim import, which the pull request's test needs; they are exported by the anim crate. No conflict markers remain and rustfmt --check passes. I couldn't confirm the build or the tests: the cargo test build dropped the connection mid-run.
2026-12-04 21:42:10 +00:00
ViktorBystrov72 9b2c47f3ca fix(show): honor triggers for paragraph animations 2026-11-25 16:38:26 +05:00
autocraft-bot[bot] 82ce5caf85 Apply review fixes
- crates/ui-egui/src/show.rs
2026-11-25 01:14:04 +00:00
ViktorBystrov72 bed4db6fbb Animations: desaturate the text in a text box 2026-11-23 21:16:28 +05:00
11 changed files with 238 additions and 54 deletions
+9 -4
View File
@@ -21,6 +21,7 @@ pub(crate) struct EffectSpec {
pub amount: Option<f64>,
pub color: Option<Rgba>,
pub path: Option<MotionPath>,
pub text_box: bool,
/// Shape box in points (sanitized).
pub xf: Xfrm,
pub slide_w: f64,
@@ -279,10 +280,8 @@ impl EffectSpec {
}
}
}
"desaturate" => {
let l = (0.299 * cur.r as f64 + 0.587 * cur.g as f64 + 0.114 * cur.b as f64).round().clamp(0.0, 255.0) as u8;
st.tint = Some(cur.lerp(Rgba::rgba(l, l, l, cur.a), e));
}
"desaturate" if self.text_box => st.text_desaturation = e,
"desaturate" => st.tint = Some(desaturate_color(cur, e)),
"darken" => st.tint = Some(cur.lerp(Rgba::rgba(0, 0, 0, cur.a), 0.4 * e)),
"lighten" => st.tint = Some(cur.lerp(Rgba::rgba(255, 255, 255, cur.a), 0.4 * e)),
"transparency" => {
@@ -318,6 +317,12 @@ impl EffectSpec {
}
}
/// Interpolate toward a gray of the same luma, retaining the source alpha.
pub fn desaturate_color(color: Rgba, amount: f64) -> Rgba {
let gray = (0.299 * color.r as f64 + 0.587 * color.g as f64 + 0.114 * color.b as f64).round() as u8;
color.lerp(Rgba::rgba(gray, gray, gray, color.a), amount)
}
/// The path for a motion-path animation: its own, or the preset default.
pub(crate) fn motion_path(effect: &str, option: &str, own: Option<&str>) -> MotionPath {
match own {
+18 -2
View File
@@ -36,6 +36,7 @@ pub use deckcraft_model::Rgba;
use serde::{Deserialize, Serialize};
pub use easing::ease;
pub use effects::desaturate_color;
pub use interact::{Click, HitShape, Target};
pub use mesh::{MeshVertex, layer_mesh};
pub use morph::{MorphFrame, MorphPath, MorphText, morph_crop, morph_frame, morph_pairs, morph_xfrm};
@@ -48,7 +49,7 @@ pub use transition::{DEFAULT_ASPECT, Layer, Source, transition_frame, transition
///
/// Same meaning as the renderer's `ShapeState`: translation in points, scale and rotation (degrees)
/// around the shape's centre, a reveal clip in shape-local unit space `[l, t, r, b]`, and a fill
/// colour override.
/// colour override or a reduction in the saturation of text colours.
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct AnimState {
pub visible: bool,
@@ -60,11 +61,24 @@ pub struct AnimState {
pub rotate: f64,
pub clip: Option<[f64; 4]>,
pub tint: Option<Rgba>,
#[serde(default)]
pub text_desaturation: f64,
}
impl Default for AnimState {
fn default() -> Self {
AnimState { visible: true, opacity: 1.0, offset_x: 0.0, offset_y: 0.0, scale_x: 1.0, scale_y: 1.0, rotate: 0.0, clip: None, tint: None }
AnimState {
visible: true,
opacity: 1.0,
offset_x: 0.0,
offset_y: 0.0,
scale_x: 1.0,
scale_y: 1.0,
rotate: 0.0,
clip: None,
tint: None,
text_desaturation: 0.0,
}
}
}
@@ -95,12 +109,14 @@ impl AnimState {
rotate: self.rotate + d.rotate,
clip,
tint: d.tint.or(self.tint),
text_desaturation: self.text_desaturation + (1.0 - self.text_desaturation) * d.text_desaturation,
}
}
/// Replace any non-finite number with its neutral value and clamp opacity and clip.
pub fn sanitized(mut self) -> AnimState {
let f = |v: f64, d: f64| if v.is_finite() { v } else { d };
self.opacity = f(self.opacity, 1.0).clamp(0.0, 1.0);
self.text_desaturation = f(self.text_desaturation, 0.0).clamp(0.0, 1.0);
self.offset_x = f(self.offset_x, 0.0);
self.offset_y = f(self.offset_y, 0.0);
self.scale_x = f(self.scale_x, 1.0);
+3 -2
View File
@@ -279,7 +279,7 @@ impl Timeline {
};
let xf = xfrm_of(a.shape).or_else(|| shape.and_then(|s| s.xfrm)).unwrap_or(Xfrm::new(sw / 4.0, sh / 4.0, sw / 2.0, sh / 2.0));
let xf = sanitize_xfrm(xf, sw, sh);
let spec = Arc::new(build_spec(a, xf, sw, sh, &resolve));
let spec = Arc::new(build_spec(a, xf, sw, sh, shape.is_some_and(|s| s.text_box), &resolve));
let dur = secs(a.duration_ms);
let delay = secs(a.delay_ms);
let until_next_click = a.repeat == u32::MAX;
@@ -612,7 +612,7 @@ fn shape_index(shapes: &[Shape]) -> HashMap<ShapeId, &Shape> {
out
}
fn build_spec(a: &Animation, xf: Xfrm, sw: f64, sh: f64, resolve: &dyn Fn(&deckcraft_model::ColorRef) -> Rgba) -> EffectSpec {
fn build_spec(a: &Animation, xf: Xfrm, sw: f64, sh: f64, text_box: bool, resolve: &dyn Fn(&deckcraft_model::ColorRef) -> Rgba) -> EffectSpec {
let effect = if a.class == AnimClass::Exit { exit_base(&a.effect).to_string() } else { a.effect.clone() };
let path = if a.class == AnimClass::Path { Some(motion_path(&a.effect, &a.option, a.path.as_deref())) } else { None };
EffectSpec {
@@ -626,6 +626,7 @@ fn build_spec(a: &Animation, xf: Xfrm, sw: f64, sh: f64, resolve: &dyn Fn(&deckc
amount: a.amount,
color: a.color.as_ref().map(resolve),
path,
text_box,
xf,
slide_w: sw,
slide_h: sh,
+18 -5
View File
@@ -14,22 +14,35 @@ const MAX_DEPTH: usize = 64;
/// Fills and gradient stops one colour glyph may paint; the rest of a hostile glyph is skipped.
const MAX_WORK: usize = 100_000;
pub(super) struct Colors {
/// Text colour (palette index 0xFFFF), already desaturated if needed.
pub foreground: Rgba,
pub opacity: f64,
/// Desaturate the embedded palette colours by the same amount as the text colour.
pub desaturation: f64,
}
/// Paint `gid` of `face` as a colour glyph, its origin mapped by `at` (y down, points) at `scale`
/// points per font unit. `fg` is the text colour (palette index 0xFFFF) and `alpha` fades it all.
/// points per font unit.
/// False when the glyph has no colour version, so the caller draws the plain outline.
pub fn paint(ctx: &mut RenderContext, face: &FontFace, gid: u32, at: Affine, scale: f64, fg: Rgba, alpha: f64) -> bool {
pub(super) fn paint(ctx: &mut RenderContext, face: &FontFace, gid: u32, at: Affine, scale: f64, colors: Colors) -> bool {
let Some(font) = face.skrifa() else { return false };
let glyphs = font.color_glyphs();
let Some(glyph) = glyphs.get(GlyphId::new(gid)) else { return false };
let palette: Vec<Rgba> = font
let mut palette: Vec<Rgba> = font
.color_palettes()
.get(0)
.map(|p| p.colors().iter().map(|c| Rgba { r: c.red, g: c.green, b: c.blue, a: c.alpha }).collect())
.unwrap_or_default();
if colors.desaturation > 0.0 {
for color in &mut palette {
*color = deckcraft_anim::desaturate_color(*color, colors.desaturation);
}
}
// Font units are y up; the slide is y down.
let base = at * Affine::scale(scale) * Affine::scale_non_uniform(1.0, -1.0);
let mut p = Painter { ctx, face, base, stack: vec![Affine::IDENTITY], palette, fg, opened: Vec::new(), work: 0 };
p.ctx.push_layer(None, None, Some(alpha.clamp(0.0, 1.0) as f32), None, None);
let mut p = Painter { ctx, face, base, stack: vec![Affine::IDENTITY], palette, fg: colors.foreground, opened: Vec::new(), work: 0 };
p.ctx.push_layer(None, None, Some(colors.opacity.clamp(0.0, 1.0) as f32), None, None);
let ok = glyph.paint(face.location(), &mut p).is_ok();
// A malformed glyph may leave layers open: close them all.
while let Some(open) = p.opened.pop() {
+42 -2
View File
@@ -13,13 +13,41 @@ pub struct ShapeState {
pub clip: Option<[f64; 4]>,
/// Colour override for emphasis effects (fill).
pub tint: Option<Rgba>,
/// Fraction by which to reduce the saturation of the text colours.
pub text_desaturation: f64,
/// Per-paragraph states of by-paragraph text builds (paragraph index, state).
pub paras: Vec<(usize, ParaState)>,
}
impl Default for ShapeState {
fn default() -> Self {
ShapeState { visible: true, opacity: 1.0, offset: Vec2::ZERO, scale: (1.0, 1.0), rotate: 0.0, clip: None, tint: None, paras: vec![] }
ShapeState {
visible: true,
opacity: 1.0,
offset: Vec2::ZERO,
scale: (1.0, 1.0),
rotate: 0.0,
clip: None,
tint: None,
text_desaturation: 0.0,
paras: vec![],
}
}
}
impl From<deckcraft_anim::AnimState> for ShapeState {
fn from(state: deckcraft_anim::AnimState) -> Self {
ShapeState {
visible: state.visible,
opacity: state.opacity,
offset: Vec2::new(state.offset_x, state.offset_y),
scale: (state.scale_x, state.scale_y),
rotate: state.rotate,
clip: state.clip,
tint: state.tint,
text_desaturation: state.text_desaturation,
paras: Vec::new(),
}
}
}
@@ -30,11 +58,23 @@ pub struct ParaState {
pub opacity: f64,
/// Translation in shape-local points.
pub offset: Vec2,
pub text_desaturation: f64,
}
impl Default for ParaState {
fn default() -> Self {
ParaState { visible: true, opacity: 1.0, offset: Vec2::ZERO }
ParaState { visible: true, opacity: 1.0, offset: Vec2::ZERO, text_desaturation: 0.0 }
}
}
impl From<deckcraft_anim::AnimState> for ParaState {
fn from(state: deckcraft_anim::AnimState) -> Self {
ParaState {
visible: state.visible,
opacity: state.opacity,
offset: Vec2::new(state.offset_x, state.offset_y),
text_desaturation: state.text_desaturation,
}
}
}
+5 -2
View File
@@ -5,7 +5,9 @@ use super::opts::{RenderOpts, ShapeState, SlideFields};
use super::raster::Image;
use super::slide::{SlidePart, needs_filters, output_size};
use super::stroke::{arrowheads, head_trims, stroke, trim_ends};
use super::text_draw::{draw_layout_with, draw_text, line_bounds, preview_empty_bullets, prompt_body, text_transform, text_warp};
use super::text_draw::{
desaturate_layout, draw_animated_layout, draw_text, line_bounds, preview_empty_bullets, prompt_body, text_transform, text_warp,
};
use super::*;
pub struct Renderer {
@@ -1092,6 +1094,7 @@ impl Renderer {
if editing {
preview_empty_bullets(&mut l);
}
desaturate_layout(&mut l, st, rctx);
let tm = text_transform(m, tr, l.rotation);
for b in l.lines.iter().filter_map(line_bounds) {
// Glyphs reach a little past their carets and line box (italics, swashes).
@@ -1100,7 +1103,7 @@ impl Renderer {
}
match text_warp(rctx, s, tr).filter(|_| l.rotation == 0.0) {
Some(w) => warp::draw(ctx, &l, tr, m, &st.paras, &w),
None => draw_layout_with(ctx, &l, tr, m, &st.paras),
None => draw_animated_layout(ctx, &l, tr, m, &st.paras, st.text_desaturation),
}
} else if f.opts.edit && s.ph.is_some() {
let kind = s.ph_type().unwrap_or(PhType::Body);
+50
View File
@@ -686,6 +686,48 @@ fn text_shape(id: u32, text: &str, x: f64, y: f64) -> Shape {
Shape { id: ShapeId(id), xfrm: Some(Xfrm::new(x, y, 600.0, 120.0)), text_box: true, text: Some(t), ..Default::default() }
}
#[test]
fn desaturate_grays_text_box_runs_without_recoloring_the_fill() {
use deckcraft_model::{AnimClass, Animation};
let mut sh = text_shape(2, "MM", 80.0, 80.0);
let id = sh.id;
let yellow = Rgba::rgb(255, 212, 32);
sh.fill = Some(Fill::solid(ColorRef::rgb(yellow)));
let runs = &mut sh.text.as_mut().unwrap().paragraphs[0].runs;
let mut next = runs[0].clone();
next.text = "M".into();
next.props.fill = Some(Fill::solid(ColorRef::rgb(Rgba::rgb(0, 0, 220))));
runs[0].text = "M".into();
runs[0].props.fill = Some(Fill::solid(ColorRef::rgb(Rgba::rgb(220, 0, 0))));
runs.push(next);
let mut p = deck_with(vec![sh]);
std::sync::Arc::make_mut(&mut p.slides[0]).animations.push(Animation {
shape: id,
class: AnimClass::Emphasis,
effect: "desaturate".into(),
duration_ms: 500,
..Default::default()
});
let timeline = deckcraft_anim::Timeline::new(&p.slides[0], p.slide_size.width, p.slide_size.height);
let at_end = |id| ShapeState::from(timeline.state_at(id, None, 1.0));
let before = render_slide(&p, 0, &RenderOpts::default());
let after = render_slide(&p, 0, &RenderOpts { state: Some(&at_end), ..Default::default() });
assert_eq!(after.pixel(400, 140), before.pixel(400, 140), "text-box fill");
let gray = |ink| {
before
.pixels
.as_chunks::<4>()
.0
.iter()
.zip(after.pixels.as_chunks::<4>().0)
.find_map(|(source, target)| (source[..3] == ink && target[0] == target[1] && target[1] == target[2]).then_some(target[0]))
};
let red = gray([220, 0, 0]).expect("the red glyph is gray");
let blue = gray([0, 0, 220]).expect("the blue glyph is gray");
assert!(red > blue, "the two glyphs keep their relative luminance");
}
#[test]
fn morph_text_tokens_are_words_or_characters() {
let p = Presentation::default();
@@ -1180,6 +1222,14 @@ fn colour_glyphs_paint_their_layers() {
assert!((share - 0.16).abs() < 0.03, "blue share {share}");
// The text-colour glyph is as big as the other square.
assert!((green as f64 / (red + blue) as f64 - 1.0).abs() < 0.1, "green {green} vs {}", red + blue);
let desaturate = |_: ShapeId| ShapeState { text_desaturation: 1.0, ..Default::default() };
let gray = render_slide(&p, 0, &RenderOpts { state: Some(&desaturate), ..Default::default() });
let layers = img.pixels.as_chunks::<4>().0.iter().zip(gray.pixels.as_chunks::<4>().0);
for rgb in [[255, 0, 0], [0, 0, 255], [0, 160, 0]] {
let (before, after) = layers.clone().find(|(px, _)| px[..3] == rgb).expect("the source colour is visible");
assert!(after[0] == after[1] && after[1] == after[2] && after[0] < 255, "the glyph colour {before:?} becomes gray: {after:?}");
}
}
#[test]
+58 -5
View File
@@ -1,5 +1,5 @@
use super::geometry::{blur, color, pre_translate, scale_of};
use super::opts::ParaState;
use super::opts::{ParaState, ShapeState};
use super::{
Affine, Arc, BezPath, Ctx, FontDb, HashMap, Opts, PhType, Rect, RenderContext, Rgba, Shape, TextBody, Vec2, colr, paint, peniko, resolve,
};
@@ -109,8 +109,55 @@ pub fn draw_layout(ctx: &mut RenderContext, l: &deckcraft_text::TextLayout, tr:
draw_layout_with(ctx, l, tr, m, &[]);
}
/// Apply Desaturate after layout, where every run already has its own resolved colours.
pub(crate) fn desaturate_layout(layout: &mut deckcraft_text::TextLayout, state: &ShapeState, ctx: &Ctx) {
use deckcraft_anim::desaturate_color;
if state.text_desaturation <= 0.0 && state.paras.iter().all(|(_, p)| p.text_desaturation <= 0.0) {
return;
}
let amount = |para| {
let extra = state.paras.iter().find(|(i, _)| *i == para).map_or(0.0, |(_, p)| p.text_desaturation);
combined_desaturation(state.text_desaturation, extra)
};
for run in &mut layout.runs {
let amount = amount(run.para);
if amount <= 0.0 {
continue;
}
run.color = desaturate_color(run.color, amount);
if let Some((color, _)) = &mut run.outline {
*color = desaturate_color(*color, amount);
}
if let Some(gradient) = &mut run.gradient {
for stop in &mut Arc::make_mut(gradient).stops {
stop.color = deckcraft_model::ColorRef::rgb(desaturate_color(ctx.color(&stop.color, None), amount));
}
}
}
for deco in layout.decos.iter_mut().filter(|d| !d.behind) {
deco.color = desaturate_color(deco.color, amount(deco.para));
}
}
fn combined_desaturation(shape: f64, paragraph: f64) -> f64 {
shape + (1.0 - shape) * paragraph
}
/// Draw a laid-out text block with per-paragraph animation states.
pub fn draw_layout_with(ctx: &mut RenderContext, l: &deckcraft_text::TextLayout, tr: Rect, m: Affine, paras: &[(usize, ParaState)]) {
draw_animated_layout(ctx, l, tr, m, paras, 0.0);
}
/// The layout already carries animated text colours; pass the same amount to any glyph's own palette.
pub(crate) fn draw_animated_layout(
ctx: &mut RenderContext,
l: &deckcraft_text::TextLayout,
tr: Rect,
m: Affine,
paras: &[(usize, ParaState)],
text_desaturation: f64,
) {
let para = |i: usize| paras.iter().find(|(p, _)| *p == i).map(|(_, s)| *s).unwrap_or_default();
let m = text_transform(m, tr, l.rotation);
let lines_of = LineIndex::new(l);
@@ -144,13 +191,14 @@ pub fn draw_layout_with(ctx: &mut RenderContext, l: &deckcraft_text::TextLayout,
continue;
}
let m = m * Affine::translate(ps.offset);
let desaturation = combined_desaturation(text_desaturation, ps.text_desaturation);
// A gradient fill starts over on every line and spans that line's text (from its top to
// its bottom, from its first to its last character), as in PowerPoint.
let mut grads: Vec<(usize, peniko::Gradient)> = Vec::new();
for (gid, x, y) in &run.glyphs {
let at = m * glyph_place(run, *gid, *x, *y);
let Some(g) = run.gradient.as_ref().filter(|g| !g.stops.is_empty()) else {
draw_glyph(ctx, run, *gid, at, ps.opacity);
draw_glyph_with(ctx, run, *gid, at, ps.opacity, None, desaturation);
continue;
};
let li = lines_of.line_at(run.para, *y);
@@ -161,7 +209,7 @@ pub fn draw_layout_with(ctx: &mut RenderContext, l: &deckcraft_text::TextLayout,
grads.push((li, paint::gradient(&g.shape, stops, bounds, run.alpha * ps.opacity)));
}
let fill = grads.iter().find(|(i, _)| *i == li).map(|(_, g)| (g, Affine::translate((-*x, -*y))));
draw_glyph_with(ctx, run, *gid, at, ps.opacity, fill);
draw_glyph_with(ctx, run, *gid, at, ps.opacity, fill, desaturation);
}
}
for d in l.decos.iter().filter(|d| !d.behind) {
@@ -347,7 +395,7 @@ fn text_effect(ctx: &mut RenderContext, run: &deckcraft_text::GlyphRun, which: T
/// Draw glyph `gid` of `run` with its origin (on the baseline) mapped by `at`, faded by `opacity`.
pub(crate) fn draw_glyph(ctx: &mut RenderContext, run: &deckcraft_text::GlyphRun, gid: u32, at: Affine, opacity: f64) {
draw_glyph_with(ctx, run, gid, at, opacity, None);
draw_glyph_with(ctx, run, gid, at, opacity, None, 0.0);
}
/// [`draw_glyph`], filled with `fill` (a gradient laid out in the text's space, and the map from
@@ -359,6 +407,7 @@ fn draw_glyph_with(
at: Affine,
opacity: f64,
fill: Option<(&peniko::Gradient, Affine)>,
desaturation: f64,
) {
let alpha = run.alpha * opacity;
if (alpha <= 0.0 || run.color.a == 0) && run.outline.is_none() {
@@ -367,7 +416,11 @@ fn draw_glyph_with(
let k = run.size / run.face.upem.max(1.0);
// Colour glyphs (emoji) paint their own colours; an outline (text outline effect) still
// strokes the plain glyph below.
if alpha > 0.0 && run.outline.is_none() && run.face.is_color() && colr::paint(ctx, &run.face, gid, at, k, run.color, alpha) {
if alpha > 0.0
&& run.outline.is_none()
&& run.face.is_color()
&& colr::paint(ctx, &run.face, gid, at, k, colr::Colors { foreground: run.color, opacity: alpha, desaturation })
{
return;
}
let path = glyph(&run.face, gid);
+2 -16
View File
@@ -2,7 +2,6 @@
//! (Animations ▸ Preview, Animation Pane ▸ Play All). The slide show uses the same mapping.
use deckcraft_anim::Timeline;
use deckcraft_geom::Vec2;
use deckcraft_model::ShapeId;
use deckcraft_render::{ParaState, ShapeState};
@@ -13,21 +12,8 @@ pub const HOLD_SECS: f64 = 0.45;
pub fn shape_state(tl: &Timeline, id: ShapeId, step: usize, t: f64) -> ShapeState {
let a = tl.state(id, None, step, t);
ShapeState {
visible: a.visible,
opacity: a.opacity,
offset: Vec2::new(a.offset_x, a.offset_y),
scale: (a.scale_x, a.scale_y),
rotate: a.rotate,
clip: a.clip,
tint: a.tint,
paras: tl
.paragraph_targets(id)
.into_iter()
.map(|p| {
let a = tl.state(id, Some(p), step, t);
(p, ParaState { visible: a.visible, opacity: a.opacity, offset: Vec2::new(a.offset_x, a.offset_y) })
})
.collect(),
paras: tl.paragraph_targets(id).into_iter().map(|p| (p, ParaState::from(tl.state(id, Some(p), step, t)))).collect(),
..ShapeState::from(a)
}
}
+2 -15
View File
@@ -561,21 +561,8 @@ impl Show {
fn state_for(tl: &Timeline, id: ShapeId, step: usize, t: f64, plays: &[TriggerPlay], stamps: &[StepStamp]) -> ShapeState {
let a = tl.state_ordered(id, None, step, t, plays, stamps);
ShapeState {
visible: a.visible,
opacity: a.opacity,
offset: deckcraft_geom::Vec2::new(a.offset_x, a.offset_y),
scale: (a.scale_x, a.scale_y),
rotate: a.rotate,
clip: a.clip,
tint: a.tint,
paras: tl
.paragraph_targets(id)
.into_iter()
.map(|p| {
let a = tl.state(id, Some(p), step, t);
(p, ParaState { visible: a.visible, opacity: a.opacity, offset: deckcraft_geom::Vec2::new(a.offset_x, a.offset_y) })
})
.collect(),
paras: tl.paragraph_targets(id).into_iter().map(|p| (p, ParaState::from(tl.state_ordered(id, Some(p), step, t, plays, stamps)))).collect(),
..ShapeState::from(a)
}
}
+31 -1
View File
@@ -12,7 +12,7 @@ use crate::test_harness::{harness, harness_with};
use crate::{Services, SlideApp};
use craft::behavior::kurbo::{Point, Size};
use craft::behavior::{Cursor, CursorIcon, PaintedCursor};
use deckcraft_anim::{ShowAction, ShowState};
use deckcraft_anim::{ShowAction, ShowState, StepStamp, Timeline, TriggerPlay};
use deckcraft_model::{Presentation, ShapeId};
use egui::{Pos2, Rect, pos2, vec2};
use serde_json::json;
@@ -625,6 +625,36 @@ fn animations_start_after_the_slides_transition() {
assert_eq!(show.clock_snapshot().step_start, 10.0);
}
#[test]
fn paragraph_animations_follow_the_order_their_triggers_were_clicked() {
use deckcraft_model::{AnimClass, Animation, Shape, Slide, TextBody};
let text = ShapeId(1);
let reveal = ShapeId(2);
let hide = ShapeId(3);
let effect = |class, trigger| Animation { shape: text, paragraph: Some(0), class, trigger: Some(trigger), ..Default::default() };
let slide = Slide {
shapes: vec![
Shape { id: text, text: Some(TextBody::from_text("A paragraph")), ..Default::default() },
Shape { id: reveal, ..Default::default() },
Shape { id: hide, ..Default::default() },
],
animations: vec![effect(AnimClass::Entrance, reveal), effect(AnimClass::Exit, hide)],
..Default::default()
};
let tl = Timeline::new(&slide, 960.0, 540.0);
let visible = |plays: &[TriggerPlay], stamps: &[StepStamp]| {
state_for(&tl, text, 0, 0.0, plays, stamps).paras.iter().find(|(paragraph, _)| *paragraph == 0).unwrap().1.visible
};
let plays = [reveal, hide].map(|trigger| TriggerPlay { trigger, step: 1, t: 0.0 });
let clicked = |first, second| [StepStamp { trigger: first, step: 0, at: 1 }, StepStamp { trigger: second, step: 0, at: 2 }];
assert!(!visible(&[], &[]), "the paragraph waits for its entrance trigger");
assert!(visible(&plays[..1], &[]), "the entrance trigger reveals the paragraph");
assert!(!visible(&plays, &clicked(reveal, hide)), "the later exit hides the paragraph");
assert!(visible(&plays, &clicked(hide, reveal)), "the later entrance reveals the paragraph again");
}
#[test]
fn a_slow_first_frame_does_not_use_up_the_transition() {
// #1385: the clock started at the key press, so rendering the new slide for longer than the