Skip to main content

Module compare

Module compare 

Source
Expand description

One surface for one to many images: one image is a loupe (the whole surface), several are a survey, side by side in a grid that grows with their count (four in a square, six in three columns), with their zoom and pan synced (an option), an active image and a “best” marker.

Each pane is an image canvas with the image viewport’s own gestures, implemented once (egui_pop_core::pointer::view) and read from the pointer profile in force: the wheel, a scroll and a pinch zoom around the pointer or pan (the wheel alone zooms with darktable’s profile, Alt and the wheel with Photoshop’s, where Ctrl and the wheel pan sideways, Ctrl and the wheel with the default one), a drag pans (any drag with Space held), a click and a double click run the profile’s view action (darktable’s middle click cycles 100 %, 200 % and fit; its double click asks to leave, Intent::Leave), and with the keyboard + and - step the zoom, 0 fits, 1 shows 100 % and 2 200 % in the active pane. The zoom counts physical pixels per image pixel as in the viewport (View): it goes below fit and the wheel stops at 100 %. Synced, every pane shows the same View, its centre taken to the same place of each photo, whatever its size.

The application owns the list of images: the surface says what the user asked for, as Intents in CompareOutput::intents: a pane made active (a click, the arrow keys, the keyboard focus), images dropped on the surface to add at a place, a pane taken out (its close button, Delete or Backspace on the active pane, a pane dragged out and let go over nothing), a pane dragged to another place. Drops go through the application’s drag session (egui_pop_api::bus::drag, feature api), across windows too, with the payload the application names (CompareView::carry). The images come from the library’s ThumbSource; the application says which one is the best and hears when the user marks another (CompareOutput::best).

use egui_pop_views::library::compare::{CompareState, CompareView, Intent, Pane};
use egui_pop_views::library::grid::{Thumb, ThumbSource};

struct Thumbs;

impl ThumbSource<u64> for Thumbs {
    fn thumb(&self, _: &u64, _: u32) -> Thumb {
        Thumb::Pending { average: None }
    }
}

struct Compared {
    keys: Vec<u64>,
    active: Option<u64>,
    best: Option<u64>,
}

fn ui(ui: &mut egui::Ui, state: &mut CompareState, c: &mut Compared) {
    let panes: Vec<Pane<u64>> = c
        .keys
        .iter()
        .map(|k| Pane::new(*k, format!("IMG_{k:04}")))
        .collect();
    let out = CompareView::new("compare")
        .best(c.best)
        .active(c.active)
        .removable(true)
        .show(ui, state, &panes, &Thumbs);
    if let Some(key) = out.best {
        c.best = Some(key);
    }
    for intent in out.intents {
        match intent {
            Intent::Active { key } => c.active = Some(key),
            Intent::Remove { key } => {
                if let Some(i) = c.keys.iter().position(|k| *k == key) {
                    c.keys.remove(i);
                    state.removed(i);
                }
            }
            _ => {}
        }
    }
}

Structs§

CompareOutput
What CompareView::show returns.
CompareState
The comparison’s state: one view shared by every pane when synced, else one per pane, by the pane’s place; and each pane’s gestures.
CompareView
The comparison view.
Pane
One image to compare.

Enums§

Intent
What the user asked of the comparison’s list, which the application owns: it edits its list (or refuses), and shows it again.

Constants§

MAX_PANES
How many panes a comparison shows unless CompareView::max_panes says otherwise: four, in a square.
PANE_LIMIT
The most panes a comparison can show (CompareView::max_panes).

Functions§

layout
The panes’ places for n panes in rect, gap apart, row by row: one fills it, two and three side by side, four in a square, more in the grid that shows a 3:2 image the largest.