Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The photo library

egui_pop::views::library (crate egui-pop-views) holds the widgets of a photo library, the kind of view used to import, cull and sort images:

  • a thumbnail grid, virtualised (a hundred thousand images cost what a screenful does), and a filmstrip, the same view in one row, sharing the grid’s selection;
  • ratings (0 to 5 stars), colour labels and pick or reject flags, drawn over the thumbnails and edited with the mouse, the keys of a culling keymap (Lightroom’s), or their own widgets;
  • stacks, collapsed to their top image with a count, or expanded;
  • a comparison of one to many images (a loupe, a survey), zoom and pan synced, images dragged in and out;
  • tag chips and a tag input completing from the application’s tags;
  • a search field with filter chips, giving the application a structured filter.

The application owns its images, their marks, their tags and the filtering. The widgets show what the application gives them and say what the user asked for, in their output and as steps (ADR 0011) a plugin may veto, redirect or follow. Agents drive them through commands.

The gallery’s library page shows all of it on 10 000 synthetic images.

The grid and the filmstrip

The application implements two traits:

use egui_pop::views::library::{Badge, LibraryItems, Marks, Stack, Thumb, ThumbSource};

struct Shoot { /* the application's images */ }

impl LibraryItems<u64> for Shoot {
    fn len(&self) -> usize { todo!() }
    fn key(&self, index: usize) -> u64 { todo!() }      // the selection is kept by key
    fn label(&self, index: usize) -> String { todo!() } // accessible name and caption
    fn marks(&self, index: usize) -> Marks { todo!() }  // rating, labels, flag
    fn stack(&self, index: usize) -> Option<Stack<u64>> { None }
    fn badges(&self, index: usize) -> Vec<Badge> { Vec::new() }
    fn revision(&self) -> u64 { 0 } // changes when stacks change at the same count
}

struct Thumbs { /* a cache, a loader thread */ }

impl ThumbSource<u64> for Thumbs {
    fn thumb(&self, key: &u64, size: u32) -> Thumb {
        // Ready { texture, size }, or Pending { average } while it loads
        // (and start loading it), or Failed.
        todo!()
    }
    fn wanted(&self, keys: &[u64], size: u32) {
        // The images in view this pass: load these first.
    }
}

An application that already feeds the file browser’s thumbnails (files::browser::ThumbnailProvider) needs no second source: wrap it for the frame with library::thumbs::ProviderThumbs, saying which file each key is. It begins the provider’s frame when made and ends it when dropped, so draw the views between the two:

use egui_pop::views::library::thumbs::ProviderThumbs;

let thumbs = ProviderThumbs::begin(ui.ctx(), provider, |key: &u64| shoot.entry(*key));
grid.show(ui, state, &shoot, &thumbs);
drop(thumbs);

Only the cells in view are built: LibraryItems is asked about those alone, and ThumbSource::thumb too. A thumbnail not there yet is drawn as a placeholder: the image’s average colour when the source knows it (Pending { average: Some(..) }, from an embedded preview, a thumbhash or a cache), else a skeleton block, never a spinner. The source loads asynchronously and asks egui for a repaint when a thumbnail arrives.

When the application knows how many images a query gives before its rows arrive, ThumbGrid::expected_len(total) lays out that many cells at once, so the scroll bar and the layout are final and nothing moves as rows come in. The cells the items still lack are pending cells, after the real ones: a skeleton, said as “Loading image N of M”. They are not items: no selection, focus, Enter, drag or signal, Ctrl+A and the rubber band leave them out, and the keyboard stops at the last real image. Each arriving image takes the next pending cell; items as many as expected, or more, leave none.

use egui_pop::views::library::{CullKeymap, LibraryState, Signal, ThumbGrid};

fn ui(ui: &mut egui::Ui, app: &egui_pop::api::AppHandle, state: &mut LibraryState<u64>,
      shoot: &Shoot, thumbs: &Thumbs) {
    let keymap = CullKeymap::lightroom().auto_advance(true);
    let grid = ThumbGrid::new("grid").app(app).keymap(keymap.clone()).height(400.0)
        .show(ui, state, shoot, thumbs);
    let strip = ThumbGrid::filmstrip("strip").app(app).keymap(keymap).height(96.0)
        .show(ui, state, shoot, thumbs);
    for signal in grid.signals.into_iter().chain(strip.signals) {
        match signal {
            Signal::Rate { keys, rating } => { /* rate them */ }
            Signal::Label { keys, label, on } => { /* label them */ }
            Signal::Flag { keys, flag } => { /* flag them */ }
            _ => {}
        }
    }
}

