mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-03 22:41:09 +00:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c405f4005f | ||
|
|
076a95b713 | ||
|
|
577ada30b4 | ||
|
|
75c29c27db | ||
|
|
e7b67fb029 | ||
|
|
6c068ffc30 | ||
|
|
7a51671ebd | ||
|
|
d5741616c1 | ||
|
|
877e6db673 | ||
|
|
b697455ea7 | ||
|
|
5c179822d9 |
Generated
+1
@@ -2469,6 +2469,7 @@ name = "deckcraft-engine"
|
||||
version = "0.20.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-metafile",
|
||||
"craft-mime",
|
||||
"deckcraft-anim",
|
||||
"deckcraft-color",
|
||||
|
||||
@@ -40,7 +40,7 @@ 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};
|
||||
pub use path::{MotionPath, default_path};
|
||||
pub use show::{LinkJump, ShowAction, ShowState, safe_url, show_order};
|
||||
pub use show::{LinkJump, ShowAction, ShowState, looping, safe_url, show_order};
|
||||
pub use timeline::{EffectTiming, Sequence, StepStamp, Timeline, TriggerPlay};
|
||||
pub use transition::{DEFAULT_ASPECT, Layer, Source, transition_frame, transition_layers, uses_slide_parts};
|
||||
|
||||
|
||||
+45
-10
@@ -117,7 +117,7 @@ fn custom_indices(pres: &Presentation, name: &str) -> Option<Vec<usize>> {
|
||||
if order.is_empty() { None } else { Some(order) }
|
||||
}
|
||||
|
||||
fn looping(pres: &Presentation) -> bool {
|
||||
pub fn looping(pres: &Presentation) -> bool {
|
||||
pres.show.loop_until_esc || pres.show.show_type == "kiosk"
|
||||
}
|
||||
|
||||
@@ -236,19 +236,54 @@ impl ShowState {
|
||||
}
|
||||
|
||||
fn next_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
let order = self.visit(pres);
|
||||
match order.iter().position(|&i| i == self.slide) {
|
||||
Some(p) => order.get(p + 1).copied(),
|
||||
None => order.iter().copied().find(|&i| i > self.slide),
|
||||
}
|
||||
self.visible_step(pres, self.slide, true, 1)
|
||||
}
|
||||
|
||||
fn prev_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
let order = self.visit(pres);
|
||||
match order.iter().position(|&i| i == self.slide) {
|
||||
Some(p) => p.checked_sub(1).and_then(|q| order.get(q).copied()),
|
||||
None => order.iter().copied().rev().find(|&i| i < self.slide),
|
||||
self.visible_step(pres, self.slide, false, 1)
|
||||
}
|
||||
|
||||
/// Show the end screen without advancing a step (the pointer wheel past the last visible
|
||||
/// slide). A later forward input leaves the show through the end screen's own handling.
|
||||
pub fn end(&mut self) {
|
||||
self.ended = true;
|
||||
self.playing = false;
|
||||
}
|
||||
|
||||
/// `steps` slides after (`forward`) or before `from` in this show's visible order (the custom
|
||||
/// show or range, hidden slides skipped), without entering them; `None` when the order ends
|
||||
/// first. The pointer wheel turns slides through this, so it skips hidden slides as ←/→ do.
|
||||
pub fn visible_step(&self, pres: &Presentation, from: usize, forward: bool, steps: usize) -> Option<usize> {
|
||||
self.visible_step_in(pres, from, forward, steps, false)
|
||||
}
|
||||
|
||||
/// Like [`Self::visible_step`], but stops at the first/last visible slide instead of running
|
||||
/// past it: one fast wheel gesture lands on the end slide rather than leaving the order.
|
||||
pub fn visible_step_clamped(&self, pres: &Presentation, from: usize, forward: bool, steps: usize) -> Option<usize> {
|
||||
self.visible_step_in(pres, from, forward, steps, true)
|
||||
}
|
||||
|
||||
fn visible_step_in(&self, pres: &Presentation, from: usize, forward: bool, steps: usize, clamp: bool) -> Option<usize> {
|
||||
if steps == 0 {
|
||||
return None;
|
||||
}
|
||||
let order = self.visit(pres);
|
||||
// A `from` that is not in the order (a hidden slide opened by number) reaches the
|
||||
// nearest visible slide in the direction, which counts as the first step.
|
||||
let (start, used) = match order.iter().position(|&i| i == from) {
|
||||
Some(p) => (p, 0),
|
||||
None if forward => (order.iter().position(|&i| i > from)?, 1),
|
||||
None => (order.iter().rposition(|&i| i < from)?, 1),
|
||||
};
|
||||
let rest = steps.saturating_sub(used);
|
||||
let q = if forward {
|
||||
if clamp { start.saturating_add(rest).min(order.len().checked_sub(1)?) } else { start.checked_add(rest)? }
|
||||
} else if clamp {
|
||||
start.saturating_sub(rest)
|
||||
} else {
|
||||
start.checked_sub(rest)?
|
||||
};
|
||||
order.get(q).copied()
|
||||
}
|
||||
|
||||
/// Click / → / Space: finish the playing step, else play the next step, else go to the next slide.
|
||||
|
||||
@@ -763,6 +763,21 @@ fn show_skips_hidden_slides() {
|
||||
assert_eq!(s.goto(&p, 99), ShowAction::None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_step_from_a_hidden_slide_counts_its_first_visible_neighbour() {
|
||||
// A hidden slide opened by number is not in the show order; the nearest visible slide in the
|
||||
// direction is the first step, and the rest of the notches still apply.
|
||||
let mut p = pres(5);
|
||||
Arc::make_mut(&mut p.slides[1]).hidden = true;
|
||||
let s = ShowState::new(&p);
|
||||
assert_eq!(s.visible_step_clamped(&p, 1, true, 2), Some(3));
|
||||
assert_eq!(s.visible_step_clamped(&p, 1, false, 2), Some(0));
|
||||
assert_eq!(s.visible_step(&p, 1, true, 2), Some(3));
|
||||
// Clamped steps stop at the ends of the visible order.
|
||||
assert_eq!(s.visible_step_clamped(&p, 4, true, 3), Some(4));
|
||||
assert_eq!(s.visible_step_clamped(&p, 0, false, 3), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_remembers_a_slide_was_reached_by_going_back() {
|
||||
// #1531: the UI plays the left slide's transition reversed only for Back.
|
||||
|
||||
@@ -10,6 +10,8 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-mime = { workspace = true }
|
||||
# Tells EMF from WMF when a picture is inserted (#2392).
|
||||
craft-metafile = { workspace = true }
|
||||
deckcraft-geom = { workspace = true }
|
||||
deckcraft-color = { workspace = true }
|
||||
deckcraft-model = { workspace = true }
|
||||
@@ -32,6 +34,7 @@ chrono = { workspace = true }
|
||||
[dev-dependencies]
|
||||
deckcraft-anim = { workspace = true }
|
||||
zip = { workspace = true }
|
||||
craft-metafile = { workspace = true, features = ["write"] }
|
||||
|
||||
# The browser clock for comment timestamps (wasm has no std::time::SystemTime).
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
||||
@@ -33,6 +33,12 @@ pub fn content_type(name: &str, bytes: &[u8]) -> &'static str {
|
||||
"image/bmp"
|
||||
} else if bytes.starts_with(b"II*\0") || bytes.starts_with(b"MM\0*") {
|
||||
"image/tiff"
|
||||
} else if let Some(kind) = craft_metafile::sniff(bytes) {
|
||||
// The MIME types the PPTX writer saves as `.emf` / `.wmf` parts (#2392).
|
||||
match kind {
|
||||
craft_metafile::Kind::Emf => "image/x-emf",
|
||||
craft_metafile::Kind::Wmf => "image/x-wmf",
|
||||
}
|
||||
} else if bytes.starts_with(b"fLaC") {
|
||||
"audio/flac"
|
||||
} else if bytes.starts_with(b"OggS") {
|
||||
|
||||
@@ -689,24 +689,13 @@ fn section_remove(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let sec = doc.sections.remove(i);
|
||||
if with_slides {
|
||||
let current = doc.slides.get(sel.slide).map(|x| x.id);
|
||||
let first = sec.slides.iter().filter_map(|id| doc.slide_index(*id)).min().unwrap_or(0);
|
||||
doc.slides.retain(|x| !sec.slides.contains(&x.id));
|
||||
// As in slide.delete: the deleted slides leave every custom show and the selection.
|
||||
for show in &mut doc.custom_shows {
|
||||
show.slides.retain(|x| !sec.slides.contains(x));
|
||||
}
|
||||
sel.slides.retain(|x| !sec.slides.contains(x));
|
||||
// The current slide keeps its place by id. When it was deleted, the slide that takes its
|
||||
// place becomes current and the selection, as after slide.delete.
|
||||
if let Some(at) = current.and_then(|id| doc.slide_index(id)) {
|
||||
sel.slide = at;
|
||||
} else {
|
||||
sel.slide = first.min(doc.slides.len().saturating_sub(1));
|
||||
sel.slides = doc.slides.get(sel.slide).map(|x| vec![x.id]).unwrap_or_default();
|
||||
sel.shapes.clear();
|
||||
sel.text = None;
|
||||
}
|
||||
sel.slide = sel.slide.min(doc.slides.len().saturating_sub(1));
|
||||
} else if let Some(prev) = i.checked_sub(1).and_then(|k| doc.sections.get_mut(k)) {
|
||||
prev.slides.extend(sec.slides);
|
||||
} else if let Some(next) = doc.sections.get_mut(0) {
|
||||
@@ -998,33 +987,6 @@ mod tests {
|
||||
assert_eq!(selected(&s), (0, vec![ids[2]]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_an_earlier_section_with_its_slides_keeps_the_current_slide() {
|
||||
let (mut s, ids) = deck(5);
|
||||
s.execute("section.add", &json!({"name": "First", "at": 0})).expect("First");
|
||||
s.execute("section.add", &json!({"name": "Second", "at": 2})).expect("Second");
|
||||
s.execute("slide.selectSlides", &json!({"ids": [ids[2]]})).expect("select C");
|
||||
|
||||
s.execute("section.remove", &json!({"index": 0, "slides": true})).expect("remove First and its slides");
|
||||
let (cur, sel) = selected(&s);
|
||||
assert_eq!(order(&s).get(cur), Some(&ids[2]), "C stays the current slide after the slides before it go");
|
||||
assert_eq!(sel, [ids[2]], "the selection still names C");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_the_current_slides_section_moves_the_selection_to_the_new_current_slide() {
|
||||
let (mut s, ids) = deck(5);
|
||||
s.execute("section.add", &json!({"name": "First", "at": 0})).expect("First");
|
||||
s.execute("section.add", &json!({"name": "Second", "at": 2})).expect("Second");
|
||||
s.execute("slide.selectSlides", &json!({"ids": [ids[3]]})).expect("select D");
|
||||
|
||||
s.execute("section.remove", &json!({"index": 1, "slides": true})).expect("remove Second and its slides");
|
||||
assert_eq!(order(&s), [ids[0], ids[1]]);
|
||||
let (cur, sel) = selected(&s);
|
||||
let current = *order(&s).get(cur).expect("a current slide");
|
||||
assert_eq!(sel, [current], "as after slide.delete, the selection names the new current slide");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removing_a_section_with_its_slides_prunes_them_from_custom_shows() {
|
||||
let (mut s, ids) = deck(4);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
//! Standalone EMF and WMF files inserted as pictures (#2392).
|
||||
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
use craft_metafile::write::{Op, emf, wmf};
|
||||
use deckcraft_engine::Session;
|
||||
use deckcraft_engine::cmd::base64_encode;
|
||||
use deckcraft_geom::{KurboShape as _, Rect};
|
||||
use deckcraft_model::{ShapeId, ShapeKind};
|
||||
use serde_json::json;
|
||||
|
||||
/// Two solid rectangles, red at the top left and blue at the bottom right, on a 200 x 100 pt
|
||||
/// picture.
|
||||
fn two_rects() -> (Vec<Op>, Rect) {
|
||||
let fill = |r: Rect, rgb: [u8; 3]| Op::Fill { path: r.to_path(0.1), even_odd: false, rgb };
|
||||
(
|
||||
vec![fill(Rect::new(0.0, 0.0, 100.0, 50.0), [0xC7, 0x30, 0x40]), fill(Rect::new(100.0, 50.0, 200.0, 100.0), [0x20, 0x70, 0xD0])],
|
||||
Rect::new(0.0, 0.0, 200.0, 100.0),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standalone_emf_and_wmf_files_insert_as_pictures_and_save_as_metafile_parts() {
|
||||
let (ops, region) = two_rects();
|
||||
let emf = emf(&ops, region, "DeckCraft", "two rects").expect("EMF");
|
||||
let wmf = wmf(&ops, region).expect("WMF").bytes;
|
||||
for (name, bytes, ext) in [("source.emf", emf, "emf"), ("source.wmf", wmf, "wmf")] {
|
||||
let mut s = Session::with_new();
|
||||
let rect = [200.0, 120.0, 480.0, 270.0];
|
||||
let r = s.execute("insert.picture", &json!({"data": base64_encode(&bytes), "name": name, "rect": rect})).expect(name);
|
||||
let id = ShapeId(r["id"].as_u64().expect("id") as u32);
|
||||
let doc = &s.doc().expect("doc").doc;
|
||||
let sh = doc.slides.iter().flat_map(|sl| &sl.shapes).find(|sh| sh.id == id).expect("inserted shape");
|
||||
let ShapeKind::Picture { fill } = &sh.kind else { panic!("{name} is a picture: {:?}", sh.kind) };
|
||||
let x = sh.xfrm.expect("xfrm");
|
||||
assert_eq!([x.x, x.y, x.w, x.h], rect, "{name} sits at the requested bounds");
|
||||
assert_eq!(doc.media(fill.media).expect("media").data.as_slice(), bytes.as_slice(), "{name} is embedded as given");
|
||||
|
||||
// Saved as a metafile part, and read back as the same picture.
|
||||
let pptx = deckcraft_pptx::export(doc).expect("export");
|
||||
let mut z = zip::ZipArchive::new(Cursor::new(&pptx)).expect("zip");
|
||||
let part = z.file_names().find(|n| n.starts_with("ppt/media/") && n.ends_with(&format!(".{ext}"))).map(str::to_string);
|
||||
let part = part.unwrap_or_else(|| panic!("{name} is saved as a .{ext} part: {:?}", z.file_names().collect::<Vec<_>>()));
|
||||
let mut saved = Vec::new();
|
||||
z.by_name(&part).expect("part").read_to_end(&mut saved).expect("read");
|
||||
assert_eq!(saved, bytes, "{part} holds the file's bytes");
|
||||
let back = deckcraft_pptx::import(&pptx).expect("import");
|
||||
let reopened = back
|
||||
.slides
|
||||
.iter()
|
||||
.flat_map(|sl| &sl.shapes)
|
||||
.find(|sh| matches!(&sh.kind, ShapeKind::Picture { fill } if back.media(fill.media).is_some_and(|m| *m.data == bytes)));
|
||||
let reopened = reopened.unwrap_or_else(|| panic!("{name} reopens as a picture"));
|
||||
let x = reopened.xfrm.expect("reopened xfrm");
|
||||
let near = |a: f64, b: f64| (a - b).abs() < 0.01;
|
||||
assert!(
|
||||
near(x.x, rect[0]) && near(x.y, rect[1]) && near(x.w, rect[2]) && near(x.h, rect[3]),
|
||||
"{name} reopens at the requested bounds: {:?}",
|
||||
[x.x, x.y, x.w, x.h]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
mod chart_native;
|
||||
mod insert_metafile;
|
||||
mod show_clicks;
|
||||
|
||||
+39
-15
@@ -376,18 +376,15 @@ Then wave"
|
||||
);
|
||||
}
|
||||
|
||||
/// Text with very many formatting runs is laid into runs in about linear time. Each lookup used to
|
||||
/// scan the run starts from the beginning, so the cost grew with runs²: in a debug build these 640k
|
||||
/// one-character runs (about 6 MB of file) took 75 s that way, and take about 2 s with binary search.
|
||||
#[test]
|
||||
fn many_character_runs_are_not_quadratic() {
|
||||
const N: usize = 640_000;
|
||||
let text: String = (0..N).map(|i| if i % 2 == 0 { 'a' } else { '\u{0B}' }).collect();
|
||||
/// A text box holding `n` one-character formatting runs (a character and a line break, alternating),
|
||||
/// as a legacy .ppt file.
|
||||
fn file_with_character_runs(n: usize) -> Vec<u8> {
|
||||
let text: String = (0..n).map(|i| if i % 2 == 0 { 'a' } else { '\u{0B}' }).collect();
|
||||
let mut style = vec![];
|
||||
style.extend_from_slice(&(N as u32 + 1).to_le_bytes());
|
||||
style.extend_from_slice(&(n as u32 + 1).to_le_bytes());
|
||||
style.extend_from_slice(&0u16.to_le_bytes());
|
||||
style.extend_from_slice(&0u32.to_le_bytes()); // a paragraph exception with no fields
|
||||
for _ in 0..=N {
|
||||
for _ in 0..=n {
|
||||
style.extend_from_slice(&1u32.to_le_bytes());
|
||||
style.extend_from_slice(&0u32.to_le_bytes()); // a character exception with no fields
|
||||
}
|
||||
@@ -398,12 +395,39 @@ fn many_character_runs_are_not_quadratic() {
|
||||
);
|
||||
let slide = container(rt::SLIDE, 0, &[slide_atom(1, MASTER_ID, 0x7), drawing(None, &[shape])]);
|
||||
let (cu, doc, pics) = streams_of(0xE391_C05F, 1, slide, None);
|
||||
let bytes = crate::cfb::build(&[("Current User", &cu), ("PowerPoint Document", &doc), ("Pictures", &pics)]);
|
||||
let t = std::time::Instant::now();
|
||||
let p = crate::import(&bytes).unwrap();
|
||||
assert!(t.elapsed() < std::time::Duration::from_secs(20), "{:?}", t.elapsed());
|
||||
let runs = &p.slides[0].shapes[0].text.as_ref().unwrap().paragraphs[0].runs;
|
||||
assert_eq!(runs.iter().filter(|r| r.kind == RunKind::Break).count(), N / 2);
|
||||
crate::cfb::build(&[("Current User", &cu), ("PowerPoint Document", &doc), ("Pictures", &pics)])
|
||||
}
|
||||
|
||||
/// Text with very many formatting runs is laid into runs in about linear time. Each lookup used to
|
||||
/// scan the run starts from the beginning, so the cost grew with runs²: 640k one-character runs
|
||||
/// (about 6 MB of file) took 75 s that way in a debug build, and about 2 s with binary search.
|
||||
///
|
||||
/// The test compares two sizes in the same process instead of timing one against a fixed limit, so
|
||||
/// a slow or busy host (the FreeBSD CI VM took 20 to 31 s for the 640k file, mostly in the kernel,
|
||||
/// where a quiet one takes 2 s) slows both alike. Four times the runs take about four times as long
|
||||
/// when the work is linear and sixteen times as long when it is quadratic. Each size is the best of
|
||||
/// three imports, so a stall in one of them doesn't decide the result.
|
||||
#[test]
|
||||
fn many_character_runs_are_not_quadratic() {
|
||||
const SMALL: usize = 40_000;
|
||||
const LARGE: usize = 4 * SMALL;
|
||||
let best_of_three = |n: usize| {
|
||||
let bytes = file_with_character_runs(n);
|
||||
let mut best = std::time::Duration::MAX;
|
||||
let mut breaks = 0;
|
||||
for _ in 0..3 {
|
||||
let t = std::time::Instant::now();
|
||||
let p = crate::import(&bytes).unwrap();
|
||||
best = best.min(t.elapsed());
|
||||
let runs = &p.slides[0].shapes[0].text.as_ref().unwrap().paragraphs[0].runs;
|
||||
breaks = runs.iter().filter(|r| r.kind == RunKind::Break).count();
|
||||
}
|
||||
(best, breaks)
|
||||
};
|
||||
let (small, small_breaks) = best_of_three(SMALL);
|
||||
let (large, large_breaks) = best_of_three(LARGE);
|
||||
assert_eq!((small_breaks, large_breaks), (SMALL / 2, LARGE / 2));
|
||||
assert!(large < small * 10, "{LARGE} runs took {large:?}, {SMALL} runs took {small:?}: more than 10x for 4x the runs");
|
||||
}
|
||||
|
||||
/// A slide naming a master that doesn't exist falls back to the first main master, every time. The
|
||||
|
||||
@@ -82,6 +82,11 @@ pub struct Show {
|
||||
notes_px: f32,
|
||||
timings: Vec<(usize, f64)>,
|
||||
last_move: f64,
|
||||
/// Leftover fraction of a discrete wheel line. High-resolution and free-spin wheels send
|
||||
/// fractions of a line, so the delta accumulates here and each whole line is one slide.
|
||||
wheel_carry: f32,
|
||||
/// A discrete wheel line was handled this frame, so the canvas tool must not turn the page too.
|
||||
wheel_taken: bool,
|
||||
pub ended: bool,
|
||||
/// The slide whose media was last started (auto-play runs once per visit).
|
||||
media_slide: Option<usize>,
|
||||
@@ -125,7 +130,16 @@ pub(crate) struct BackKey {
|
||||
struct Transition {
|
||||
/// The slide left behind, whose shapes Morph matches.
|
||||
from: Option<usize>,
|
||||
/// The time of the key press. A hidden show, which draws nothing, expires the transition
|
||||
/// from it.
|
||||
start: f64,
|
||||
/// Where the drawn transition's clock starts: the frame after the first one (see `progress`),
|
||||
/// because rendering the new slide and the transition's pictures can take longer than the
|
||||
/// whole transition (#1385). `None` until then.
|
||||
clock: Option<f64>,
|
||||
/// The first frame of the transition has been drawn: the new slide and the pictures the
|
||||
/// transition needs exist, so the time they took is not part of the transition.
|
||||
primed: bool,
|
||||
kind: String,
|
||||
option: String,
|
||||
dur: f64,
|
||||
@@ -134,6 +148,20 @@ struct Transition {
|
||||
reverse: bool,
|
||||
}
|
||||
|
||||
impl Transition {
|
||||
/// How far the transition has come at frame time `now`, from 0 to 1. The first frame is the
|
||||
/// one that renders the new slide and the transition's pictures and the second one starts the
|
||||
/// clock, so a slow render never eats the transition's duration (#1385).
|
||||
fn progress(&mut self, now: f64) -> f64 {
|
||||
if !self.primed {
|
||||
self.primed = true;
|
||||
return 0.0;
|
||||
}
|
||||
let clock = *self.clock.get_or_insert(now);
|
||||
((now - clock) / self.dur.max(0.01)).clamp(0.0, 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// A copy of the show's clock origins for regressions that must not depend on wall time.
|
||||
#[cfg(test)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -209,6 +237,8 @@ impl Show {
|
||||
notes_px: NOTES_DEFAULT,
|
||||
timings: vec![],
|
||||
last_move: 0.0,
|
||||
wheel_carry: 0.0,
|
||||
wheel_taken: false,
|
||||
ended: false,
|
||||
media_slide: None,
|
||||
last_viewed: None,
|
||||
@@ -230,7 +260,7 @@ impl Show {
|
||||
.map(|t| (t.kind.clone(), t.option.clone(), t.duration_ms as f64 / 1000.0))
|
||||
.unwrap_or(("none".into(), String::new(), 0.0));
|
||||
self.trans = if kind != "none" && dur > 0.0 && !doc.show.without_animation {
|
||||
Some(Transition { from, start: now, kind, option, dur, reverse: false })
|
||||
Some(Transition { from, start: now, clock: None, primed: false, kind, option, dur, reverse: false })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -443,7 +473,7 @@ impl Show {
|
||||
// reversed Morph.
|
||||
let reverse = back && kind != "morph";
|
||||
self.trans = if kind != "none" && dur > 0.0 && !doc.show.without_animation {
|
||||
Some(Transition { from, start: now, kind, option, dur, reverse })
|
||||
Some(Transition { from, start: now, clock: None, primed: false, kind, option, dur, reverse })
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -493,8 +493,8 @@ fn prepare_transition(
|
||||
store: &TextureStore<FrameKey>,
|
||||
frame: &mut PaintFrame,
|
||||
) {
|
||||
let Some(tr) = &show.trans else { return };
|
||||
let p = ((now - tr.start) / tr.dur.max(0.01)).clamp(0.0, 1.0);
|
||||
let Some(tr) = &mut show.trans else { return };
|
||||
let p = tr.progress(now);
|
||||
if p >= 1.0 {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -625,6 +625,29 @@ fn animations_start_after_the_slides_transition() {
|
||||
assert_eq!(show.clock_snapshot().step_start, 10.0);
|
||||
}
|
||||
|
||||
#[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
|
||||
// transition's duration showed the next slide with no transition at all.
|
||||
let mut s = deckcraft_engine::Session::with_new();
|
||||
s.execute("slide.new", &json!({})).unwrap();
|
||||
s.execute("transition.set", &json!({"kind": "fade", "index": 1, "duration": 500})).unwrap();
|
||||
let doc = s.active().unwrap().doc.clone();
|
||||
let mut show = Show::new(&doc, 0, false, false);
|
||||
assert!(show.apply(ShowAction::Slide(1), &doc, 10.0));
|
||||
let tr = show.trans.as_mut().expect("the fade plays");
|
||||
assert!((tr.dur - 0.5).abs() < 1e-9);
|
||||
// The first frame renders for two seconds; it still shows the start of the transition.
|
||||
assert_eq!(tr.progress(10.0), 0.0);
|
||||
// The frame after it starts the clock.
|
||||
assert_eq!(tr.progress(12.0), 0.0);
|
||||
assert!((tr.progress(12.25) - 0.5).abs() < 1e-9);
|
||||
assert_eq!(tr.progress(12.5), 1.0);
|
||||
assert_eq!(tr.progress(20.0), 1.0);
|
||||
// A hidden show still expires it from the key press.
|
||||
assert_eq!(tr.start, 10.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn going_back_plays_the_left_slides_transition_reversed() {
|
||||
// #1531: Back plays the transition of the slide being left, in reverse.
|
||||
@@ -752,9 +775,18 @@ fn a_first_animation_after_or_with_previous_plays_when_the_slide_appears() {
|
||||
|
||||
/// A running show on the first of three slides, with presenter view off.
|
||||
fn show_of_three() -> egui_kittest::Harness<'static, SlideApp> {
|
||||
show_of_with_hidden(3, &[])
|
||||
}
|
||||
|
||||
/// A running show on the first of `slides`, with `hidden` slides hidden.
|
||||
fn show_of_with_hidden(slides: usize, hidden: &[usize]) -> egui_kittest::Harness<'static, SlideApp> {
|
||||
let mut session = deckcraft_engine::Session::with_new();
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
for _ in 1..slides {
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
}
|
||||
for &i in hidden {
|
||||
session.execute("slide.hide", &json!({"index": i, "hidden": true})).unwrap();
|
||||
}
|
||||
let mut harness =
|
||||
harness_with(session, Services::default(), egui_kittest::Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(1.0 / 60.0), |_| {});
|
||||
harness.state_mut().ui.presenter_view = false;
|
||||
@@ -801,10 +833,184 @@ fn ctrl_wheel_zooms_the_show_and_the_plain_wheel_turns_the_page() {
|
||||
assert!((show.view.zoom - fit).abs() < fit * 1e-3);
|
||||
|
||||
show_wheel(&mut h, centre, -3.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "the plain wheel turns the page");
|
||||
// #1724: a -3.0 wheel event is three lines, so three slides (clamped to the last of three).
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2, "the plain wheel turns the page");
|
||||
}
|
||||
}
|
||||
|
||||
/// #1724: two discrete wheel notches inside the trackpad's old 0.35 s cooldown turn two slides.
|
||||
/// One notch is one slide; the second notch must not be dropped by a gesture gate.
|
||||
#[test]
|
||||
fn two_wheel_notches_inside_the_trackpad_cooldown_turn_two_slides() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
let notch = |harness: &mut egui_kittest::Harness<'static, SlideApp>, steps: usize| {
|
||||
harness.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
harness.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, -1.0),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
harness.run_steps(steps);
|
||||
};
|
||||
notch(&mut h, 4);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "one notch turns one slide");
|
||||
notch(&mut h, 4);
|
||||
assert_eq!(
|
||||
h.state().show.as_ref().expect("still showing").state.slide,
|
||||
2,
|
||||
"a second notch inside the old trackpad cooldown still turns the next slide"
|
||||
);
|
||||
}
|
||||
|
||||
/// #1724: on the end screen a discrete wheel notch keeps the old semantics: forward exits
|
||||
/// the show, back resumes the last slide instead of jumping.
|
||||
#[test]
|
||||
fn wheel_on_the_end_screen_exits_forward_and_resumes_back() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
let line = |harness: &mut egui_kittest::Harness<'static, SlideApp>, y: f32| {
|
||||
harness.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
harness.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, y),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
harness.run_steps(4);
|
||||
};
|
||||
line(&mut h, -1.0);
|
||||
line(&mut h, -1.0);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "past the last slide: the end screen");
|
||||
// Back resumes the last slide instead of jumping to the one before it.
|
||||
line(&mut h, 1.0);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "a backward notch leaves the end screen");
|
||||
assert_eq!(show.state.slide, 2, "it resumes the last slide");
|
||||
// Forward past the end again, then a forward notch exits.
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended);
|
||||
line(&mut h, -1.0);
|
||||
assert!(h.state().show.is_none(), "a forward notch on the end screen exits the show");
|
||||
}
|
||||
|
||||
/// Backward from an end screen reached on a hidden tail resumes the last visible slide, not the
|
||||
/// hidden slide the show was left on.
|
||||
#[test]
|
||||
fn wheel_back_on_an_end_screen_from_a_hidden_tail_resumes_the_last_visible_slide() {
|
||||
let mut h = show_of_with_hidden(4, &[3]);
|
||||
let doc = h.state().session.active().unwrap().doc.clone();
|
||||
h.state_mut().show.as_mut().unwrap().state.goto(&doc, 3);
|
||||
h.run_steps(2);
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "the hidden tail has no forward slide");
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), 1.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "a backward notch leaves the end screen");
|
||||
assert_eq!(show.state.slide, 2, "it resumes the last visible slide, not the hidden one");
|
||||
}
|
||||
|
||||
/// A looping show wraps a forward wheel notch from the last visible slide to the first instead
|
||||
/// of entering the end screen.
|
||||
#[test]
|
||||
fn wheel_forward_on_the_last_slide_wraps_in_a_looping_show() {
|
||||
let mut h = show_of_three();
|
||||
let st = h.state_mut().session.active_mut().unwrap();
|
||||
std::sync::Arc::make_mut(&mut st.doc).show.loop_until_esc = true;
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "the looping show does not end");
|
||||
assert_eq!(show.state.slide, 0, "it wraps to the first visible slide");
|
||||
}
|
||||
|
||||
/// The wheel turns slides through the show's visible order, so a hidden slide is skipped as
|
||||
/// ←/→ skip it instead of opening it through `ShowState::goto`.
|
||||
#[test]
|
||||
fn a_wheel_notch_skips_a_hidden_slide() {
|
||||
let mut h = show_of_with_hidden(3, &[1]);
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2, "the hidden middle slide is skipped");
|
||||
show_wheel(&mut h, centre, 1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 0, "back also skips it");
|
||||
}
|
||||
|
||||
/// Two notches in one frame are applied in the order they arrived: a backward then a forward
|
||||
/// notch at the first slide still moves forward (a signed net would cancel them out).
|
||||
#[test]
|
||||
fn a_backward_then_forward_notch_in_one_frame_still_moves_forward() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
h.input_mut().events.push(egui::Event::PointerMoved(centre));
|
||||
for y in [1.0_f32, -1.0] {
|
||||
h.input_mut().events.push(egui::Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Line,
|
||||
delta: vec2(0.0, y),
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
});
|
||||
}
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "the forward notch still moves one slide");
|
||||
}
|
||||
|
||||
/// A backward notch with two lines on the end screen resumes the last slide and still steps one
|
||||
/// more back, matching the per-line contract of the ordinary-slide path.
|
||||
#[test]
|
||||
fn two_backward_lines_on_the_end_screen_reach_the_penultimate_slide() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "at the end screen");
|
||||
show_wheel(&mut h, centre, 2.0, egui::Modifiers::NONE);
|
||||
let show = h.state().show.as_ref().expect("still showing");
|
||||
assert!(!show.ended, "two backward lines leave the end screen");
|
||||
assert_eq!(show.state.slide, 1, "the last slide then one more back");
|
||||
}
|
||||
|
||||
/// A hidden slide after the last visible one has no forward neighbour; a notch there still shows
|
||||
/// the end screen instead of doing nothing.
|
||||
#[test]
|
||||
fn a_forward_notch_on_a_hidden_slide_after_the_last_visible_ones_ends_the_show() {
|
||||
let mut h = show_of_with_hidden(4, &[3]);
|
||||
let doc = h.state().session.active().unwrap().doc.clone();
|
||||
h.state_mut().show.as_mut().unwrap().state.goto(&doc, 3);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 3);
|
||||
show_wheel(&mut h, pos2(500.0, 350.0), -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "no visible slide ahead: the end screen");
|
||||
}
|
||||
|
||||
/// A completed forward wheel notch past the last slide reaches the end screen and then exits,
|
||||
/// the same way a trackpad flick does; a partial line still does nothing.
|
||||
#[test]
|
||||
fn a_forward_wheel_notch_past_the_last_slide_reaches_the_end_screen() {
|
||||
let mut h = show_of_three();
|
||||
let centre = pos2(500.0, 350.0);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 2);
|
||||
// A partial line on the last slide does not end the show.
|
||||
show_wheel(&mut h, centre, -0.4, egui::Modifiers::NONE);
|
||||
assert!(!h.state().show.as_ref().expect("still showing").ended, "a partial notch does not reach the end screen");
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.as_ref().expect("still showing").ended, "a completed forward notch reaches the end screen");
|
||||
show_wheel(&mut h, centre, -1.0, egui::Modifiers::NONE);
|
||||
assert!(h.state().show.is_none(), "forward on the end screen exits the show");
|
||||
}
|
||||
|
||||
/// A zoom at the top of the letterboxed slide keeps the slide over the fitted picture, as production's zoom window
|
||||
/// stays on the slide: its top edge stays at the picture's, not pushed up to the window's.
|
||||
#[test]
|
||||
|
||||
@@ -112,6 +112,7 @@ impl CanvasTool for ShowTool<'_> {
|
||||
if !self.show.zoomed
|
||||
&& !self.show.pen
|
||||
&& !self.show.grid
|
||||
&& !self.show.wheel_taken
|
||||
&& let Some(wheel) = space.wheel()
|
||||
&& !wheel.zooms
|
||||
{
|
||||
|
||||
@@ -143,6 +143,12 @@ fn canvas_pass(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>, show: &mut
|
||||
if show.reading {
|
||||
bars::show(ui, show, p.doc, p.room, p.now);
|
||||
}
|
||||
// A discrete mouse-wheel notch turns one slide per line at once; point-based trackpad
|
||||
// gestures keep the canvas's own page turn.
|
||||
show.wheel_taken = false;
|
||||
if !show.pen && !show.zoomed {
|
||||
wheel_lines(&ctx, show, p.doc, out);
|
||||
}
|
||||
let mut media_wake = None;
|
||||
with_env(
|
||||
ui,
|
||||
@@ -220,6 +226,98 @@ fn canvas_pass(app: &mut SlideApp, ui: &mut Ui, bcx: &mut BodyCx<'_>, show: &mut
|
||||
media_wake
|
||||
}
|
||||
|
||||
/// Discrete wheel input must not share the trackpad's gesture gate. Keep every completed line in
|
||||
/// the order it arrived, including several notches in one frame, so movement at a boundary is not
|
||||
/// lost: a backward then forward notch at the first slide still moves forward. High-resolution
|
||||
/// and free-spin wheels send fractions of a line, accumulated in `show.wheel_carry`; a change of
|
||||
/// direction drops the leftover. The line events are taken out of the frame so the canvas's own
|
||||
/// wheel navigation does not turn the page a second time.
|
||||
fn wheel_lines(ctx: &egui::Context, show: &mut Show, doc: &Presentation, out: &mut Out) {
|
||||
// A multi-pass layout replays the frame's events; only the pass that is kept may move slides,
|
||||
// but every pass must take the lines out so the canvas does not also turn the page.
|
||||
let act = !ctx.will_discard();
|
||||
let mut steps = Vec::new();
|
||||
let mut handled = false;
|
||||
ctx.input_mut(|input| {
|
||||
let slides = doc.slides.len();
|
||||
input.events.retain(|event| {
|
||||
let egui::Event::MouseWheel { unit, delta, modifiers, .. } = event else { return true };
|
||||
if !matches!(unit, egui::MouseWheelUnit::Line | egui::MouseWheelUnit::Page)
|
||||
|| modifiers.ctrl
|
||||
|| modifiers.command
|
||||
|| modifiers.shift
|
||||
|| !delta.y.is_finite()
|
||||
|| delta.y == 0.0
|
||||
|| delta.y.abs() < delta.x.abs()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if act {
|
||||
if show.wheel_carry * delta.y < 0.0 {
|
||||
show.wheel_carry = 0.0;
|
||||
}
|
||||
show.wheel_carry += delta.y;
|
||||
// The small slack keeps sums such as 10 × 0.1 from falling just short of a line.
|
||||
let whole = (show.wheel_carry.abs() + 1e-4).floor();
|
||||
show.wheel_carry -= whole.copysign(show.wheel_carry);
|
||||
let count = whole.min(slides as f32) as usize;
|
||||
if count > 0 {
|
||||
steps.push(if delta.y < 0.0 { count as i32 } else { -(count as i32) });
|
||||
}
|
||||
}
|
||||
handled = true;
|
||||
false
|
||||
});
|
||||
});
|
||||
show.wheel_taken = handled;
|
||||
if !handled || !act {
|
||||
return;
|
||||
}
|
||||
// Each line is applied in arrival order against the state the preceding line left.
|
||||
for by in steps {
|
||||
let count = by.unsigned_abs() as usize;
|
||||
if show.ended {
|
||||
if by > 0 {
|
||||
out.keep = false;
|
||||
break;
|
||||
}
|
||||
show.ended = false;
|
||||
// Resume the last visible slide, even when the show ended from a hidden tail.
|
||||
let Some(target) = show.state.last_index(doc) else { continue };
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
if count > 1
|
||||
&& let Some(target) = show.state.visible_step_clamped(doc, target, false, count - 1)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let forward = by > 0;
|
||||
match show.state.visible_step_clamped(doc, show.state.slide, forward, count) {
|
||||
Some(target) if target != show.state.slide => out.actions.push(show.state.goto(doc, target)),
|
||||
Some(_) | None if forward => {
|
||||
// A looping show wraps from its last visible slide to the first instead of ending.
|
||||
if deckcraft_anim::looping(doc)
|
||||
&& let Some(first) = show.state.first_index(doc)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, first));
|
||||
if count > 1
|
||||
&& let Some(target) = show.state.visible_step_clamped(doc, first, true, count - 1)
|
||||
{
|
||||
out.actions.push(show.state.goto(doc, target));
|
||||
}
|
||||
} else {
|
||||
// A notch that cannot move forward shows the end screen instead of being
|
||||
// swallowed, as a trackpad flick past the last slide does.
|
||||
show.state.end();
|
||||
show.ended = true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The slide's rect on screen when fitted to `rect`, as the unzoomed show draws it.
|
||||
fn fitted_picture(rect: Rect, target: &ViewTarget, zoom: &ShowZoomInputs<'_>) -> Rect {
|
||||
let mut view = CanvasView::new(rect, Point::ZERO, 1.0);
|
||||
|
||||
Reference in New Issue
Block a user