mirror of
https://github.com/storytold/deckcraft.git
synced 2026-12-03 22:41:09 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6957219245 | ||
|
|
9e73fef158 | ||
|
|
4885a1724d | ||
|
|
72e3055b3b | ||
|
|
c462f658ab | ||
|
|
9e00c7ae9b | ||
|
|
23f0cd1c9f | ||
|
|
bb345f2828 | ||
|
|
dd18f64d3f | ||
|
|
8519680df0 |
Generated
+12
-1
@@ -2469,7 +2469,6 @@ name = "deckcraft-engine"
|
||||
version = "0.20.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-metafile",
|
||||
"craft-mime",
|
||||
"deckcraft-anim",
|
||||
"deckcraft-color",
|
||||
@@ -2487,6 +2486,7 @@ dependencies = [
|
||||
"image",
|
||||
"js-sys",
|
||||
"log",
|
||||
"memory-stats",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2671,6 +2671,7 @@ dependencies = [
|
||||
"egui",
|
||||
"egui_kittest",
|
||||
"log",
|
||||
"memory-stats",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"skrifa 0.47.0",
|
||||
@@ -4949,6 +4950,16 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memory-stats"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c73f5c649995a115e1a0220b35e4df0a1294500477f97a91d0660fb5abeb574a"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.18"
|
||||
|
||||
@@ -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, looping, safe_url, show_order};
|
||||
pub use show::{LinkJump, ShowAction, ShowState, 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};
|
||||
|
||||
|
||||
+10
-45
@@ -117,7 +117,7 @@ fn custom_indices(pres: &Presentation, name: &str) -> Option<Vec<usize>> {
|
||||
if order.is_empty() { None } else { Some(order) }
|
||||
}
|
||||
|
||||
pub fn looping(pres: &Presentation) -> bool {
|
||||
fn looping(pres: &Presentation) -> bool {
|
||||
pres.show.loop_until_esc || pres.show.show_type == "kiosk"
|
||||
}
|
||||
|
||||
@@ -236,54 +236,19 @@ impl ShowState {
|
||||
}
|
||||
|
||||
fn next_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
self.visible_step(pres, self.slide, true, 1)
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
fn prev_index(&self, pres: &Presentation) -> Option<usize> {
|
||||
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()
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
/// Click / → / Space: finish the playing step, else play the next step, else go to the next slide.
|
||||
|
||||
@@ -763,21 +763,6 @@ 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,8 +10,6 @@ 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 }
|
||||
@@ -33,8 +31,8 @@ chrono = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
deckcraft-anim = { workspace = true }
|
||||
memory-stats = "1.2.0"
|
||||
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,12 +33,6 @@ 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") {
|
||||
|
||||
@@ -64,6 +64,42 @@ fn params(r: &mut Rng, s: &Session) -> Value {
|
||||
}
|
||||
}
|
||||
|
||||
/// Physical memory in use, in bytes: the resident set size on Linux and macOS, the working set on
|
||||
/// Windows. `None` where the platform cannot say.
|
||||
fn rss_bytes() -> Option<u64> {
|
||||
memory_stats::memory_stats().map(|m| m.physical_mem as u64)
|
||||
}
|
||||
|
||||
/// Whether this process may run the named soak itself, so its memory reading is its own.
|
||||
///
|
||||
/// The reading is for the whole process, and plain `cargo test` runs every test of the crate on
|
||||
/// threads of one process, so other tests' allocations would count against the budget. nextest
|
||||
/// runs each test in its own process (and sets `NEXTEST`). Anywhere else the test runs itself again
|
||||
/// in a child process of its own, which takes this branch, and fails if the child does.
|
||||
fn alone(test: &str) -> bool {
|
||||
const MARK: &str = "DECKCRAFT_SOAK_ALONE";
|
||||
if std::env::var_os("NEXTEST").is_some() || std::env::var_os(MARK).is_some() {
|
||||
return true;
|
||||
}
|
||||
let path = module_path!().split_once("::").map_or(module_path!(), |(_, rest)| rest);
|
||||
let out = std::process::Command::new(std::env::current_exe().expect("test binary path"))
|
||||
.args(["--exact", &format!("{path}::{test}"), "--include-ignored", "--test-threads=1", "--nocapture"])
|
||||
.env(MARK, "1")
|
||||
.output()
|
||||
.expect("run the soak in its own process");
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"soak {test} failed in its own process:\n{}\n{}",
|
||||
String::from_utf8_lossy(&out.stdout),
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
false
|
||||
}
|
||||
|
||||
/// RSS growth allowed between the warmed-up start and the end of a soak, with the test alone in
|
||||
/// its process (see `alone`).
|
||||
const MAX_RSS_GROWTH: u64 = 256 << 20;
|
||||
|
||||
fn doc(s: &Session) -> Option<deckcraft_model::Presentation> {
|
||||
s.active().map(|d| (*d.doc).clone())
|
||||
}
|
||||
@@ -91,7 +127,12 @@ fn soak(seed: u64, steps: usize) {
|
||||
let mut r = Rng(seed | 1);
|
||||
let mut log: VecDeque<String> = VecDeque::new();
|
||||
let mut edits = 0usize;
|
||||
let mut rss_start = None;
|
||||
for step in 0..steps {
|
||||
// Sample after a quarter of the run so one-off caches and allocator arenas are warm.
|
||||
if step == steps / 4 {
|
||||
rss_start = rss_bytes();
|
||||
}
|
||||
let id = *r.pick(&ids).unwrap();
|
||||
let p = params(&mut r, &s);
|
||||
log.push_back(format!("{id} {p}"));
|
||||
@@ -140,7 +181,13 @@ fn soak(seed: u64, steps: usize) {
|
||||
}
|
||||
// The soak must really edit, not just bounce off disabled commands.
|
||||
assert!(edits * 10 >= steps, "only {edits} of {steps} steps changed the document; seed {seed}");
|
||||
eprintln!("soak seed {seed}: {edits} of {steps} steps edited");
|
||||
if let (Some(start), Some(end)) = (rss_start, rss_bytes()) {
|
||||
let grew = end.saturating_sub(start);
|
||||
eprintln!("soak seed {seed}: {edits} of {steps} steps edited, memory {} -> {} MiB", start >> 20, end >> 20);
|
||||
assert!(grew <= MAX_RSS_GROWTH, "memory grew {} MiB over {} MiB; seed {seed}", grew >> 20, MAX_RSS_GROWTH >> 20);
|
||||
} else {
|
||||
eprintln!("soak seed {seed}: {edits} of {steps} steps edited");
|
||||
}
|
||||
}
|
||||
|
||||
fn steps(default: usize) -> usize {
|
||||
@@ -149,6 +196,9 @@ fn steps(default: usize) -> usize {
|
||||
|
||||
#[test]
|
||||
fn soak_random_edits_keep_the_document_valid() {
|
||||
if !alone("soak_random_edits_keep_the_document_valid") {
|
||||
return;
|
||||
}
|
||||
for seed in [1, 0xDEC0_C2AF, 42, 7_777_777] {
|
||||
soak(seed, steps(400));
|
||||
}
|
||||
@@ -157,6 +207,9 @@ fn soak_random_edits_keep_the_document_valid() {
|
||||
#[test]
|
||||
#[ignore = "long soak; set DECKCRAFT_SOAK_STEPS"]
|
||||
fn soak_long() {
|
||||
if !alone("soak_long") {
|
||||
return;
|
||||
}
|
||||
let seed = std::env::var("DECKCRAFT_SOAK_SEED").ok().and_then(|v| v.parse().ok()).unwrap_or(0x5EED);
|
||||
soak(seed, steps(20_000));
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
//! 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,3 +1,2 @@
|
||||
mod chart_native;
|
||||
mod insert_metafile;
|
||||
mod show_clicks;
|
||||
|
||||
@@ -38,6 +38,7 @@ skrifa = { workspace = true }
|
||||
# kittest's own dev-dependencies do not propagate; tests need both font features explicitly.
|
||||
egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] }
|
||||
egui_kittest = { workspace = true, features = ["wgpu", "snapshot", "eframe"] }
|
||||
memory-stats = "1.2.0"
|
||||
|
||||
[build-dependencies]
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -82,11 +82,6 @@ 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>,
|
||||
@@ -237,8 +232,6 @@ 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,
|
||||
|
||||
@@ -775,18 +775,9 @@ 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();
|
||||
for _ in 1..slides {
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
}
|
||||
for &i in hidden {
|
||||
session.execute("slide.hide", &json!({"index": i, "hidden": true})).unwrap();
|
||||
}
|
||||
session.execute("slide.new", &json!({})).unwrap();
|
||||
session.execute("slide.new", &json!({})).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;
|
||||
@@ -833,184 +824,10 @@ 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);
|
||||
// #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");
|
||||
assert_eq!(h.state().show.as_ref().expect("still showing").state.slide, 1, "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,7 +112,6 @@ 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,12 +143,6 @@ 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,
|
||||
@@ -226,98 +220,6 @@ 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);
|
||||
|
||||
@@ -23,6 +23,16 @@ const MAX_JOURNAL: usize = 10_000;
|
||||
/// Mean wall time per frame, generous for slow CI machines (the test profile is optimized).
|
||||
const MAX_MEAN_FRAME: Duration = Duration::from_millis(250);
|
||||
|
||||
/// RSS growth allowed between the warmed-up start and the end of a soak; generous because
|
||||
/// `cargo test` threads share the process.
|
||||
const MAX_RSS_GROWTH: u64 = 256 << 20;
|
||||
|
||||
/// Physical memory in use, in bytes: the resident set size on Linux and macOS, the working set on
|
||||
/// Windows. `None` where the platform cannot say.
|
||||
fn rss_bytes() -> Option<u64> {
|
||||
memory_stats::memory_stats().map(|m| m.physical_mem as u64)
|
||||
}
|
||||
|
||||
struct Rng(u64);
|
||||
|
||||
impl Rng {
|
||||
@@ -161,6 +171,7 @@ fn soak(seed: u64, steps: usize) {
|
||||
let mut log = VecDeque::new();
|
||||
let t0 = Instant::now();
|
||||
let mut frames = 0usize;
|
||||
let mut rss_start = None;
|
||||
for step in 0..steps {
|
||||
log.push_back(act(&mut h, &mut r));
|
||||
if log.len() > 20 {
|
||||
@@ -168,6 +179,11 @@ fn soak(seed: u64, steps: usize) {
|
||||
}
|
||||
h.run_steps(2);
|
||||
frames += 8;
|
||||
// Sample after a quarter of the run and its frames, so texture caches and allocator arenas
|
||||
// are warm. Short runs sample only after their first completed action.
|
||||
if step + 1 == (steps / 4).max(1) {
|
||||
rss_start = rss_bytes();
|
||||
}
|
||||
if step % 10 == 9 {
|
||||
check(&h, seed, step, &log);
|
||||
}
|
||||
@@ -184,6 +200,11 @@ fn soak(seed: u64, steps: usize) {
|
||||
let mean = t0.elapsed() / frames.max(1) as u32;
|
||||
eprintln!("ui soak seed {seed}: {steps} actions, {edits} commands, ~{frames} frames, mean frame {mean:?}");
|
||||
assert!(mean <= MAX_MEAN_FRAME, "mean frame {mean:?} over {MAX_MEAN_FRAME:?}; seed {seed}");
|
||||
if let (Some(start), Some(end)) = (rss_start, rss_bytes()) {
|
||||
let grew = end.saturating_sub(start);
|
||||
eprintln!("ui soak seed {seed}: memory {} -> {} MiB", start >> 20, end >> 20);
|
||||
assert!(grew <= MAX_RSS_GROWTH, "memory grew {} MiB over {} MiB; seed {seed}", grew >> 20, MAX_RSS_GROWTH >> 20);
|
||||
}
|
||||
}
|
||||
|
||||
fn env(name: &str, default: u64) -> u64 {
|
||||
|
||||
+9
-4
@@ -48,7 +48,7 @@ revision history.
|
||||
- **Estimate:** 4–8 h (backend probing outside the process or a safe-mode fallback, a software
|
||||
renderer path). Needs a tester with the hardware. **Beta blocker.**
|
||||
|
||||
### Soak testing has no memory or timing budgets
|
||||
### Soak memory budgets run in CI on Linux only
|
||||
- **Evidence:** `crates/engine/src/soak_tests.rs` runs seeded random command sequences over a
|
||||
~100-slide deck (validity, selection, undo/redo exactness, bounded undo, save/reopen in both
|
||||
formats every 100 steps); `DECKCRAFT_SOAK_STEPS` runs it long. It found a chart `clamp` panic
|
||||
@@ -56,9 +56,13 @@ revision history.
|
||||
seeded random clicks, drags, keys (plain, Ctrl, Shift), typing and scrolling over the sample
|
||||
deck, checking document validity, bounded undo/journal/thumbnail/texture caches, zero caught
|
||||
command and render panics (`Session::panics_caught`, `deckcraft_render::panics_caught`) and a
|
||||
mean frame under 250 ms; 4 × 3000-action runs are clean.
|
||||
- **Impact:** long-session crash rate is sampled in CI; RSS is not measured directly.
|
||||
- **Estimate:** 1–2 h (RSS sampling per platform).
|
||||
mean frame under 250 ms; 4 × 3000-action runs are clean. Both soaks also sample resident memory
|
||||
(`memory-stats`: `/proc` on Linux, `GetProcessMemoryInfo` on Windows, Mach task info on macOS)
|
||||
after a quarter of the run and fail if it then grows by more than 256 MiB.
|
||||
- **Impact:** long-session crash rate is sampled in CI; the RSS budget is only exercised on Linux
|
||||
(`ci.yml`), and the Windows and macOS code paths have never run in CI. The engine soak has no
|
||||
wall-time budget.
|
||||
- **Estimate:** 1 h (a Windows and macOS test job; a timing budget).
|
||||
|
||||
## File formats
|
||||
|
||||
@@ -367,6 +371,7 @@ Detail in [localization-parity.md](localization-parity.md).
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-26 | trivial | The engine and UI soaks fail if resident memory grows by more than 256 MiB after warm-up (through `memory-stats`: Linux, Windows and macOS; only Linux runs in CI) |
|
||||
| 2026-11-02 | trivial | Run alternate-language metadata now survives native and PPTX saves; UI and proofing gaps remain; scores unchanged |
|
||||
| 2026-11-02 | trivial | PPTX reflection geometry is retained through native and PPTX resaves; no rendering parity claim |
|
||||
| 2026-11-02 | trivial | Reused slide geometry and content scale to the destination; picker thumbnails remain the reuse gap |
|
||||
|
||||
Reference in New Issue
Block a user