//! Regenerates the README screenshots from a made-up library: //! `MULBERRY_DOCS=docs cargo test --test docs_shots -- --nocapture` use eframe::egui::{self, pos2, vec2, Event, Modifiers, PointerButton}; use egui_kittest::Harness; use mulberry::app::{AddMode, App}; fn click(h: &mut Harness<'_, App>, pos: egui::Pos2, button: PointerButton, mods: Modifiers) { h.input_mut().events.push(Event::ModifiersChanged(mods)); h.input_mut().events.push(Event::PointerMoved(pos)); h.step(); h.input_mut().events.push(Event::PointerButton { pos, button, pressed: true, modifiers: mods }); h.step(); h.input_mut().events.push(Event::PointerButton { pos, button, pressed: false, modifiers: mods }); h.step(); h.input_mut().events.push(Event::ModifiersChanged(Modifiers::NONE)); h.step(); } fn settle(h: &mut Harness<'_, App>, n: usize) { for _ in 0..n { h.step(); std::thread::sleep(std::time::Duration::from_millis(40)); } } const LYRICS: &str = "[00:00.00]\n[00:08.00]Neon rain on the avenue\n[00:14.00]Every light a little louder\n[00:20.00]Every street a little new\n[00:26.00]Hold the signal, hold it true\n[00:32.00]Falling through the static bloom\n[00:38.00]Mulberry dusk in an empty room\n[00:44.00]Carry me home when the city sleeps\n[00:50.00]Under the glow that the evening keeps\n[00:56.00]Neon rain on the avenue\n[01:02.00]Every light a little louder\n"; #[test] fn readme_screenshots() { let out = std::env::var("MULBERRY_DOCS").unwrap_or_else(|_| "docs".into()); let sc = std::env::temp_dir().join(format!("mulberry-docs-{}", std::process::id())); let music = sc.join("Music"); let albums: [(&str, &str, i32, Vec<&str>, &str, &str); 4] = [ ("Velvet Arcade", "Nightglass", 2019, vec!["Neon Rain", "Glass Hearts", "Midnight Signal", "Afterglow", "Static Bloom"], "#7b4fd1", "#e85fb0"), ("Velvet Arcade", "Low Tide Radio", 2021, vec!["Harbour Lights", "Salt and Static", "Tape Hiss Lullaby", "Slow Current"], "#1d8f9c", "#8ee0b4"), ("Marlow Quay", "Paper Lanterns", 2017, vec!["First Light", "Lantern Season", "Wooden Bridges", "Quiet Hours"], "#d17a2f", "#f2c14e"), ("The Hollow Pines", "Understory", 2022, vec!["Root and Branch", "Moss", "Lichen Moon"], "#2f8a4d", "#b7e07a"), ]; for (artist, album, year, tracks, c1, c2) in &albums { let dir = music.join(artist).join(album); std::fs::create_dir_all(&dir).unwrap(); assert!(std::process::Command::new("magick").args(["-size", "700x700", &format!("gradient:{c1}-{c2}"), "-gravity", "center", "-fill", "white", "-pointsize", "64", "-annotate", "0", &album.replace(' ', "\n")]).arg(dir.join("cover.jpg")).status().unwrap().success()); for (i, t) in tracks.iter().enumerate() { let p = dir.join(format!("{:02} {t}.flac", i + 1)); let mut args: Vec = ["-v", "quiet", "-y", "-f", "lavfi", "-i", "sine=frequency=330:duration=200"].iter().map(|s| s.to_string()).collect(); for (k, v) in [("title", t.to_string()), ("artist", artist.to_string()), ("album", album.to_string()), ("date", year.to_string()), ("track", (i + 1).to_string()), ("genre", "Synthwave".to_string()), ("lyrics", LYRICS.to_string())] { args.push("-metadata".into()); args.push(format!("{k}={v}")); } assert!(std::process::Command::new("ffmpeg").args(&args).arg(&p).status().unwrap().success()); } } std::fs::create_dir_all(sc.join("config/mulberry")).unwrap(); std::fs::write( sc.join("config/mulberry/settings.json"), format!("{{\"library/folders\":[\"{}\"],\"playback/resume\":false,\"online/auto_lyrics\":false,\"online/auto_covers\":false,\"lyrics/source\":\"embedded\",\"appearance/color_source\":\"album\",\"appearance/mode\":\"dark\",\"ui/sidebar_tab\":0,\"lastfm/enabled\":false}}", music.display()), ) .unwrap(); std::env::set_var("MULBERRY_TEST", "1"); std::env::set_var("XDG_DATA_HOME", sc.join("data")); std::env::set_var("XDG_CONFIG_HOME", sc.join("config")); std::env::set_var("XDG_CACHE_HOME", sc.join("cache")); let mut h = Harness::builder().with_size(vec2(1380.0, 860.0)).wgpu().build_eframe(|cc| App::new(cc, vec![])); h.ctx.set_missing_glyph_policy(eframe::epaint::text::MissingGlyphPolicy::Tofu); settle(&mut h, 60); // scan h.state_mut().add_paths(vec![music.join("Velvet Arcade/Nightglass").to_string_lossy().into_owned()], AddMode::Play); settle(&mut h, 40); h.state_mut().seek(41.0); settle(&mut h, 40); // library tree: expand the first artist click(&mut h, pos2(26.0, 168.0), PointerButton::Primary, Modifiers::NONE); settle(&mut h, 8); let save = |h: &mut Harness<'_, App>, name: &str| { for _ in 0..4 { h.step(); } h.render().unwrap().save(format!("{out}/{name}.png")).unwrap(); }; save(&mut h, "main"); // two albums mixed in one playlist: select across them and right-click the Album cell of a Nightglass track h.state_mut().add_paths(vec![music.join("Velvet Arcade").to_string_lossy().into_owned()], AddMode::New); settle(&mut h, 40); click(&mut h, pos2(480.0, 489.0 + 60.0), PointerButton::Primary, Modifiers::NONE); click(&mut h, pos2(480.0, 489.0 + 150.0), PointerButton::Primary, Modifiers::SHIFT); click(&mut h, pos2(1000.0, 489.0 + 150.0), PointerButton::Secondary, Modifiers::NONE); h.input_mut().events.push(Event::PointerMoved(pos2(1300.0, 20.0))); settle(&mut h, 4); save(&mut h, "set-tag-menu"); h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: Some(egui::Key::Escape), pressed: true, repeat: false, modifiers: Modifiers::NONE }); settle(&mut h, 3); h.state_mut().do_action("focus"); settle(&mut h, 6); save(&mut h, "focus"); h.state_mut().do_action("focus"); h.state_mut().do_action("settings"); settle(&mut h, 6); save(&mut h, "settings"); }