LibraryState::new("shoot") names the library in steps and commands; the grid and the filmstrip drawn over the same state share its selection, its stacks and the cursor. The state also keeps the thumbnails’ size (size, set_size).

Keys and pointer

The view takes the keyboard focus as a whole (a click on a cell gives it). Its keys, read after the key dispatcher (a key the application binds to a command never reaches it):

KeysGridFilmstrip
Left, Rightthe previous, the next imagethe same
Up, Downthe row above, below (same column)nothing
Page Up, Page Downa screenful of rowsa screenful of cells
Home, Endthe first, the last imagethe same
Shift with a moveextends the selection from the anchorthe same
Ctrl with a movemoves the cursor alonethe same
Space, Ctrl+Spaceselects the cursor’s image, toggles itthe same
Ctrl+Aselects every image shownthe same
Enter (a double click)Activate the cursor’s imagethe same
Ctrl and the wheel, + and -the thumbnails’ sizenothing

The pointer: a click selects, Shift extends a range, Ctrl toggles; a drag across the cells draws a rubber band selecting what it touches (with Ctrl or Shift held at its start, added to the selection). A cell’s stars rate it (the star of its rating clears it; under the pointer they preview the value a click gives, Rating stars) and its stack chip expands or collapses the stack. Marks made on a selected cell apply to the whole selection.

The culling keymap

CullKeymap::lightroom() binds Lightroom Classic’s culling keys (also Capture One’s for ratings):

KeysAction
0 to 5the rating (0 clears it)
P, X, Upick, reject, unflag
6, 7, 8, 9toggle red, yellow, green, blue (purple has no key)
Sexpand or collapse the stack under the cursor
+, -, =larger, smaller thumbnails

auto_advance(true) moves the cursor to the next image after a rating, a flag or a label (Lightroom’s Caps Lock mode). bind(key, action) changes one binding and CullKeymap::none() has none. A mark applies to the selection, else to the cursor’s image.

These are view keys, like the arrows: they do not appear in the shortcut editor. An application wanting them rebindable there declares its own commands and runs library.rate and the other steps through change.

Overlays and stacks

Over each thumbnail (from 64 points up): the flag (a pennant, or a cross, the image dimmed when rejected) in the top left corner, the labels in the top right one, the stars in the bottom left one (empty stars as outlines under the pointer, or on every cell with ThumbGrid::empty_stars(EmptyStars::Always)), the badges (a short text, Badge::new("RAW"), or an icon of the registry, Badge::icon("phosphor:plugs", "offline"), toned with Tone) in the bottom right one, drawn as indicators the way the file browser draws its marks (MarkChip::from(badge) gives the browser’s chip; agents read them as library.badge:<image>:<text>, an icon badge by its name). A cell’s accessible name says its badges after the image’s name (IMG_0001.CR3 · offline); Badge::named names a terse text. Colour labels are same-shape swatches, as in Lightroom and darktable; LabelStyle::Shape gives them a shape each (circle, triangle, square, diamond, hexagon), so they never read by colour alone, for colour-blind users. The application’s choice (LabelStyle::set(ctx, Some(LabelStyle::Shape)), from a setting say) wins over the theme’s (library.label-style: swatch or shape); the marks bar and the grid’s badges both follow it.

A stack’s members follow their top image in the application’s order, each saying Stack { top, count }. Collapsed, the top image shows with its count and a chevron; expanded, the members follow it with a bar on their left. library.stack expands or collapses one (the chevron, S, a command); LibraryState::set_expanded does it without a step.

Colours

The stars are the kit’s rating-star (Rating stars). The other marks’ colours come from the theme, through optional component tokens falling back on system ones: library.pick (text.strong), library.reject (status.danger), library.label-red, -yellow, -green, -blue (the status colours) and -purple, library.band. LibraryTokens::of(ctx) reads them. The boxes they sit on are the kit’s (docs/kit.md): thumb-cell, thumb-layer (a rejected image’s veil, a stack member’s bar), thumb-overlay-badge, pill (badges by tone), tag-chip, mark-toggle, search-field and compare-pane.

The library grid in a file browser

