LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Merge PR #313
Claude9e9e45b3c7ba
diff --cc crates/ui-egui/src/panels/detail.rsindex c1257fafa,b15a7fd88..57a1a2024--- a/crates/ui-egui/src/panels/detail.rs+++ b/crates/ui-egui/src/panels/detail.rs@@@ -125,14 -125,60 +125,68 @@@ pub(crate) fn fit_rect(area: Rect, aspeRect::from_center_size(c, vec2(w, h))}+/// Fit a decoded image inside the frame calculated from catalog metadata. Unsupported RAWs can+/// only show their embedded camera JPEG, whose crop and aspect ratio can differ from that metadata.+pub(crate) fn fit_texture_rect(area: Rect, size: [usize; 2]) -> Rect {+ let (w, h) = (size[0].max(1) as f32, size[1].max(1) as f32);+ let scale = (area.width() / w).min(area.height() / h);+ Rect::from_center_size(area.center(), vec2(w * scale, h * scale))+}++ /// Keep the viewport inside the photo; axes smaller than the viewport stay centred.+ fn bounded_pan(area: Rect, size: egui::Vec2, pan: (f32, f32)) -> (f32, f32) {+ let bound = |visible: f32, image: f32, centre: f32| {+ let centre = if centre.is_finite() { centre } else { 0.5 };+ if image > visible.max(0.0) {+ let half = visible.max(0.0) / image / 2.0;+ centre.clamp(half, 1.0 - half)+ } else {+ 0.5+ }+ };+ (bound(area.width(), size.x, pan.0), bound(area.height(), size.y, pan.1))+ }++ pub(crate) fn pan_image(app: &mut LightcraftApp, area: Rect, img: Rect, delta: egui::Vec2) {+ let centre = area.center() - img.min - delta;+ let pan = bounded_pan(area, img.size(), (centre.x / img.width().max(1.0), centre.y / img.height().max(1.0)));+ let _ = app.run("view.navigate", json!({"pan": pan}));+ }++ /// Native pinch (also modifier-wheel zoom) and two-finger scroll, scoped to this image view.+ pub(crate) fn navigate_gesture(app: &mut LightcraftApp, ui: &mut egui::Ui, resp: &egui::Response, area: Rect, img: Rect, native: [usize; 2]) -> bool {+ if !resp.hovered() {+ return false;+ }+ let (factor, delta, anchor) =+ ui.input(|i| (i.zoom_delta(), i.translation_delta(), i.multi_touch().map(|t| t.center_pos).or(i.pointer.hover_pos())));+ if !factor.is_finite() || factor <= 0.0 || !delta.is_finite() || (factor == 1.0 && delta == egui::Vec2::ZERO) {+ return false;+ }+ let Some(anchor) = anchor.filter(|p| area.contains(*p)) else { return false };+ let ppp = ui.ctx().pixels_per_point();+ let aspect = img.width() / img.height().max(1.0);+ let fit = fit_rect(area, aspect, Zoom::Fit, native, ppp, (0.5, 0.5));+ let fit_pct = fit.width() * ppp * 100.0 / native[0].max(1) as f32;+ let mut zoom = app.ui.zoom;+ let size = if factor != 1.0 {+ // Start at the displayed scale (including Fit/Fill and an interrupted click animation).+ let pct = (img.width() * ppp * 100.0 / native[0].max(1) as f32 * factor).clamp(fit_pct.min(800.0), 800.0);+ zoom = if pct <= fit_pct { Zoom::Fit } else { Zoom::Percent(pct) };+ fit_rect(area, aspect, zoom, native, ppp, (0.5, 0.5)).size()+ } else {+ img.size()+ };+ // The image point under the pointer remains there as its size changes, then follows the pan.+ let point = (anchor - img.min) / img.size();+ let offset = area.center() - anchor - delta;+ let pan = bounded_pan(area, size, (point.x + offset.x / size.x.max(1.0), point.y + offset.y / size.y.max(1.0)));+ let _ = app.run("view.navigate", json!({"zoom": zoom, "pan": pan}));+ ui.input_mut(|i| i.smooth_scroll_delta = egui::Vec2::ZERO);+ ui.ctx().request_repaint();+ true+ }+/// Ease the loupe rect toward `target` while a click-zoom animation runs; otherwise follow it exactly.fn animated_rect(ctx: &egui::Context, anim: &mut bool, target: Rect) -> Rect {let t = if *anim { 0.22 } else { 0.0 };@@@ -199,20 -245,19 +253,31 @@@ pub fn show(app: &mut LightcraftApp, ui_ => vec![area],};let main_area = *areas.last().unwrap_or(&area);+ let visible_texture_aspect = app+ .renderer+ .textures+ .get(&Slot::Main)+ .filter(|t| t.photo == id)+ .or_else(|| app.renderer.textures.get(&Slot::Preview).filter(|t| t.photo == id))+ .or_else(|| app.renderer.thumb(id))+ .map(|tex| tex.size[0].max(1) as f32 / tex.size[1].max(1) as f32);+ // Follow the texture only where it really differs (an unsupported raw's embedded JPEG with+ // another crop): a texture's whole-pixel size is a little off the exact aspect, and the crop+ // tool's overlays need the frame's own geometry.+ let display_aspect = visible_texture_aspect.filter(|a| !crop_tool && (a / aspect - 1.0).abs() > 0.02).unwrap_or(aspect);- let target_rect = fit_rect(main_area, display_aspect, app.ui.zoom, native, ppp, app.ui.pan);- let img_rect = animated_rect(ui.ctx(), &mut app.ui.zoom_anim, target_rect);+ let resp = ui.interact(canvas, egui::Id::new("loupe"), Sense::click_and_drag());- let mut target_rect = fit_rect(main_area, aspect, app.ui.zoom, native, ppp, app.ui.pan);++ let mut target_rect = fit_rect(main_area, display_aspect, app.ui.zoom, native, ppp, app.ui.pan);+ let mut img_rect = animated_rect(ui.ctx(), &mut app.ui.zoom_anim, target_rect);+ let mut navigating = false;+ for &view_area in &areas {- let view_img = if view_area == main_area { img_rect } else { fit_rect(view_area, aspect, app.ui.zoom, native, ppp, app.ui.pan) };++ let view_img = if view_area == main_area { img_rect } else { fit_rect(view_area, display_aspect, app.ui.zoom, native, ppp, app.ui.pan) };+ if navigate_gesture(app, ui, &resp, view_area, view_img, native) {+ navigating = true;- target_rect = fit_rect(main_area, aspect, app.ui.zoom, native, ppp, app.ui.pan);++ target_rect = fit_rect(main_area, display_aspect, app.ui.zoom, native, ppp, app.ui.pan);+ img_rect = target_rect;+ break;+ }+ }app.image_rect = Some(img_rect);// request renders: the loupe at display resolution (drafts during drags)let interacting = app.session.interaction.is_some();diff --cc docs/parity.mdindex 6c5f92a55,ccd24528e..97c1b55db--- a/docs/parity.md+++ b/docs/parity.md@@@ -23,10 -23,10 +23,10 @@@ and prints the summary; `cargo xtask pa|---|---:|---:|---:|---:|---:|---:|| A. Import (IMP) | 11 | 3 | 1 | 1 | 3/5 (60%) | 5/5 (100%) || B. Library management (LIB) | 22 | 2 | 1 | 2 | 9/9 (100%) | 9/9 (100%) |- | C. Views & navigation (VIEW) | 16 | 0 | 1 | 0 | 9/9 (100%) | 4/4 (100%) |+ | C. Views & navigation (VIEW) | 15 | 1 | 1 | 0 | 8/9 (89%) | 4/4 (100%) || D. Search & filter (FILT) | 11 | 1 | 1 | 0 | 4/4 (100%) | 4/4 (100%) || E. Metadata (META) | 5 | 1 | 0 | 0 | 2/2 (100%) | 2/2 (100%) |-| F. Edit panel — global adjustments (EDIT) | 42 | 1 | 5 | 1 | 28/28 (100%) | 13/14 (93%) |+| F. Edit panel — global adjustments (EDIT) | 41 | 2 | 5 | 1 | 27/28 (96%) | 13/14 (93%) || G. Profiles (PROF) | 6 | 2 | 3 | 0 | 3/4 (75%) | 2/3 (67%) || H. Crop & rotate (CROP) | 9 | 0 | 0 | 1 | 6/6 (100%) | 3/3 (100%) || I. Remove / healing (REM) | 7 | 1 | 2 | 2 | 4/4 (100%) | 2/3 (67%) |@@@ -171,8 -175,8 +175,8 @@@ under the UI command that wraps it (a n| LR-VIEW-DETAIL | Single-photo view | P0 | ✅ | `cmd:view.detail`, `crates/ui-egui/src/panels/detail.rs` | || LR-VIEW-EDIT | Edit view | P0 | ✅ | `cmd:panel.edit` | || LR-VIEW-FULLSCREEN | Full-screen preview | P1 | ✅ | `cmd:view.fullScreenPreview`, `cmd:view.enterFullScreen` | photo on black, arrows step, Esc exits; ⇧⌘F window full screen |-| LR-VIEW-FILMSTRIP | Filmstrip | P0 | ✅ | `cmd:view.filmstrip`, `crates/ui-egui/src/panels/detail.rs` | the photo context menu on right-click; the mouse wheel scrolls it sideways; it follows the active photo only when that changes (centred if off screen), so a scrolled strip stays put |+| LR-VIEW-FILMSTRIP | Filmstrip | P0 | ✅ | `cmd:view.filmstrip`, `crates/ui-egui/src/panels/detail.rs` | the photo context menu on right-click; the mouse wheel scrolls it sideways; it follows the active photo only when that changes (centred if off screen), so a scrolled strip stays put; every selected photo is highlighted, the active one framed in white, as in the grid |- | LR-VIEW-ZOOM | Zoom & pan | P0 | ✅ | `cmd:view.zoomFit`, `cmd:view.zoom100`, `cmd:view.zoomIn`, `cmd:view.zoomOut`, `cmd:view.zoomToggle`, `cmd:view.clickZoom` | steps 25–800 % (not 6–1600 %); Fill only in the bottom bar; a click on the photo (and Z / Space) eases to the click-zoom ratio (1:1 default, 2:1, 3:1, 4:1, 8:1 in the bottom bar) |+ | LR-VIEW-ZOOM | Zoom & pan | P0 | 🟡 | `cmd:view.zoomFit`, `cmd:view.zoom100`, `cmd:view.zoomIn`, `cmd:view.zoomOut`, `cmd:view.zoomToggle`, `cmd:view.clickZoom`, `cmd:view.navigate`, `crates/ui-egui/src/panels/detail.rs`, `crates/ui-egui/src/headless.rs` | continuous native pinch / modifier-wheel zoom (Fit–800%, anchored under the pointer), two-finger scroll / touch pan with edge limits; Detail (including tools, Before/After and full-screen preview), Compare and Reference; fractional percentages preserve small gestures; image, picker and targeted-adjustment cursors stay steady between gesture events; keyboard steps 25–800 % (not 6–1600 %); Fill in the bottom bar; click / Z / Space eases to the chosen ratio (1:1 default, 2:1, 3:1, 4:1, 8:1). Missing: native-resolution detail beyond the configured whole-image preview size (2,560 px default); no visible-region tiles || LR-VIEW-NAVIGATOR | Navigator mini map | P1 | ✅ | `cmd:view.navigator`, `crates/ui-egui/src/panels/detail.rs` | shown while zoomed (bottom right); click/drag pans || LR-VIEW-BEFOREAFTER | Before / after | P0 | ✅ | `cmd:view.showOriginal`, `cmd:view.beforeAfter`, `cmd:view.beforeAfterSplit`, `cmd:view.beforeAfterTopBottom`, `cmd:view.beforeAfterSplitTopBottom`, `cmd:beforeAfter.setBefore`, `cmd:beforeAfter.copyAfterToBefore`, `cmd:beforeAfter.copyBeforeToAfter`, `cmd:beforeAfter.swap`, `cmd:beforeAfter.resetBefore` | all four layouts; before = the import state (defaults + import preset) or a chosen history step / version / the current settings; copy and swap (View → Before/After Settings, History row menu). The chosen before lasts for the session || LR-VIEW-COMPARE | Compare two photos | P1 | ✅ | `cmd:view.compare`, `cmd:compare.swap`, `cmd:compare.makeSelect`, `crates/ui-egui/src/panels/compare.rs` | select / candidate, synced zoom + pan, arrows move the candidate; no zoom-link toggle |