LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-PREF-GENERAL: the slide preview stays above the Slideshow page while the templates are browsed
Nathaniel Ledford2525613e3e73
diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rsindex 0ec907e9e..1f1dd4eec 100644--- a/crates/ui-egui/src/panels/settings.rs+++ b/crates/ui-egui/src/panels/settings.rs@@ -44,7 +44,7 @@ pub fn body(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &str) {"performance" => performance_tab(app, ui, &t),"display" => display_tab(app, ui, &t),"interface" => interface_tab(app, ui, &t),- "slideshow" => slideshow_tab(app, ui, &t),+ "slideshow" => slideshow_tab(app, ui, &t, true),"faces" => super::faces::settings_tab(app, ui, &t),"denoise" => super::denoise::settings_tab(app, ui, &t),_ => general_tab(app, ui, &t),@@ -59,14 +59,24 @@ const PAGE_SIZE: egui::Vec2 = egui::vec2(560.0, 640.0);/// desktop minimum), the tabs and the page scroll together in the dialog's own scroll area.const PAGE_MIN_HEIGHT: f32 = 120.0;+/// The share of the page's room the pinned slide preview of the Slideshow tab takes, when the page+/// has more room than it needs to keep [`PAGE_MIN_HEIGHT`] for itself.+const PINNED_PREVIEW_SHARE: f32 = 0.4;++/// What the preview's heading, the one-line hint under the slide, its Photo / Intro / Ending+/// choice and the rule under it take around the slide (at the default spacing, about 82 pt).+const PREVIEW_CHROME: f32 = 82.0;+/// The Settings window's content: the tab bar, which stays put, above the page of `tab`/// ([`body`]), which scrolls when it is taller than the room for it, with a scroll handle that/// shows without the pointer on it. `max_height` is the room the app window leaves for both: the/// two together never take more, so the scroll area every dialog is drawn in has nothing to/// scroll (but for a window with less than [`PAGE_MIN_HEIGHT`] for the page, where that area-/// scrolls the two together). Every page gets the same room whatever it holds, and each keeps a-/// scroll position of its own. Nothing here is wider than the window from 640 pt of app window+/// scrolls the two together). Every page gets the same room whatever it holds (but for the pinned+/// preview of Slideshow), and each keeps a scroll position of its own. Nothing here is wider than the window from 640 pt of app window/// up: a row's controls wrap ([`row`]) and paths are shortened ([`path_label`]).+/// On Slideshow the slide preview is pinned between the tab bar and the page (where the room+/// allows), and comes off that page's room.pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_height: f32) {ui.set_width((ui.ctx().content_rect().width() - 64.0).clamp(240.0, PAGE_SIZE.x));let top = ui.cursor().top();@@ -86,7 +96,24 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_register(ui.ctx(), "settings:page", ui.min_rect());return;}- let height = room.min(PAGE_SIZE.y);+ let mut height = room.min(PAGE_SIZE.y);+ // The slide preview stays above the page on Slideshow: hovering a template in the Template+ // Browser previews it there, so it has to stay in view however far down the templates are+ // scrolled to. With its heading and choice it takes [`PINNED_PREVIEW_SHARE`] of the room+ // (at least the least tall slide); where that leaves less than [`PAGE_MIN_HEIGHT`] for the+ // page, it scrolls with the page instead (as in the short window above).+ let mut pinned = false;+ if tab == "slideshow" {+ let slide_h = (height * PINNED_PREVIEW_SHARE - PREVIEW_CHROME).max(super::slide_layout::PREVIEW_MIN_H);+ if height - (slide_h + PREVIEW_CHROME) >= PAGE_MIN_HEIGHT {+ let before = ui.cursor().top();+ super::slide_layout::preview(app, ui, &Tokens::get(ui.ctx()), slide_h);+ ui.add_space(2.0);+ ui.separator();+ height = (height - (ui.cursor().top() - before)).max(PAGE_MIN_HEIGHT);+ pinned = true;+ }+ }// A page that goes on below shows its scroll handle all the time: without it, a page a line// or two too long looks cut off, not scrollable.ui.spacing_mut().scroll.dormant_handle_opacity = 0.6;@@ -97,7 +124,11 @@ pub fn window(app: &mut LightcraftApp, ui: &mut egui::Ui, tab: &mut String, max_.auto_shrink([false, false]).show(ui, |ui| {ui.add_space(2.0);- body(app, ui, tab.as_str());+ if pinned {+ slideshow_tab(app, ui, &Tokens::get(ui.ctx()), false);+ } else {+ body(app, ui, tab.as_str());+ }// (what the page took: wider than the room for it would mean a control is cut off)register(ui.ctx(), "settings:page", ui.min_rect());});@@ -868,10 +899,13 @@ fn duration_slider(app: &mut LightcraftApp, ui: &mut egui::Ui, id: &str, key: &s}/// The Slideshow tab: the slide preview, then the settings, in one column the width of the page-/// (the page scrolls; a column beside the preview would be wider than the window).-fn slideshow_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {- super::slide_layout::preview(app, ui, t);- ui.add_space(6.0);+/// (the page scrolls; a column beside the preview would be wider than the window). Without+/// `with_preview` the preview is left out: [`window`] has pinned it above the page.+fn slideshow_tab(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, with_preview: bool) {+ if with_preview {+ super::slide_layout::preview(app, ui, t, f32::INFINITY);+ ui.add_space(6.0);+ }super::slide_templates::section(app, ui, t);ui.add_space(6.0);playback_section(app, ui, t);diff --git a/crates/ui-egui/src/panels/slide_layout.rs b/crates/ui-egui/src/panels/slide_layout.rsindex 08b361441..802e62a5c 100644--- a/crates/ui-egui/src/panels/slide_layout.rs+++ b/crates/ui-egui/src/panels/slide_layout.rs@@ -24,6 +24,8 @@ use crate::widgets::register;pub const DEBOUNCE: f64 = 0.15;/// The preview's greatest width in points (less where the room is narrower).pub const PREVIEW_W: f32 = 300.0;+/// The least tall the preview is drawn.+pub const PREVIEW_MIN_H: f32 = 80.0;#[derive(Clone, Copy)]enum Unit {@@ -162,8 +164,9 @@ fn screen_aspect(ctx: &egui::Context) -> f64 {if r.y > 0.0 { (r.x / r.y) as f64 } else { 1.6 }}-/// The small composed slide of the active photo, with the margin guides when they are on.-pub fn preview(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {+/// The small composed slide of the active photo, with the margin guides when they are on. It is+/// at most `max_h` tall (but for [`PREVIEW_MIN_H`], and without counting its heading).+pub fn preview(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, max_h: f32) {heading(ui, t, "Preview");// the template the pointer is over in the Template Browser, else the settingslet template = super::slide_templates::hovered(ui.ctx()).and_then(|id| app.session.slide_template(&id).ok());@@ -176,7 +179,7 @@ pub fn preview(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens) {let ratio = s.aspect.ratio(screen_aspect(ui.ctx())) as f32;let own = SlideLook::of(&app.session).layout.aspect.ratio(screen_aspect(ui.ctx())) as f32;let w = ui.available_width().clamp(1.0, PREVIEW_W);- let room_h = (w / own).clamp(80.0, 320.0);+ let room_h = (w / own).clamp(PREVIEW_MIN_H, 320.0).min(max_h.max(PREVIEW_MIN_H));let (room, _) = ui.allocate_exact_size(vec2(w, room_h), Sense::hover());let (fit_w, fit_h) = if ratio >= w / room_h { (w, w / ratio) } else { (room_h * ratio, room_h) };let rect = Rect::from_center_size(room.center(), vec2(fit_w, fit_h));diff --git a/crates/ui-egui/src/tests_slideshow.rs b/crates/ui-egui/src/tests_slideshow.rsindex 911902ab2..890abde7a 100644--- a/crates/ui-egui/src/tests_slideshow.rs+++ b/crates/ui-egui/src/tests_slideshow.rs@@ -16,9 +16,13 @@ const T: Duration = Duration::from_secs(20);const SETTLE: Duration = Duration::from_secs(120);fn grid() -> Headless {+ grid_sized([1000.0, 700.0])+}++fn grid_sized(size: [f32; 2]) -> Headless {let services = Services { png: None, ..Default::default() };let app = LightcraftApp::new(lightcraft_engine::Session::with_demo(), services);- let mut h = Headless::new(app, [1000.0, 700.0], 1.0);+ let mut h = Headless::new(app, size, 1.0);h.step();h}@@ -259,12 +263,19 @@ fn a_photo_deleted_while_it_plays_does_not_stall_the_slideshow() {}/// Scroll the Settings ▸ Slideshow page until widget `id` is in view (in the middle of the room-/// for the page): the sections are taller than the dialog.+/// for the page): the sections are taller than the dialog. (The slide preview and its choice are pinned+/// above the page and are in view already.)fn reveal(h: &mut Headless, id: &str) {let find = |h: &Headless, w: &str| h.app.widgets.iter().find(|(i, _)| i == w).map(|(_, r)| *r);for _ in 0..40 {h.step();let room = find(h, "settings:pageRoom").expect("the Slideshow settings are open");+ // (the preview and its Photo / Intro / Ending choice are pinned above the page: always in+ // view, never scrolled to)+ let pinned = id == "slideshow:preview" || id.starts_with("button:settingsSlideshowPreviewShows-");+ if pinned && find(h, id).is_some_and(|w| w.bottom() <= room.top()) {+ return;+ }let dy = match find(h, id) {Some(w) if w.center().y >= room.top() + 10.0 && w.center().y <= room.bottom() - 10.0 => {// (in view and still: the page eases to where it was scrolled to)@@ -381,7 +392,7 @@ fn settings_shows_the_slide_layout_and_a_live_preview() {run(&mut h, "slideshow.layout", json!({"margins": 0.2, "backdropColor": "#00ff00"}));assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&Slot::SlidePreview).map(|t| t.key) != before));h.step();- // (the preview scrolls with the page: back to it)+ // (the preview is pinned above the page: in view already)reveal(&mut h, "slideshow:preview");let rect = h.app.widgets.iter().find(|(id, _)| id == "slideshow:preview").map(|(_, r)| *r).unwrap();let img = h.paint();@@ -744,3 +755,25 @@ fn template_browser_previews_on_hover_applies_and_manages_user_templates() {h.settle(SETTLE);let _ = std::fs::remove_dir_all(dir);}++/// Hovering a template in the Template Browser previews it in the slide preview, so the preview+/// must be in view while the templates (further down the page) are: it is pinned above the page,+/// under the tab bar, and does not scroll away with it.+#[test]+fn the_slide_preview_stays_in_view_while_the_templates_are_browsed() {+ // (900 x 560 is the least the desktop app's window is)+ for size in [[1000.0, 700.0], [900.0, 560.0]] {+ let mut h = grid_sized(size);+ run(&mut h, "view.slideshowOptions", json!({}));+ h.step();+ let find = |h: &Headless, w: &str| h.app.widgets.iter().find(|(i, _)| i == w).map(|(_, r)| *r);+ let tabs = find(&h, "button:settingsTab-slideshow").expect("the tab bar");+ // down to the last section of the page: the templates are far above the preview's old place+ reveal(&mut h, "button:slideshowExportPdf");+ let preview = find(&h, "slideshow:preview").expect("the preview is still drawn");+ let room = find(&h, "settings:pageRoom").unwrap();+ assert!(preview.height() > 40.0, "{size:?}: {preview:?}");+ assert!(preview.top() >= tabs.bottom(), "{size:?}: under the tab bar, not scrolled up behind it: {preview:?} {tabs:?}");+ assert!(preview.bottom() <= room.top() + 1.0, "{size:?}: above the page, not in it: {preview:?} {room:?}");+ }+}diff --git a/docs/whats-new.md b/docs/whats-new.mdindex 2f143d6a6..4bbbac16d 100644--- a/docs/whats-new.md+++ b/docs/whats-new.md@@ -4,14 +4,17 @@### Settings window- Settings is one size on every tab and stays where it is as you go through them; before, each tab made its own- size and the tabs moved under the pointer. The tabs stay in place while a long page scrolls, a page that goes on- below shows a scroll handle without the pointer on it, and each page remembers where it was scrolled to, also when Settings is closed and opened again.+ size and the tabs moved under the pointer. The tabs stay in place while a long page scrolls (in a very short+ LightCraft window, where the page has too little room to scroll by itself, the tabs and the page scroll together), a+ page that goes on below shows a scroll handle without the pointer on it, and each page remembers where it was+ scrolled to, also when Settings is closed and opened again.- Nothing in Settings runs off the side any more. A row with more choices than fit (the languages on General) wrapsonto further lines and a long label wraps in its column, where both used to widen the window: in a smallLightCraft window the labels and the Close button of General ended up off screen.- The Slideshow tab is one column like the other tabs, with the slide preview first, instead of a column beside the- preview that made Settings much wider on that tab. Pointing at a template no longer pushes its rows out from- under the pointer, and the Export buttons wrap.+ preview that made Settings much wider on that tab. The preview stays above the page while it scrolls, so pointing+ at a template further down still shows it there (in a very short window it scrolls with the page instead). Pointing+ at a template no longer pushes its rows out from under the pointer, and the Export buttons wrap.- A long folder (General ▸ Library ▸ Location, the folder Auto Import watches, the smart previews folder, a monitorprofile's file) is shortened to its last folders ("…/Pictures/Library") on one line; rest the pointer on it forthe whole path.