304 lines
18 KiB
Rust
304 lines
18 KiB
Rust
//! Screenshots of the interface, drawn without a window:
|
|
//!
|
|
//! MEDLAR_SHOTS=dir [SCENE=name] [SIZES=480x360,1080x720] [HOVER=x,y] [PRESS=1] cargo test -p medlar --test shots
|
|
//!
|
|
//! Every scene is saved as `<scene>-<light|dark>-<size>.png`; `tools/contact.sh dir` puts them on one sheet. Without
|
|
//! MEDLAR_SHOTS it only checks that every scene draws. A plan adds its view to `SCENES`.
|
|
|
|
use eframe::egui::{self, Align2, Color32, Event, Modifiers, PointerButton, Pos2, Rect, Sense, Stroke, Ui, pos2, vec2};
|
|
use egui_kittest::Harness;
|
|
use medlar_app::app::App;
|
|
use medlar_app::bridge::Bridge;
|
|
use medlar_app::desktop::Sources;
|
|
use medlar_app::motion::spring;
|
|
use medlar_app::theme::{alpha, mix};
|
|
use medlar_app::tokens::{self, radius, space, text};
|
|
use medlar_app::ui::gallery;
|
|
use medlar_app::views::list::layout::Form;
|
|
use medlar_app::{fonts, icons};
|
|
use medlar_app::views::firstrun::FirstRun;
|
|
use medlar_app::views::add::{Add, Request, When};
|
|
use medlar_app::views::main::Wish;
|
|
use medlar_app::views::settings::rows::Page;
|
|
use medlar_core::manager::Probed;
|
|
use medlar_core::model::ErrorKind;
|
|
use medlar_core::settings::{Appearance, Settings};
|
|
use medlar_core::site::Site;
|
|
|
|
#[path = "visuals/gallery.rs"]
|
|
mod progress;
|
|
#[path = "main/fixture.rs"]
|
|
mod downloads;
|
|
|
|
type Scene = (&'static str, fn(&mut App, &mut Ui));
|
|
|
|
const SCENES: &[Scene] = &[("window", App::show), ("tokens", |app, ui| app.frame(ui, sheet)),
|
|
("buttons", |app, ui| app.frame(ui, |app, ui| gallery::page(app, ui, 0))),
|
|
("fields", |app, ui| app.frame(ui, |app, ui| gallery::page(app, ui, 1))),
|
|
("choices", |app, ui| app.frame(ui, |app, ui| gallery::page(app, ui, 2))),
|
|
("over", |app, ui| app.frame(ui, |app, ui| gallery::page(app, ui, 3))),
|
|
("menu", |app, ui| over(app, ui, "menu")),
|
|
("dialog", |app, ui| over(app, ui, "dialog")),
|
|
("confirm", |app, ui| over(app, ui, "confirm")),
|
|
("sheet", |app, ui| over(app, ui, "sheet")),
|
|
("fab", |app, ui| over(app, ui, "fab")),
|
|
("toasts", |app, ui| over(app, ui, "toasts")),
|
|
("main", |app, ui| main_view(app, ui, |_| {})),
|
|
("main-snail", |app, ui| main_view(app, ui, |app| app.settings.mode = medlar_core::settings::Mode::Snail)),
|
|
("main-onebar", |app, ui| main_view(app, ui, |app| app.settings.bar = medlar_core::settings::BarStyle::One)),
|
|
("main-cards", |app, ui| main_view(app, ui, |app| app.main.list.form = Form::Cards)),
|
|
("main-selected", |app, ui| main_view(app, ui, |app| app.main.list.selected = [2, 4, 9].into())),
|
|
("main-filtered", |app, ui| main_view(app, ui, |app| app.main.list.query.filter.kind = Some(medlar_app::ui::shape::Kind::Archive))),
|
|
("main-nothing", |app, ui| main_view(app, ui, |app| app.main.list.query.filter.search = "no such thing".into())),
|
|
("main-failed", |app, ui| main_view(app, ui, |app| app.main.bridge = Bridge::stuck(Some("The download list was made by a newer Medlar (format 9, this one knows 2). Update Medlar to open it.")))),
|
|
("main-opening", |app, ui| main_view(app, ui, |app| app.main.bridge = Bridge::stuck(None))),
|
|
("add-empty", |app, ui| main_view(app, ui, |app| app.main.adding.ask(Request::default()))),
|
|
("add", |app, ui| main_view(app, ui, |app| add(app, "https://mirror.example.org/iso/linux-2026.11.iso", |a| {
|
|
a.learned(Probed { name: "linux-2026.11.iso".into(), size: Some(1_240 * downloads::MB), mime: None, ranges: true, page: false });
|
|
}))),
|
|
("add-more", |app, ui| main_view(app, ui, |app| add(app, "https://mirror.example.org/iso/linux-2026.11.iso", |a| {
|
|
(a.more, a.when) = (true, When::At);
|
|
(a.headers, a.checksum, a.at) = ("no colon".into(), "12".into(), "25:00".into());
|
|
a.learned(Probed { name: "linux-2026.11.iso".into(), size: Some(900_000 * downloads::MB), mime: None, ranges: false, page: false });
|
|
}))),
|
|
("add-error", |app, ui| main_view(app, ui, |app| add(app, "https://files.example.org/private/plan.pdf", |a| {
|
|
a.failed(ErrorKind::Login, "Login needed: files.example.org wants a user name and password.");
|
|
}))),
|
|
("add-video", |app, ui| main_view(app, ui, |app| add(app, "https://videos.example.org/playlist?list=talks", |a| {
|
|
a.learned(Probed { name: "playlist".into(), size: None, mime: Some("text/html".into()), ranges: false, page: true });
|
|
let json = r#"{"_type":"playlist","title":"Conference talks 2026","uploader":"Example Channel","formats":[{"format_id":"a","ext":"m4a","vcodec":"none","acodec":"mp4a","filesize":3000000},{"format_id":"v1","ext":"mp4","height":1080,"vcodec":"avc1","acodec":"none","filesize":90000000},{"format_id":"v2","ext":"mp4","height":480,"vcodec":"avc1","acodec":"none","filesize":20000000}],"subtitles":{"en":[{}],"de":[{}]},"automatic_captions":{"fr":[{}]},"entries":[{"title":"Opening keynote"},{"title":"Fast downloads on slow lines"},{"title":"Spring motion in practice"},{"title":"Wavy progress bars"},{"title":"Closing panel"},{"title":"Lightning talks"},{"title":"Hallway track"},{"title":"Workshop recap"},{"title":"Sponsors"},{"title":"Thanks"}]}"#;
|
|
let probe = medlar_core::ytdlp::Probe::read(&serde_json::from_str(json).unwrap());
|
|
a.video = Some(medlar_app::views::video::Page::Ready(Box::new(medlar_app::views::video::Video::new(std::sync::Arc::new(probe)))));
|
|
a.name = "Conference talks 2026".into();
|
|
}))),
|
|
("add-batch", |app, ui| main_view(app, ui, |app| add(app, "https://share.example.org/files/fonts-collection.zip\nhttps://share.example.org/files/[098-120].jpg\nno link", |_| {}))),
|
|
("add-duplicate", |app, ui| main_view(app, ui, |app| add(app, "https://audio.example.edu/files/podcast-archive.flac", |a| {
|
|
a.learned(Probed { name: "podcast-archive.flac".into(), size: Some(410 * downloads::MB), mime: None, ranges: true, page: false });
|
|
}))),
|
|
("add-continue", |app, ui| main_view(app, ui, |app| add(app, "https://files.example.com/files/report-final.docx?X-Amz-Date=20261125T120000Z&X-Amz-Expires=300&X-Amz-Signature=ab12", |a| {
|
|
a.learned(Probed { name: "report-final.docx".into(), size: Some(4 * downloads::MB), mime: None, ranges: true, page: false });
|
|
a.check.found = Some(Err("Connection failed: files.example.com can't be reached.".into()));
|
|
}))),
|
|
("relink", |app, ui| main_view(app, ui, |app| {
|
|
let mut task = (*downloads::all()[8].task).clone();
|
|
task.source_page = Some("https://example.com/report".into());
|
|
app.main.adding.relink(&task);
|
|
})),
|
|
("set-look", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Look))),
|
|
("set-look-desktop", |app, ui| main_view(app, ui, |app| {
|
|
app.desktop.seed = Some(Color32::from_rgb(0x5a, 0x8f, 0x3c));
|
|
app.settings.desktop_colors = Some(true);
|
|
app.open_settings(Page::Look);
|
|
})),
|
|
("set-downloads", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Downloads))),
|
|
("set-connections", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Connections))),
|
|
("set-network", |app, ui| main_view(app, ui, |app| {
|
|
app.settings.proxy = "socks5://127.0.0.1:1080".into();
|
|
app.open_settings(Page::Network);
|
|
})),
|
|
("set-sites", |app, ui| main_view(app, ui, |app| {
|
|
let site = |pattern: &str| Site { pattern: pattern.into(), ..Site::default() };
|
|
app.settings.sites = vec![
|
|
Site { secret: Some("site:files.example.org".into()), max_connections: Some(4), ..site("files.example.org") },
|
|
Site { speed_limit: Some(512 * 1024), proxy: Some("direct".into()), folder: Some("/home/me/Videos/Lectures and other long names".into()), ..site("*.example.com") },
|
|
site("a-server-with-a-very-long-name-that-does-not-fit-anywhere.downloads.example.net"),
|
|
];
|
|
app.open_settings(Page::Sites);
|
|
})),
|
|
("set-sites-empty", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Sites))),
|
|
("set-browser", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Browser))),
|
|
("set-shortcuts", |app, ui| main_view(app, ui, |app| {
|
|
app.settings.shortcuts.insert("find".into(), "Ctrl+N".into());
|
|
app.settings.shortcuts.insert("rail".into(), String::new());
|
|
app.open_settings(Page::Shortcuts);
|
|
})),
|
|
("set-backup", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Backup))),
|
|
("set-site-dialog", |app, ui| main_view(app, ui, |app| {
|
|
app.open_settings(Page::Sites);
|
|
app.screen.as_mut().unwrap().add_site();
|
|
})),
|
|
("sign-in", |app, ui| main_view(app, ui, |app| app.main.wish = Some(Wish::SignIn("https://files.example.org/a".into(), vec![])))),
|
|
("set-search", |app, ui| main_view(app, ui, |app| {
|
|
app.open_settings(Page::Look);
|
|
app.screen.as_mut().unwrap().find("connection");
|
|
})),
|
|
("set-search-none", |app, ui| main_view(app, ui, |app| {
|
|
app.open_settings(Page::Look);
|
|
app.screen.as_mut().unwrap().find("no such thing");
|
|
})),
|
|
("palette", |app, ui| main_view(app, ui, |app| app.palette.toggle())),
|
|
("first-folder", |app, ui| main_view(app, ui, |app| app.first = Some(FirstRun::default()))),
|
|
("first-colours", |app, ui| main_view(app, ui, |app| app.first = Some(FirstRun::at(1)))),
|
|
("first-browser", |app, ui| main_view(app, ui, |app| app.first = Some(FirstRun::at(2)))),
|
|
("set-rules", |app, ui| main_view(app, ui, |app| {
|
|
app.settings.rules = medlar_core::rules::defaults();
|
|
app.open_settings(Page::Rules);
|
|
})),
|
|
("set-rules-long", |app, ui| main_view(app, ui, |app| {
|
|
let mut r = medlar_core::rules::defaults();
|
|
r[0].name = "A rule with a name of two hundred characters ".repeat(5);
|
|
r[0].min_mb = 1_000_000;
|
|
app.settings.rules = r;
|
|
app.open_settings(Page::Rules);
|
|
})),
|
|
("set-rules-empty", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Rules))),
|
|
("set-clipboard", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Clipboard))),
|
|
("set-notifications", |app, ui| main_view(app, ui, |app| app.open_settings(Page::Notifications))),
|
|
("details", |app, ui| main_view(app, ui, |app| app.main.details.open = Some(2))),
|
|
("control-0", |app, ui| main_view(app, ui, |app| (app.main.control.open, app.main.control.tab) = (true, 0))),
|
|
("control-1", |app, ui| main_view(app, ui, |app| (app.main.control.open, app.main.control.tab) = (true, 1))),
|
|
("control-2", |app, ui| main_view(app, ui, |app| (app.main.control.open, app.main.control.tab) = (true, 2))),
|
|
("control-3", |app, ui| main_view(app, ui, |app| (app.main.control.open, app.main.control.tab) = (true, 3))),
|
|
("progress", |app, ui| app.frame(ui, progress::gallery)),
|
|
("progress-states", |app, ui| app.frame(ui, progress::states)),
|
|
];
|
|
|
|
fn pair(s: &str, sep: char) -> Option<(f32, f32)> {
|
|
let (a, b) = s.split_once(sep)?;
|
|
Some((a.trim().parse().ok()?, b.trim().parse().ok()?))
|
|
}
|
|
|
|
fn settings(appearance: Appearance) -> Settings {
|
|
Settings { appearance, desktop_colors: Some(false), ..Settings::default() }
|
|
}
|
|
|
|
/// No desktop colours: the same picture on every PC.
|
|
fn sources() -> Sources {
|
|
Sources { caelestia: "/nonexistent".into(), kde: "/nonexistent".into() }
|
|
}
|
|
|
|
fn harness(scene: Scene, appearance: Appearance, size: (f32, f32)) -> Harness<'static> {
|
|
let mut app = None;
|
|
Harness::builder().with_size(vec2(size.0, size.1)).with_step_dt(1.0 / 60.0).wgpu().build_ui(move |ui| {
|
|
if app.is_none() {
|
|
// Fonts count from the next frame.
|
|
app = Some(App::new(ui.ctx(), settings(appearance), sources()));
|
|
ui.ctx().request_repaint();
|
|
return;
|
|
}
|
|
scene.1(app.as_mut().unwrap(), ui);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn shots() {
|
|
let out = std::env::var("MEDLAR_SHOTS").ok();
|
|
let only = std::env::var("SCENE").ok();
|
|
let hover = std::env::var("HOVER").ok().map(|h| pair(&h, ',').expect("HOVER=x,y"));
|
|
let sizes = std::env::var("SIZES").unwrap_or_else(|_| "480x360,1080x720".into());
|
|
if let Some(dir) = &out {
|
|
std::fs::create_dir_all(dir).unwrap();
|
|
}
|
|
for scene in SCENES.iter().filter(|s| only.as_deref().is_none_or(|o| o == s.0)) {
|
|
for (mode, appearance) in [("light", Appearance::Light), ("dark", Appearance::Dark)] {
|
|
for size in sizes.split(',') {
|
|
let mut h = harness(*scene, appearance, pair(size, 'x').expect("SIZES=WxH,WxH"));
|
|
// The pointer meets what the last frame drew.
|
|
h.run_steps(2);
|
|
if let Some((x, y)) = hover {
|
|
h.input_mut().events.push(Event::PointerMoved(pos2(x, y)));
|
|
}
|
|
h.run_steps(60);
|
|
if let Some((x, y)) = hover.filter(|_| std::env::var_os("PRESS").is_some()) {
|
|
let pos = pos2(x, y);
|
|
h.input_mut().events.push(Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
|
// egui gives up on a click held for 0.8 s.
|
|
h.run_steps(30);
|
|
}
|
|
if let Some(dir) = &out {
|
|
h.render().expect("render").save(format!("{dir}/{}-{mode}-{size}.png", scene.0)).unwrap();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The main screen with downloads in every state, changed once by `set`.
|
|
fn main_view(app: &mut App, ui: &mut Ui, set: fn(&mut App)) {
|
|
let seen = egui::Id::unique("main view set");
|
|
if ui.data(|d| d.get_temp::<bool>(seen).is_none()) {
|
|
ui.data_mut(|d| d.insert_temp(seen, true));
|
|
app.main.bridge = Bridge::still(downloads::shot(downloads::all()), downloads::lists());
|
|
set(app);
|
|
}
|
|
app.show(ui);
|
|
}
|
|
|
|
/// The Add dialog with an answer from no server.
|
|
fn add(app: &mut App, text: &str, set: fn(&mut Add)) {
|
|
app.main.adding.open_still(Request { text: text.into(), ..Request::default() }, &app.settings, set);
|
|
}
|
|
|
|
fn over(app: &mut App, ui: &mut Ui, what: &str) {
|
|
gallery::open(ui, what);
|
|
app.frame(ui, |app, ui| gallery::page(app, ui, 3));
|
|
}
|
|
|
|
/// Roles, type, icons, shapes and one control that answers the pointer.
|
|
fn sheet(app: &mut App, ui: &mut Ui) {
|
|
let t = app.theme.clone();
|
|
let roles = [
|
|
("Primary", t.primary, t.on_primary),
|
|
("Primary container", t.primary_container, t.on_primary_container),
|
|
("Secondary", t.secondary, t.on_secondary),
|
|
("Secondary container", t.secondary_container, t.on_secondary_container),
|
|
("Tertiary", t.tertiary, t.on_tertiary),
|
|
("Tertiary container", t.tertiary_container, t.on_tertiary_container),
|
|
("Error", t.error, t.on_error),
|
|
("Error container", t.error_container, t.on_error_container),
|
|
("Inverse surface", t.inverse_surface, t.inverse_on_surface),
|
|
("Lowest", t.lowest, t.on_surface),
|
|
("Low", t.low, t.on_surface),
|
|
("Container", t.container, t.on_surface),
|
|
("High", t.high, t.on_variant),
|
|
("Highest", t.highest, t.on_variant),
|
|
];
|
|
for (i, (name, fill, on)) in roles.into_iter().enumerate() {
|
|
let at = pos2(space::L + (i % 2) as f32 * 168.0, space::L + (i / 2) as f32 * 48.0);
|
|
let r = Rect::from_min_size(at, vec2(160.0, 40.0));
|
|
ui.painter().rect(r, radius::M, fill, Stroke::new(tokens::size::HAIRLINE, t.outline_variant), egui::StrokeKind::Inside);
|
|
ui.painter().text(r.left_center() + vec2(space::M, 0.0), Align2::LEFT_CENTER, name, fonts::med(text::LABEL), on);
|
|
}
|
|
let mut y = space::L;
|
|
let x = 376.0;
|
|
let mut line = |what: &str, font, color: Color32| {
|
|
y = ui.painter().text(pos2(x, y), Align2::LEFT_TOP, what, font, color).bottom() + space::S;
|
|
};
|
|
line("1,111.8", fonts::semi(text::DISPLAY), t.on_surface);
|
|
line("0,404.7", fonts::semi(text::DISPLAY), t.on_surface);
|
|
line("Headline", fonts::semi(text::HEADLINE), t.on_surface);
|
|
line("Title", fonts::semi(text::TITLE), t.on_surface);
|
|
line("Body text Ωж €", fonts::ui(text::BODY), t.on_surface);
|
|
line("Second line", fonts::ui(text::BODY), t.on_variant);
|
|
line("Label", fonts::ui(text::LABEL), t.on_variant);
|
|
for (i, (word, c)) in [("Error", t.error), ("Done", t.success), ("Slow", t.warning)].into_iter().enumerate() {
|
|
ui.painter().text(pos2(x + i as f32 * 64.0, y), Align2::LEFT_TOP, word, fonts::med(text::BODY), c);
|
|
}
|
|
y += space::XXL;
|
|
for (i, size) in tokens::icon::ALL.into_iter().take(4).enumerate() {
|
|
icons::paint(ui.painter(), pos2(x + 24.0 + i as f32 * 48.0, y + 20.0), size, "folder", t.on_variant);
|
|
icons::paint(ui.painter(), pos2(x + 24.0 + i as f32 * 48.0, y + 64.0), size, "download_done", t.primary);
|
|
}
|
|
button(app, ui, pos2(x, y + 104.0));
|
|
let panel = Rect::from_min_size(pos2(640.0, space::L), vec2(240.0, 160.0));
|
|
ui.painter().add(tokens::elevation::floating(t.dark).as_shape(panel, radius::L));
|
|
ui.painter().rect_filled(panel, radius::L, t.container);
|
|
ui.painter().rect_filled(panel.shrink(space::S), radius::inner(radius::L, space::S), t.high);
|
|
icons::paint_app(ui.painter(), panel.center_bottom() + vec2(0.0, 88.0), tokens::icon::HERO);
|
|
icons::paint_app(ui.painter(), panel.center_bottom() + vec2(88.0, 88.0), tokens::icon::L);
|
|
}
|
|
|
|
fn button(app: &App, ui: &mut Ui, at: Pos2) {
|
|
use tokens::spring::{EFFECT, FAST};
|
|
let t = &app.theme;
|
|
let rect = Rect::from_min_size(at, vec2(128.0, tokens::size::CONTROL));
|
|
let r = ui.interact(rect, ui.scope_id().with("button"), Sense::click());
|
|
let down = r.is_pointer_button_down_on();
|
|
let tint = if down { tokens::state::PRESS } else if r.hovered() { tokens::state::HOVER } else { 0.0 };
|
|
let tint = spring("button tint", tint, EFFECT);
|
|
let scale = spring("button scale", if down { 0.94 } else { 1.0 }, FAST);
|
|
let rect = Rect::from_center_size(rect.center(), rect.size() * scale);
|
|
ui.painter().rect_filled(rect, radius::FULL, mix(t.primary, t.on_primary, tint));
|
|
icons::paint(ui.painter(), rect.left_center() + vec2(26.0, 0.0), tokens::icon::M, "add", t.on_primary);
|
|
ui.painter().text(rect.center() + vec2(14.0, 0.0), Align2::CENTER_CENTER, "Add links", fonts::med(text::BODY), alpha(t.on_primary, 1.0));
|
|
}
|