LibraryGridMode (in library::mode, with the api feature) is the grid as one of a FileBrowser’s view modes: a folder shown the way the Library shows photos. It lays the entries out as the browser’s thumbnails mode does, so the zoom (a count per row), the rubber band, the arrows, Page Up and Page Down, Home and End, Enter and quick look behave the same. Over each file’s cell it draws the overlays above: the flag, the labels, the stars and a rejected image dimmed. A screen reader hears the marks as the cell’s description (“Rated 4 of 5, Pick, Red”).

let signals = LibrarySignals::default();
let modes = ViewModes::built_in();
LibraryGridMode::new(move |entry| marks_of(&entry.path))
    .keymap(CullKeymap::lightroom().auto_advance(true))
    .signals(signals.clone())
    .register(&modes)?;
let browser = FileBrowser::new("photos", source, folder).with_modes(modes);
// Each frame, after drawing the browser:
for signal in signals.drain() { apply(signal) } // Rate, Flag, Label by path

The application owns the marks: new takes what gives each entry’s Marks. The culling keys (0 to 5, P, X, U, 6 to 9) act on the selection, else on the focused entry, and the browser does not type them ahead. They do not change the marks. They give Signal<PathBuf> (Rate, Flag, Label) into the LibrarySignals queue, and the application applies them. With auto-advance, the focus then moves on to the next file.

The mode draws over the browser’s own cell, so the browser’s badges, chips and groups stay. A grouping (FileBrowser::with_grouping) stands for stacks: a RAW with its JPEG is one entry with its members’ chip.

What it leaves to ThumbGrid: expanding a stack, clicking a cell’s stars, the stack and zoom keys (S, + and -: the browser has its own zoom), and running the marks as library.* steps an application can veto. An application that needs those draws a ThumbGrid.

Marks outside the grid

RatingStars, ColorLabels and FlagToggle edit one image’s marks (a metadata panel, a loupe): each takes the current value and returns the one asked for in changed. Focused, the stars take 0 to 5, the arrows, Home and End; each label and flag is a toggle button, named for assistive technologies, its tooltip saying what it is (“Red label”, “Pick”). keys(&keymap) adds the key a CullKeymap binds to it (“Red label (6)”, “Pick (P)”); tooltip(label, text) puts the application’s own text instead (its own commands’ keys, say). The stars are the shared egui_pop::core::rating::RatingStars (Rating stars), as on the cells.

To run such a change through the library’s steps (so hooks see it as they see the grid’s), call change:

use egui_pop::views::library::{Change, Signal, change};

let signal = change(Some(app), "shoot", Change::Rate { keys: vec![12], rating: 4 });
if let Signal::Rate { keys, rating } = signal { /* apply */ }

Tags

TagChip::new("beach").removable(true).show(ui) draws a chip and says whether its remove button was clicked. TagInput shows the tags as removable chips and a field: Enter, a comma or Tab adds a tag, Up and Down move in the completions, Backspace in the empty field removes the last tag. Completions come from a TagSource (a Vec<String> is one, matching fuzzily); the output’s added and removed say what changed.

Search and filter chips

SearchField::new("shoot").app(app).show(ui, &mut search) returns the filter whenever it changes, as a Filter:

pub struct Filter {
    pub text: String,              // words, in the name or a tag
    pub min_rating: Option<u8>,    // at least this many stars
    pub labels: Vec<ColorLabel>,   // one of these labels
    pub flags: Vec<Flag>,          // one of these flags
    pub tags: Vec<String>,         // all of these tags
    pub from: Option<String>,      // YYYY-MM-DD, included
    pub to: Option<String>,
}

