Skip to main content

Module grid

Module grid 

Source
Expand description

A virtualised thumbnail grid, and the filmstrip (the same view in one row), over images the application lists and thumbnails it supplies.

The application gives:

  • its images (LibraryItems): how many, each one’s key, name, marks, stack and badges. Only the cells in view are asked for, so a hundred thousand images cost what a screenful does;
  • their thumbnails (ThumbSource), asynchronously: a thumbnail not there yet is Thumb::Pending and the cell shows a placeholder (the image’s average colour when known, else a skeleton block); the source is told which images are in view (ThumbSource::wanted) so it loads those first, and asks for a repaint when one arrives.

The grid does the layout (the zoom, Zoom, is a count of thumbnails per row that share the panel’s width, so it survives a resize, or with ThumbGrid::resize a size that keeps on a resize and gains columns: Ctrl and the wheel, or + and -), the keyboard (arrows, Page Up and Page Down, Home and End, Space, Ctrl+A, Enter), the selection (a click, Shift for a range, Ctrl to toggle, a rubber band dragged across the cells), the culling keys (CullKeymap: ratings, flags, labels, auto-advance), the overlays (rating, labels, flag, a stack’s count and chevron, badges) and the stacks (collapsed to their top image, or expanded). Every change runs a step (see plugin); the marks are the application’s, which applies the output’s signals.

A grid and a filmstrip drawn over the same LibraryState share its selection and its stacks.

use egui_pop_views::library::grid::{LibraryItems, LibraryState, Thumb, ThumbGrid, ThumbSource};
use egui_pop_views::library::marks::Marks;

struct Shoot(Vec<(u64, String, u8)>);

impl LibraryItems<u64> for Shoot {
    fn len(&self) -> usize { self.0.len() }
    fn key(&self, i: usize) -> u64 { self.0[i].0 }
    fn label(&self, i: usize) -> String { self.0[i].1.clone() }
    fn marks(&self, i: usize) -> Marks { Marks { rating: self.0[i].2, ..Marks::default() } }
}

struct Thumbs;

impl ThumbSource<u64> for Thumbs {
    fn thumb(&self, _key: &u64, _size: u32) -> Thumb {
        Thumb::Pending { average: Some(egui::Color32::from_gray(90)) }
    }
}

fn ui(ui: &mut egui::Ui, state: &mut LibraryState<u64>, shoot: &mut Shoot) {
    let out = ThumbGrid::new("grid").show(ui, state, shoot, &Thumbs);
    for signal in out.signals {
        if let egui_pop_views::library::Signal::Rate { keys, rating } = signal {
            for p in shoot.0.iter_mut().filter(|p| keys.contains(&p.0)) {
                p.2 = rating;
            }
        }
    }
}

Structs§

Badge
A badge in a corner of a cell: a short text (RAW, HDR, 2×) or an icon of the icon registry (phosphor:plugs for “offline”). Its name is said after the cell’s name and is its tooltip.
LibraryOutput
What ThumbGrid::show returns.
LibraryState
A library’s state between passes: the selection, the stacks expanded, the grid’s zoom, each view’s scrolling.
Stack
A stack an image belongs to: its top image’s key, and how many images it holds. Members follow their top image in the application’s order.
ThumbGrid
The thumbnail grid, or the filmstrip (ThumbGrid::filmstrip).

Enums§

Change
A change of marks or tags made outside a grid (a panel’s stars, a tag input), for change.
GridResize
How a thumbnail grid’s zoom answers a resize: what the zoom (its slider, Ctrl and + or -, Ctrl and the wheel) means, and so what a wider grid shows.
Signal
What happened in a library view this pass.
Thumb
A thumbnail, as the source has it now.
Tone
A badge’s tone: egui-pop’s one tone (egui_pop_core::kit::Tone). The default kit’s pill gives info, success, warning, danger and record; a tone it does not give is drawn as its own (neutral) box. What a part says, the same names for every component. Neutral is the component’s own box (no tone); the others are read from component.tone.<name>, their defaults aliasing the system’s status tokens (accent.default, info, success, warning, danger, text.muted; record aliases danger too). Serialized by its token name ("danger").
Zoom
A grid’s zoom: how many thumbnails fill a row.

Constants§

DEFAULT_PER_ROW
The zoom at first: this many thumbnails per row.
MIN_SIZE
The smallest thumbnail in a grid, in points: it bounds how many fit in a row (Zoom::most_per_row).
PER_ROW_STEPS
The counts per row the zoom steps through (+, -, Ctrl and the wheel); past the last, each step out adds a quarter.

Traits§

LibraryItems
The images a library shows; the application owns them.
ThumbSource
Where thumbnails come from; the application implements it, loading them asynchronously (a thread, its engine), caching them, and asking for a repaint when one arrives.

Functions§

change
Runs a change’s step (library.rate, library.label, library.flag, library.tag) for library library, as the grid does: the signal to apply (with what a before-hook redirected it to), or Signal::Vetoed.