Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ui-egui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl LightcraftApp {
compare_windows: [None; 2],
compare_tiles: Default::default(),
compare_hold_until: f64::NEG_INFINITY,
survey_motion: Default::default(),
merge: merge::MergeState::default(),
import: None,
scan: None,
Expand Down
3 changes: 3 additions & 0 deletions crates/ui-egui/src/dialogs/settings/libraries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ fn switch_library(app: &mut LightcraftApp, path: &str) -> Result<Value, String>
app.ui.dialog = None;
}
app.renderer.forget_all();
// photo ids are local to a catalog: a survey tile of the next library must not glide from a
// cell of this one, nor keep its render slot
app.survey_motion = Default::default();
if let Err(err) = opened {
let Some(prev) = previous_dir else { return Err(err) };
return match app.session.open_library(&prev, false) {
Expand Down
1 change: 1 addition & 0 deletions crates/ui-egui/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ impl Headless {
|| self.app.import.is_some()
|| self.app.export.is_some()
|| self.app.session.denoise_busy()
|| self.app.survey_motion.moving(self.time)
|| !self.app.tasks.is_empty()
|| !self.app.synthetic.is_empty()
|| !self.app.pending_gestures.is_empty()
Expand Down
2 changes: 2 additions & 0 deletions crates/ui-egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ pub struct LightcraftApp {
pub(crate) compare_tiles: std::collections::HashMap<(u8, u64), region::RegionView>,
/// Until when (s) a pinch or scroll in Compare / Reference holds the windows there are.
pub(crate) compare_hold_until: f64,
/// Survey tiles gliding to new cells, and the render slot each surveyed photo keeps.
pub(crate) survey_motion: panels::compare::survey::SurveyMotion,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
/// Photo Merge dialog previews and background merges.
pub merge: merge::MergeState,
/// An import in progress (the import review dialog's batches).
Expand Down
69 changes: 39 additions & 30 deletions crates/ui-egui/src/panels/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::state::{ViewMode, Zoom};
use crate::theme::Tokens;
use crate::widgets::register;

pub mod survey;

/// Most photos a survey shows.
pub const SURVEY_MAX: usize = 48;

Expand Down Expand Up @@ -203,11 +205,27 @@ fn request_tile_renders(app: &mut LightcraftApp, id: PhotoId, slot: Slot, want:
if let Some(job) = app.session.render_job(id, rw.max(8), rh.max(8), false, true) {
app.renderer.request(slot, job, 60);
}
request_thumb(app, id);
}

/// Ask for the thumbnail a tile shows until its render is there.
fn request_thumb(app: &mut LightcraftApp, id: PhotoId) {
if let Some(job) = app.session.thumb_job(id, 256) {
app.renderer.request(Slot::Thumb(id), job, 30);
}
}

/// The photo's frame as shown: cropped, rotated and lens-corrected.
fn frame_of(photo: &lightcraft_catalog::Photo) -> lightcraft_pipeline::geometry::Frame {
lightcraft_pipeline::geometry::Frame::with_lens(
photo.width.max(1) as usize,
photo.height.max(1) as usize,
&photo.develop,
true,
photo.embedded_lens.as_ref(),
)
}

/// Draw one photo fitted into `area` (rendered at its display size into `slot`), with its caption
/// strip below. Returns the image rect and the click/drag response.
fn photo_tile(
Expand All @@ -226,13 +244,7 @@ fn photo_tile(
let Some(photo) = app.session.catalog.photo(id).cloned() else { return (area, area, resp) };
let caption_h = 26.0;
let img_area = Rect::from_min_max(area.min, pos2(area.right(), area.bottom() - caption_h));
let frame = lightcraft_pipeline::geometry::Frame::with_lens(
photo.width.max(1) as usize,
photo.height.max(1) as usize,
&photo.develop,
true,
photo.embedded_lens.as_ref(),
);
let frame = frame_of(&photo);
let aspect = frame.aspect() as f32;
let native = super::detail::output_px(&frame);
let mut img = super::detail::fit_rect(img_area, aspect, zoom, native, ppp, app.ui.pan);
Expand All @@ -249,7 +261,13 @@ fn photo_tile(
let texture_side = super::detail::texture_side(ui.ctx());
let want =
(img.width().max(img.height()).min(img_area.width().max(img_area.height()) * 4.0) * ppp).min(2560.0_f32.min(texture_side as f32)) as usize;
request_tile_renders(app, id, slot, want, aspect);
// a gliding survey tile asks for its render once it has landed, not one per size it passes on
// the way, and for its thumbnail (one size) meanwhile; tiles that stay put render as usual
if app.ui.view == ViewMode::Survey && app.survey_motion.gliding(id, ui.input(|i| i.time)) {
request_thumb(app, id);
} else {
request_tile_renders(app, id, slot, want, aspect);
}
// zoomed past what that render holds (1:1 to check focus): the part on screen as a window, as
// in the loupe. Compare and Reference only; Survey tiles are fit views.
let pane = match slot {
Expand Down Expand Up @@ -546,21 +564,6 @@ pub fn show_compare(app: &mut LightcraftApp, ui: &mut egui::Ui) {
ui.painter().line_segment([pos2(mid, area.top()), pos2(mid, area.bottom())], Stroke::new(1.0, Tokens::get(ui.ctx()).divider));
}

/// Columns for `n` tiles of aspect ~3:2 in `area`, maximizing the tile size.
pub fn survey_columns(n: usize, area: Rect) -> usize {
let mut best = (1, 0.0f32);
for cols in 1..=n.max(1) {
let rows = n.div_ceil(cols);
let w = area.width() / cols as f32;
let h = area.height() / rows as f32;
let s = w.min(h * 1.5);
if s > best.1 {
best = (cols, s);
}
}
best.0
}

pub fn show_survey(app: &mut LightcraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
let canvas = area_and_filmstrip(app, ui);
Expand All @@ -570,14 +573,20 @@ pub fn show_survey(app: &mut LightcraftApp, ui: &mut egui::Ui) {
return;
}
let area = canvas.shrink(14.0);
let cols = survey_columns(photos.len(), area);
let rows = photos.len().div_ceil(cols);
let (cw, ch) = (area.width() / cols as f32, area.height() / rows as f32);
for (i, id) in photos.iter().enumerate() {
let (c, r) = (i % cols, i / cols);
let cell = Rect::from_min_size(pos2(area.left() + c as f32 * cw, area.top() + r as f32 * ch), vec2(cw, ch)).shrink(6.0);
let aspects: Vec<f32> = photos.iter().map(|id| app.session.catalog.photo(*id).map_or(1.5, |p| frame_of(p).aspect() as f32)).collect();
let cells = survey::cells(&aspects, area);
let now = ui.input(|i| i.time);
let placed = app.survey_motion.place(&photos, &cells, area, ui.ctx().cumulative_frame_nr(), now);
let (slots, freed) = app.survey_motion.assign_slots(&photos);
for s in freed {
app.renderer.release(Slot::Compare(s));
}
if app.survey_motion.moving(now) {
ui.ctx().request_repaint();
}
for ((id, cell), slot) in photos.iter().zip(placed).zip(slots) {
// (Survey tiles are fit views with no windows: what counts is the photo as painted)
let (_, img, resp) = photo_tile(app, ui, *id, Slot::Compare(i as u8), cell, "", Zoom::Fit);
let (_, img, resp) = photo_tile(app, ui, *id, Slot::Compare(slot), cell.shrink(survey::GAP), "", Zoom::Fit);
if app.session.selection.active == Some(*id) {
app.image_rect = Some(img);
}
Expand Down
Loading
Loading