Criteria typed in the field (rating>=3 or rating:3, label:red, flag:pick, tag:beach or #beach, date:2024-06-01..2024-06-30, from:…, to:…) filter as they are typed and become chips on Enter; the + menu adds a rating, a label or a flag; each chip has its remove button, and the clear button removes everything (the + button, the clear button and each chip’s remove button show their name as a tooltip). Filter::matches does the usual matching on a Candidate (name, marks, tags, date); Filter::parse, chips and remove are there for the application’s own fields.

The comparison

CompareView::new("compare").synced(true).best(best).active(active).show(ui, &mut state, &panes, &thumbs) shows the Panes the application lists: one is a loupe filling the surface, two to four sit side by side (four in a square), more tile in the grid that shows them the largest (six in three columns), up to max_panes (four by default, PANE_LIMIT at most). Each pane is an image canvas with the image viewport’s own gestures (egui_pop_core::pointer::view, one implementation for both): the wheel, a scroll and a pinch zoom or pan as the pointer profile says, a drag pans (any drag with Space held), a click and a double click run the profile’s view action (Intent::Leave for darktable’s double click), and +, -, 0, 1 and 2 zoom the active pane. The zoom counts physical pixels per image pixel against Pane::size (by default the thumbnail’s); synced, every pane shows the same View, its centre at the same place of each photo. Each pane has a “best” toggle; the output’s best is the image the user marked, and the application says which one is (best) and which one is active (active, outlined).

The application owns the list; the surface says what the user asked, in the output’s intents: Intent::Active (a click, the arrows, Home and End), Intent::Remove (with removable(true): each pane’s close button, Delete or Backspace on the active one), Intent::Add, Intent::Move and Intent::Leave. With carry(kind, pack, unpack), the surface is a target of the application’s drag session (egui_pop_api::bus::drag), in any of its windows: a payload unpack reads images from, let go on it, gives Intent::Add with the place shown by a bar while over it; a pane’s name drags its image out as pack makes it, let go over nothing it gives Intent::Remove, let go on the surface Intent::Move. Keep the state’s per-pane views with the list through CompareState::removed, inserted and moved. The output’s panes says where each pane was drawn (compare::layout gives the same places).

Steps

LibraryPlugin declares them; connect it when the views run with an application (.app(app)). Each runs from the grid, the filmstrip, the search field, change, or a command.

StepArgumentsDefault
library.selectlibrary, keys, cursorsets the selection
library.ratelibrary, keys, ratingreports it: the application rates its images
library.labellibrary, keys, label, onreports it
library.flaglibrary, keys, flag (pick, reject, none)reports it
library.taglibrary, keys, add, removereports it
library.stacklibrary, stack (the top image’s key), expandedexpands or collapses the stack
library.filterlibrary, filtersets the search field’s filter

A before-hook vetoes a mark (the view’s output then holds Signal::Vetoed) or redirects it (Redirect with other arguments: a rating capped, other keys); the signal carries what ran. An after-hook follows them, for example to write the marks to the application’s catalogue.

ctx.before(egui_pop::views::library::plugin::LIBRARY_FLAG, |_, args| {
    if args["flag"] == "reject" && read_only() {
        Before::Veto("this collection is read-only".into())
    } else {
        Before::Go
    }
});

Commands (agents)

Each acts on library (else the library that last had the focus) and on keys (else its selection), and queues its step for the view, which runs it at its next pass as if the user had asked:

CommandArguments
library.selectkeys, cursor
library.raterating (0 to 5)
library.labellabel, on (else toggled from the cursor’s image)
library.flagflag
library.tagadd, remove
library.filterfilter ({} clears it)

The debug bridge’s libraries collector lists the libraries drawn, their count, selection, cursor, filter and waiting requests.

What was checked (2026-10-13)

CrateVersion, licenceWhat it hasDecision
egui_virtual_list0.12.0, MIT, egui 0.36A list of items of varying height, measured as they are drawn and cached; a row may hold several items (a custom layout); no scrolling to an item, no keys, hides itself while resizingOwn the grid: its cells are all the same size, so the cells in view, a row’s position and the cursor’s are arithmetic, and End reaches the hundred-thousandth image at once without measuring the rows before it. egui_virtual_list stays the candidate for lists of rows of varying height (a history, a log)
egui_extras0.36.2, MIT OR Apache-2.0TableBuilder, StripBuilder, image loaders, a date pickerSkip: nothing for a grid of thumbnails; its image loaders are the application’s business (the grid takes textures from a ThumbSource)
egui ScrollArea::show_viewportegui 0.36, MIT OR Apache-2.0The visible part of a scrolled areaUsed: the grid lays its cells out in it and builds those in view, as the list and the tree do

No code was taken from either crate.

Gaps

  • The culling keys are the view’s own (rebinding them is CullKeymap::bind); they are not commands in the shortcut editor.
  • No drag and drop of images out of the grid (to a collection, to reorder); a drag draws the rubber band.
  • The rubber band does not scroll the grid when it reaches an edge.
  • The comparison draws the thumbnail it is given, whatever the zoom: the application gives larger ones for it.
  • Stacks are one level deep, and their members must follow their top image in the application’s order.