diff --git a/CLAUDE.md b/CLAUDE.md index 8b79fdf..26818b1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -83,7 +83,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~ | `cargo clippy --workspace --all-targets -- -D warnings`, `cargo fmt --check` | lint, format | phase 1 | | `busctl --user call org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings ReadOne ss org.freedesktop.appearance accent-color` | inspect portal values | now | | `fc-list` | check bundled/system fonts | now | -| `cargo run -p tunal -- --screenshot [--dark] [--size WxH]` (software renderer, offscreen, default 960x640; env `TUNAL_SEED=#rrggbb`, `TUNAL_REDUCED_MOTION=1`) | single-PNG visual check; full state matrix in phase 12 | S003 | +| `cargo run -p tunal -- --screenshot [--dark] [--size WxH]` (software renderer, offscreen, default 960x640; env `TUNAL_SEED=#rrggbb`, `TUNAL_REDUCED_MOTION=1`, `TUNAL_VIEW=grid`) | single-PNG visual check; full state matrix in phase 12 | S003 | | `XDG_DATA_HOME=/data cargo run -p tunal-core --example ops -- ` (refuses unless XDG_DATA_HOME is inside ``) | job engine + trash smoke run: conflicts, cancel, trash/restore/empty | S007 | | `cargo run -p tunal -- --gallery --screenshot [--dark] --size 1200x1000` (`--gallery` alone opens it in a window) | every control in rest/hover/pressed/focused/disabled; press squeeze not drawn by the software renderer | S004 | | `cargo run -p tunal -- --gallery --page menu\|dialog --screenshot [--dark] --size 960x640` | open menu + submenu + two toasts, or dialog + indeterminate toast, over a stand-in folder | S005 | diff --git a/Plans/03 File browsing/S009-grid-and-list-motion.md b/Plans/03 File browsing/S009-grid-and-list-motion.md index 2f60520..11274f1 100644 --- a/Plans/03 File browsing/S009-grid-and-list-motion.md +++ b/Plans/03 File browsing/S009-grid-and-list-motion.md @@ -10,12 +10,12 @@ The second view mode (icon grid), the switch between views, and motion for list CLAUDE.md §2 Motion rules, §4; `animate` skill; crates/tunal/ui/views/details-view.slint; crates/tunal/src/folder/ (model API). ## Steps -- [ ] Grid view: virtualized rows of N cells from the width (reflow on resize), two-line elided labels, animated selection indicator, same selection/keyboard model as details. -- [ ] View switch (segmented control) with a cross-fade; mode stored per pane. -- [ ] List motion: insert (fade + grow), remove (fade + collapse), reorder after sort (slide); fall back to instant above a size threshold; stable keys per entry. -- [ ] Navigation transition: content slides/fades in the direction of travel (into folder, up, back). -- [ ] Reduced motion makes all of it instant. -- [ ] PROGRESS entry, INDEX line, commit `S009: …` +- [x] Grid view: virtualized rows of N cells from the width (reflow on resize), two-line elided labels, animated selection indicator, same selection/keyboard model as details. +- [x] View switch (segmented control) with a cross-fade; mode stored per pane. +- [x] List motion: insert (fade + grow), remove (fade + collapse), reorder after sort (slide); fall back to instant above a size threshold; stable keys per entry. +- [x] Navigation transition: content slides/fades in the direction of travel (into folder, up, back). +- [x] Reduced motion makes all of it instant. +- [x] PROGRESS entry, INDEX line, commit `S009: …` ## End criteria - `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass. diff --git a/Plans/INDEX.md b/Plans/INDEX.md index a5241b9..8a1dda3 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -20,7 +20,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v - [x] [S006 — Location layer and local backend](03%20File%20browsing/S006-location-layer.md) · Opus medium - [x] [S007 — File operations engine and trash](03%20File%20browsing/S007-file-ops-engine.md) · Opus medium - [x] [S008 — Folder model and details view](03%20File%20browsing/S008-folder-model-details.md) · Opus medium -- [ ] [S009 — Icon grid view and list motion](03%20File%20browsing/S009-grid-and-list-motion.md) · Opus high +- [x] [S009 — Icon grid view and list motion](03%20File%20browsing/S009-grid-and-list-motion.md) · Opus high - [ ] [S010 — Tabs, split view, breadcrumbs, history and places](03%20File%20browsing/S010-navigation-shell.md) · Opus medium - [ ] [S011 — File operation actions](03%20File%20browsing/S011-file-op-actions.md) · Sonnet high - [ ] [S012 — Properties, Open and Open with](03%20File%20browsing/S012-properties-open-with.md) · Sonnet medium diff --git a/crates/tunal/src/folder/mod.rs b/crates/tunal/src/folder/mod.rs index 5dd81d8..60a236d 100644 --- a/crates/tunal/src/folder/mod.rs +++ b/crates/tunal/src/folder/mod.rs @@ -1,25 +1,29 @@ -//! The folder model behind the details view: entries from the location layer (loaded and -//! watched off the UI thread), sorted, grouped and filtered into rows, plus the selection. +//! The folder model behind the details and grid views: entries from the location layer +//! (loaded and watched off the UI thread), sorted, grouped and filtered into rows, plus the +//! selection, the grid's lines and the list motion of each change. -mod format; +pub mod format; mod load; +mod motion; mod sort; use std::cell::RefCell; use std::collections::{HashMap, HashSet}; use std::rc::Rc; -use std::sync::Arc; +use std::time::{Duration, Instant}; -use slint::{ComponentHandle, Model, ModelNotify, ModelRc, ModelTracker, SharedString, VecModel}; +use slint::{Model, ModelNotify, ModelRc, ModelTracker, SharedString, VecModel}; use tunal_core::playlist::Playlist; use tunal_core::{Entry, Error, Locations, Uri, Watch}; use crate::icons::{self, Category}; use crate::{ - DetailRow, FolderState, FolderStatus, Grouping, MainWindow, MenuEntry, MenuItem, NavKey, - SortColumn, + DetailRow, FolderState, FolderStatus, GridRow, Grouping, MenuEntry, MenuItem, NavKey, + SortColumn, Travel, ViewMode, }; -use load::{Change, Deliver, Msg}; +pub use load::Deliver; +use load::{Change, Msg}; +use motion::{Anim, Clock, Key, Old}; pub use sort::{GroupBy, Settings, SortKey}; /// One entry with what sorting and drawing need, computed once. @@ -47,9 +51,12 @@ impl Item { } } +#[derive(Clone)] enum Row { Header(&'static str), Item(usize), + /// A removed row kept while it collapses out (list motion). + Leaving(Key, Box), } enum Status { @@ -77,6 +84,15 @@ struct State { cursor: Option>, anchor: Option>, watches: Vec, + /// List motion of the rows, parallel to `rows` (empty when still), and its clock. + anim: Vec, + clock: Option, + /// Bumped per list change the view animates (`FolderState.motion`). + epoch: i32, + /// Grid columns the view last reported. + columns: usize, + travel: Travel, + travel_epoch: i32, } type Listener = Box; @@ -90,6 +106,8 @@ pub struct FolderModel { deliver: Deliver, /// Called after every change the window must reflect (state, menu). changed: RefCell, + /// Length of a list change (`MotionPrefs.list-change`); zero means instant. + list_time: RefCell Duration>>, } impl FolderModel { @@ -110,17 +128,37 @@ impl FolderModel { cursor: None, anchor: None, watches: Vec::new(), + anim: Vec::new(), + clock: None, + epoch: 0, + columns: 1, + travel: Travel::None, + travel_epoch: 0, }), notify: ModelNotify::default(), locations, deliver, changed: RefCell::new(Box::new(|_| {})), + list_time: RefCell::new(Box::new(|| Duration::ZERO)), }) } /// Shows `dir`: listing and watching run on a worker thread. pub fn open(&self, dir: Uri) { + self.open_travel(dir, Travel::None); + } + + /// Shows `dir`, its content sliding in from the side `travel` points to (into a folder + /// and forward from the right, up and back from the left). + pub fn open_travel(&self, dir: Uri, travel: Travel) { let generation = self.reset_to(dir.clone()); + { + let mut s = self.state.borrow_mut(); + if travel != Travel::None { + s.travel = travel; + s.travel_epoch += 1; + } + } let locations = self.locations.clone(); let deliver = self.deliver.clone(); std::thread::spawn(move || { @@ -176,6 +214,11 @@ impl FolderModel { pub fn apply(&self, msg: Msg) { let mut s = self.state.borrow_mut(); let current = s.generation; + // Watch events and playlist re-sorts animate; listing chunks don't. + let old = match &msg { + Msg::Changed(g, _) | Msg::Playlists(g, _) if *g == current => self.snapshot(&s), + _ => None, + }; match msg { Msg::Chunk(g, entries) if g == current => { for entry in entries { @@ -229,6 +272,7 @@ impl FolderModel { _ => return, } rebuild(&mut s); + self.animate(&mut s, old); drop(s); self.notify.reset(); self.emit(); @@ -250,6 +294,12 @@ impl FolderModel { }); } + /// Where list changes read their length (`MotionPrefs.list-change`); until set, or while + /// it returns zero (reduced motion), changes are instant. + pub fn set_list_time(&self, f: impl Fn() -> Duration + 'static) { + *self.list_time.borrow_mut() = Box::new(f); + } + /// Runs `f` after every change of state the window shows. pub fn on_changed(&self, f: impl Fn(&FolderModel) + 'static) { *self.changed.borrow_mut() = Box::new(f); @@ -259,6 +309,18 @@ impl FolderModel { (self.changed.borrow())(self); } + /// The folder shown (or loading), `None` before the first `open`. + pub fn dir(&self) -> Option { + self.state.borrow().dir.clone() + } + + /// Selected entries and their total size (folders count as empty). + pub fn selection(&self) -> (usize, u64) { + let s = self.state.borrow(); + let items = s.selected.iter().filter_map(|n| s.by_name.get(n)); + items.fold((0, 0), |(n, bytes), &i| (n + 1, bytes + s.items[i].size())) + } + pub fn state(&self) -> FolderState { let s = self.state.borrow(); let (status, error) = match &s.status { @@ -295,6 +357,132 @@ impl FolderModel { filter: s.settings.filter.as_str().into(), items: shown as i32, hidden: hidden as i32, + mode: s.settings.mode, + motion: s.epoch, + travel: s.travel, + travel_epoch: s.travel_epoch, + } + } + + /// The grid's lines for the current rows and column count. + pub fn grid_lines(&self) -> Vec { + let s = self.state.borrow(); + motion::grid(&headers(&s), &[], s.columns).0 + } + + pub fn set_mode(&self, mode: ViewMode) { + let ghosts = { + let mut s = self.state.borrow_mut(); + if s.settings.mode == mode { + return; + } + s.settings.mode = mode; + still(&mut s) + }; + if ghosts { + self.notify.reset(); + } + self.emit(); + } + + /// The grid view's column count changed: the lines reflow at once. + pub fn set_columns(&self, columns: usize) { + let ghosts = { + let mut s = self.state.borrow_mut(); + let columns = columns.max(1); + if s.columns == columns { + return; + } + s.columns = columns; + still(&mut s) + }; + if ghosts { + self.notify.reset(); + } + self.emit(); + } + + // ---- list motion ----------------------------------------------------------------- + + /// What the rows look like and where they are drawn, before a change that may animate. + /// `None` when it shouldn't: reduced motion, still loading, or too many rows. + fn snapshot(&self, s: &State) -> Option> { + if (self.list_time.borrow())().is_zero() + || !matches!(s.status, Status::Ready) + || s.rows.len() > motion::LIMIT + { + return None; + } + let progress = s.clock.map_or(1.0, |c| c.settled()); + let drawn = motion::drawn(s.settings.mode, &headers(s), &s.anim, s.columns, progress); + Some( + (0..s.rows.len()) + .map(|r| { + let mut row = row_data(s, r).unwrap_or_default(); + row.selected = false; + row.cursor = false; + Old { + key: key_of(s, r), + row, + drawn: drawn[r], + leaving: matches!(s.rows[r], Row::Leaving(..)), + } + }) + .collect(), + ) + } + + /// After a rebuild: puts the removed rows back as leaving copies and starts the motion + /// from `old` to the new rows. + fn animate(&self, s: &mut State, old: Option>) { + let Some(old) = old else { + return; + }; + if s.rows.len() > motion::LIMIT { + return; + } + let new: Vec = (0..s.rows.len()).map(|r| key_of(s, r)).collect(); + let merged = motion::merge(&old, &new); + let flags: Vec = merged + .iter() + .map(|m| match *m { + Ok(n) => matches!(s.rows[n], Row::Header(_)), + Err(o) => old[o].row.header, + }) + .collect(); + let Some(anims) = motion::plan(s.settings.mode, &old, &new, &merged, &flags, s.columns) + else { + return; + }; + s.rows = merged + .iter() + .map(|m| match *m { + Ok(n) => s.rows[n].clone(), + Err(o) => Row::Leaving(old[o].key.clone(), Box::new(old[o].row.clone())), + }) + .collect(); + index(s); + s.anim = anims; + s.clock = Some(Clock { + start: Instant::now(), + duration: (self.list_time.borrow())(), + }); + s.epoch += 1; + } + + /// The view's clock ran out: leaving rows go. + pub fn motion_settled(&self) { + let ghosts = { + let mut s = self.state.borrow_mut(); + // A clock that ends right after a new change started belongs to the old one. + match s.clock { + Some(c) if c.start.elapsed() >= c.duration / 2 => still(&mut s), + _ => return, + } + }; + if ghosts { + self.notify.reset(); + self.emit(); } } @@ -302,8 +490,10 @@ impl FolderModel { fn update(&self, f: impl FnOnce(&mut Settings)) { let mut s = self.state.borrow_mut(); + let old = self.snapshot(&s); f(&mut s.settings); rebuild(&mut s); + self.animate(&mut s, old); drop(s); self.notify.reset(); self.emit(); @@ -476,7 +666,7 @@ impl FolderModel { let s = self.state.borrow(); match s.rows.get(row)? { Row::Item(i) => Some(s.items[*i].entry.name.clone()), - Row::Header(_) => None, + Row::Header(_) | Row::Leaving(..) => None, } } @@ -519,34 +709,20 @@ impl FolderModel { self.select(|s| s.selected.clear()); } - /// Keyboard move of the cursor; `page` is rows per page. Returns the cursor row (or -1). + /// Keyboard move of the cursor; `page` is rows (details) or lines (grid) per page. + /// Returns the line to show: the cursor row, or the grid line holding it (-1 for none). pub fn navigate(&self, key: NavKey, shift: bool, page: usize) -> i32 { - let target = { + let (target, line) = { let s = self.state.borrow(); - let items: Vec = (0..s.rows.len()) - .filter(|&r| matches!(s.rows[r], Row::Item(_))) - .collect(); - if items.is_empty() { - return -1; - } - let current = s - .cursor - .as_ref() - .and_then(|c| s.row_of.get(c)) - .and_then(|r| items.iter().position(|i| i == r)); - let last = items.len() - 1; let page = page.max(1); - let to = match (key, current) { - (NavKey::Up | NavKey::End, None) => last, - (_, None) => 0, - (NavKey::Up, Some(c)) => c.saturating_sub(1), - (NavKey::Down, Some(c)) => (c + 1).min(last), - (NavKey::Home, _) => 0, - (NavKey::End, _) => last, - (NavKey::PageUp, Some(c)) => c.saturating_sub(page), - (NavKey::PageDown, Some(c)) => (c + page).min(last), + let found = match s.settings.mode { + ViewMode::Details => list_move(&s, key, page).map(|r| (r, r)), + ViewMode::Grid => grid_move(&s, key, page), }; - items[to] + let Some(found) = found else { + return -1; + }; + found }; let Some(name) = self.name_at(target) else { return -1; @@ -562,7 +738,7 @@ impl FolderModel { } s.cursor = Some(name); }); - target as i32 + line as i32 } /// Enter or double-click: opens the folder at `row` (the cursor row when `None`). @@ -578,7 +754,7 @@ impl FolderModel { } }; if let Some(dir) = target { - self.open(dir); + self.open_travel(dir, Travel::Into); } } } @@ -593,11 +769,119 @@ fn range(s: &State, a: &[u8], b: &[u8]) -> Vec> { .iter() .filter_map(|r| match r { Row::Item(i) => Some(s.items[*i].entry.name.clone()), - Row::Header(_) => None, + Row::Header(_) | Row::Leaving(..) => None, }) .collect() } +/// Details view: the row a key moves the cursor to. +fn list_move(s: &State, key: NavKey, page: usize) -> Option { + let items: Vec = (0..s.rows.len()) + .filter(|&r| matches!(s.rows[r], Row::Item(_))) + .collect(); + let current = s + .cursor + .as_ref() + .and_then(|c| s.row_of.get(c)) + .and_then(|r| items.iter().position(|i| i == r)); + let last = items.len().checked_sub(1)?; + let to = match (key, current) { + (NavKey::Up | NavKey::End, None) => last, + (_, None) => 0, + (NavKey::Up | NavKey::Left, Some(c)) => c.saturating_sub(1), + (NavKey::Down | NavKey::Right, Some(c)) => (c + 1).min(last), + (NavKey::Home, _) => 0, + (NavKey::End, _) => last, + (NavKey::PageUp, Some(c)) => c.saturating_sub(page), + (NavKey::PageDown, Some(c)) => (c + page).min(last), + }; + Some(items[to]) +} + +/// Grid view: the row a key moves the cursor to, and the grid line holding it. Up and Down +/// keep the column (or take the last cell of a shorter line), Left and Right step through +/// the entries. +fn grid_move(s: &State, key: NavKey, page: usize) -> Option<(usize, usize)> { + let (lines, _) = motion::grid(&headers(s), &[], s.columns); + // Lines of cells as (grid line, entry rows). + let cells: Vec<(usize, Vec)> = lines + .iter() + .enumerate() + .filter(|(_, l)| !l.header) + .map(|(li, l)| { + let rows = (l.start as usize..(l.start + l.count) as usize) + .filter(|&r| matches!(s.rows[r], Row::Item(_))) + .collect::>(); + (li, rows) + }) + .filter(|(_, rows)| !rows.is_empty()) + .collect(); + let last_line = cells.len().checked_sub(1)?; + let place = s + .cursor + .as_ref() + .and_then(|c| s.row_of.get(c)) + .and_then(|&r| { + cells + .iter() + .enumerate() + .find_map(|(i, (_, rows))| rows.iter().position(|&x| x == r).map(|c| (i, c))) + }); + let at = |line: usize, col: usize| { + let (li, rows) = &cells[line]; + (rows[col.min(rows.len() - 1)], *li) + }; + let first = at(0, 0); + let last = at(last_line, usize::MAX); + Some(match (key, place) { + (NavKey::Up | NavKey::Left | NavKey::End | NavKey::PageUp, None) => last, + (_, None) => first, + (NavKey::Home, _) => first, + (NavKey::End, _) => last, + (NavKey::Up, Some((l, c))) => at(l.saturating_sub(1), c), + (NavKey::Down, Some((l, c))) => at((l + 1).min(last_line), c), + (NavKey::PageUp, Some((l, c))) => at(l.saturating_sub(page), c), + (NavKey::PageDown, Some((l, c))) => at((l + page).min(last_line), c), + (NavKey::Left, Some((l, c))) if c > 0 => at(l, c - 1), + (NavKey::Left, Some((l, _))) if l > 0 => at(l - 1, usize::MAX), + (NavKey::Right, Some((l, c))) if c + 1 < cells[l].1.len() => at(l, c + 1), + (NavKey::Right, Some((l, _))) if l < last_line => at(l + 1, 0), + (NavKey::Left | NavKey::Right, Some((l, c))) => at(l, c), + }) +} + +/// Header flags of the rows (leaving copies included). +fn headers(s: &State) -> Vec { + s.rows + .iter() + .map(|r| match r { + Row::Header(_) => true, + Row::Item(_) => false, + Row::Leaving(_, row) => row.header, + }) + .collect() +} + +fn key_of(s: &State, row: usize) -> Key { + match &s.rows[row] { + Row::Header(label) => Key::Header(label), + Row::Item(i) => Key::Item(s.items[*i].entry.name.clone()), + Row::Leaving(key, _) => key.clone(), + } +} + +/// Ends any list motion at once: leaving rows go. True if there were any. +fn still(s: &mut State) -> bool { + let ghosts = s.rows.iter().any(|r| matches!(r, Row::Leaving(..))); + if ghosts { + s.rows.retain(|r| !matches!(r, Row::Leaving(..))); + index(s); + } + s.anim.clear(); + s.clock = None; + ghosts +} + fn upsert(s: &mut State, entry: Entry) { match s.by_name.get(&entry.name) { Some(&i) => s.items[i] = Item::new(entry), @@ -658,15 +942,10 @@ fn rebuild(s: &mut State) { } rows.push(Row::Item(i)); } - s.row_of = rows - .iter() - .enumerate() - .filter_map(|(r, row)| match row { - Row::Item(i) => Some((s.items[*i].entry.name.clone(), r)), - Row::Header(_) => None, - }) - .collect(); s.rows = rows; + s.anim.clear(); + s.clock = None; + index(s); let row_of = &s.row_of; s.selected.retain(|n| row_of.contains_key(n)); if s.cursor.as_ref().is_some_and(|c| !row_of.contains_key(c)) { @@ -674,6 +953,19 @@ fn rebuild(s: &mut State) { } } +/// Recomputes `row_of` from `rows`. +fn index(s: &mut State) { + s.row_of = s + .rows + .iter() + .enumerate() + .filter_map(|(r, row)| match row { + Row::Item(i) => Some((s.items[*i].entry.name.clone(), r)), + Row::Header(_) | Row::Leaving(..) => None, + }) + .collect(); +} + /// Slint sends special keys (arrows, F-keys) as private-use characters. fn is_key_code(c: char) -> bool { ('\u{F700}'..='\u{F8FF}').contains(&c) @@ -688,6 +980,40 @@ fn error_text(e: &Error) -> String { } } +/// The row as the views draw it, with its list motion. +fn row_data(s: &State, row: usize) -> Option { + let mut data = match s.rows.get(row)? { + Row::Leaving(_, data) => (**data).clone(), + Row::Header(label) => DetailRow { + header: true, + name: (*label).into(), + ..Default::default() + }, + Row::Item(i) => { + let item = &s.items[*i]; + let entry = &item.entry; + DetailRow { + header: false, + name: entry.display_name.as_str().into(), + glyph: item.category.glyph().into(), + badge: icons::link_badge(&entry.kind).into(), + size: if item.is_dir { + SharedString::new() + } else { + format::size(entry.size).into() + }, + kind: icons::type_label(entry, item.category).into(), + modified: entry.mtime.map(format::date).unwrap_or_default().into(), + selected: s.selected.contains(&entry.name), + cursor: s.cursor.as_ref() == Some(&entry.name), + ..Default::default() + } + } + }; + s.anim.get(row).copied().unwrap_or_default().fill(&mut data); + Some(data) +} + impl Model for FolderModel { type Data = DetailRow; @@ -696,33 +1022,7 @@ impl Model for FolderModel { } fn row_data(&self, row: usize) -> Option { - let s = self.state.borrow(); - Some(match s.rows.get(row)? { - Row::Header(label) => DetailRow { - header: true, - name: (*label).into(), - ..Default::default() - }, - Row::Item(i) => { - let item = &s.items[*i]; - let entry = &item.entry; - DetailRow { - header: false, - name: entry.display_name.as_str().into(), - glyph: item.category.glyph().into(), - badge: icons::link_badge(&entry.kind).into(), - size: if item.is_dir { - SharedString::new() - } else { - format::size(entry.size).into() - }, - kind: icons::type_label(entry, item.category).into(), - modified: entry.mtime.map(format::date).unwrap_or_default().into(), - selected: s.selected.contains(&entry.name), - cursor: s.cursor.as_ref() == Some(&entry.name), - } - } - }) + row_data(&self.state.borrow(), row) } fn model_tracker(&self) -> &dyn ModelTracker { @@ -733,55 +1033,3 @@ impl Model for FolderModel { self } } - -/// Connects a folder model to the window: rows, state, sort menu and every view callback. -pub fn attach(ui: &MainWindow, locations: Locations) -> Rc { - let weak = ui.as_weak(); - let deliver: Deliver = Arc::new(move |msg| { - let _ = weak.upgrade_in_event_loop(move |ui| { - if let Some(model) = ui.get_rows().as_any().downcast_ref::() { - model.apply(msg); - } - }); - }); - let model = FolderModel::new(locations, deliver); - ui.set_rows(ModelRc::from(model.clone())); - - let weak = ui.as_weak(); - model.on_changed(move |model| { - if let Some(ui) = weak.upgrade() { - ui.set_folder(model.state()); - ui.set_sort_menu(ModelRc::new(VecModel::from(model.sort_menu()))); - } - }); - - let m = Rc::downgrade(&model); - let with = move |f: &dyn Fn(&FolderModel)| { - if let Some(model) = m.upgrade() { - f(&model); - } - }; - let w = with.clone(); - ui.on_sort_by(move |column| w(&|m| m.sort_column(column))); - let w = with.clone(); - ui.on_filter_typed(move |text| w(&|m| m.type_filter(&text))); - let w = with.clone(); - ui.on_filter_edited(move |text| w(&|m| m.set_filter(&text))); - let w = with.clone(); - ui.on_toggle_hidden(move || w(&|m| m.toggle_hidden())); - let w = with.clone(); - ui.on_row_clicked(move |row, ctrl, shift| w(&|m| m.click(row.max(0) as usize, ctrl, shift))); - let w = with.clone(); - ui.on_row_activated(move |row| w(&|m| m.activate(usize::try_from(row).ok()))); - let w = with.clone(); - ui.on_select_all(move || w(&|m| m.select_all())); - let w = with.clone(); - ui.on_clear_selection(move || w(&|m| m.clear_selection())); - let m = Rc::downgrade(&model); - ui.on_navigate(move |key, shift, page| { - m.upgrade() - .map_or(-1, |m| m.navigate(key, shift, page.max(1) as usize)) - }); - model.emit(); - model -} diff --git a/crates/tunal/src/folder/motion.rs b/crates/tunal/src/folder/motion.rs new file mode 100644 index 0000000..b922f6c --- /dev/null +++ b/crates/tunal/src/folder/motion.rs @@ -0,0 +1,340 @@ +//! List motion. When the rows of the open folder change in place (sort, filter, hidden files, +//! watch events), rows that stay slide from where they were drawn, new rows grow in, and +//! removed rows stay as leaving copies until the change settles. The view draws it from the +//! per-row fields of `DetailRow` and one clock (`MotionClock` in `motion.slint`). +//! +//! Positions are in view units: rows for the details view; cells, cell lines and header +//! lines for the grid. + +use std::collections::{HashMap, HashSet}; +use std::ops::{Add, Mul, Sub}; +use std::time::{Duration, Instant}; + +use crate::{DetailRow, GridRow, ViewMode}; + +/// Above this many rows (before or after) a change is instant. +pub const LIMIT: usize = 2000; + +/// Identity of a row across rebuilds. +#[derive(Clone, PartialEq, Eq, Hash, Debug)] +pub enum Key { + Header(&'static str), + Item(Vec), +} + +#[derive(Clone, Copy, Default, PartialEq, Debug)] +pub struct Pos { + pub x: f32, + /// Rows (details) or cell lines (grid). + pub y: f32, + /// Header lines (grid only; details headers are rows). + pub h: f32, +} + +impl Add for Pos { + type Output = Pos; + fn add(self, o: Pos) -> Pos { + Pos { + x: self.x + o.x, + y: self.y + o.y, + h: self.h + o.h, + } + } +} + +impl Sub for Pos { + type Output = Pos; + fn sub(self, o: Pos) -> Pos { + Pos { + x: self.x - o.x, + y: self.y - o.y, + h: self.h - o.h, + } + } +} + +impl Mul for Pos { + type Output = Pos; + fn mul(self, k: f32) -> Pos { + Pos { + x: self.x * k, + y: self.y * k, + h: self.h * k, + } + } +} + +/// How one row moves: from `from` to `to`, both relative to its slot. +#[derive(Clone, Copy, Default, Debug)] +pub struct Anim { + pub from: Pos, + pub to: Pos, + pub enter: bool, + pub leave: bool, +} + +impl Anim { + pub fn fill(self, row: &mut DetailRow) { + row.from_x = self.from.x; + row.from_y = self.from.y; + row.from_h = self.from.h; + row.to_x = self.to.x; + row.to_y = self.to.y; + row.to_h = self.to.h; + row.enter = self.enter; + row.leave = self.leave; + } +} + +/// Same curve as `Motion.settle` in `motion.slint`. +pub fn settle(t: f32) -> f32 { + 1.0 - (1.0 - t.clamp(0.0, 1.0)).powi(3) +} + +/// A running change. +#[derive(Clone, Copy)] +pub struct Clock { + pub start: Instant, + pub duration: Duration, +} + +impl Clock { + pub fn settled(&self) -> f32 { + settle(self.start.elapsed().as_secs_f32() / self.duration.as_secs_f32()) + } +} + +/// The grid's lines for rows whose header flags are `headers`, and each row's slot. With +/// `skip`, rows marked there take no slot: they sit at the slot of the row after them (the +/// layout once they are gone). +pub fn grid(headers: &[bool], skip: &[bool], columns: usize) -> (Vec, Vec) { + let columns = columns.max(1); + let mut lines: Vec = Vec::new(); + let mut slots = vec![Pos::default(); headers.len()]; + let (mut y, mut h, mut x) = (0.0, 0.0, 0usize); + // Rows waiting for the next slot (skipped ones). + let mut pending: Vec = Vec::new(); + let mut open = false; + for (r, &header) in headers.iter().enumerate() { + if skip.get(r).copied().unwrap_or(false) { + pending.push(r); + continue; + } + if header { + if open { + y += 1.0; + open = false; + } + let at = Pos { x: 0.0, y, h }; + for p in pending.drain(..) { + slots[p] = at; + } + slots[r] = at; + h += 1.0; + x = 0; + continue; + } + if x == columns { + y += 1.0; + x = 0; + } + let at = Pos { x: x as f32, y, h }; + for p in pending.drain(..) { + slots[p] = at; + } + slots[r] = at; + x += 1; + open = true; + } + let end = Pos { x: x as f32, y, h }; + for p in pending { + slots[p] = end; + } + // Lines cover every row, skipped or not, in order, so the view can index them. + let mut x = 0usize; + let mut headers_before = 0; + for (r, &header) in headers.iter().enumerate() { + if header { + lines.push(GridRow { + header: true, + start: r as i32, + count: 1, + headers_before, + }); + headers_before += 1; + x = 0; + continue; + } + match lines.last_mut() { + Some(line) if !line.header && x < columns => line.count += 1, + _ => { + lines.push(GridRow { + header: false, + start: r as i32, + count: 1, + headers_before, + }); + x = 0; + } + } + x += 1; + } + (lines, slots) +} + +/// Where each row is drawn at progress `s` (settled 0..1) of `anims`. +pub fn drawn(mode: ViewMode, headers: &[bool], anims: &[Anim], columns: usize, s: f32) -> Vec { + let anim = |r: usize| anims.get(r).copied().unwrap_or_default(); + match mode { + ViewMode::Details => { + let mut y = 0.0; + (0..headers.len()) + .map(|r| { + let a = anim(r); + let pos = Pos { + y: y + a.from.y * (1.0 - s), + ..Pos::default() + }; + y += if a.enter { + s + } else if a.leave { + 1.0 - s + } else { + 1.0 + }; + pos + }) + .collect() + } + ViewMode::Grid => { + let (_, slots) = grid(headers, &[], columns); + slots + .iter() + .enumerate() + .map(|(r, &at)| { + let a = anim(r); + at + a.to + (a.from - a.to) * (1.0 - s) + }) + .collect() + } + } +} + +/// One row before the change: identity, look (for a leaving copy) and where it was drawn. +pub struct Old { + pub key: Key, + pub row: DetailRow, + pub drawn: Pos, + /// Already collapsing out of an interrupted change: it goes now instead of collapsing + /// again, and if it comes back it grows in like a new row. + pub leaving: bool, +} + +/// Rows of the new list in order: `Ok(new index)` or `Err(old index)` for a leaving copy. +pub type Merged = Vec>; + +/// Puts each removed old row back right after the old row before it that stays (or first). +pub fn merge(old: &[Old], new: &[Key]) -> Merged { + let at: HashMap<&Key, usize> = new.iter().enumerate().map(|(i, k)| (k, i)).collect(); + // Leaving rows grouped by the new row they follow (None: before the first). + let mut after: HashMap, Vec> = HashMap::new(); + let mut anchor = None; + for (i, o) in old.iter().enumerate() { + match at.get(&o.key) { + Some(&n) => anchor = Some(n), + None if !o.leaving => after.entry(anchor).or_default().push(i), + None => {} + } + } + let mut merged = Vec::with_capacity(new.len() + old.len()); + merged.extend(after.remove(&None).unwrap_or_default().into_iter().map(Err)); + for n in 0..new.len() { + merged.push(Ok(n)); + if let Some(leaving) = after.remove(&Some(n)) { + merged.extend(leaving.into_iter().map(Err)); + } + } + merged +} + +/// The animation of every merged row, given the new rows' keys and header flags. `None` when +/// nothing would move. +pub fn plan( + mode: ViewMode, + old: &[Old], + new: &[Key], + merged: &Merged, + headers: &[bool], + columns: usize, +) -> Option> { + let was: HashMap<&Key, Pos> = old + .iter() + .filter(|o| !o.leaving) + .map(|o| (&o.key, o.drawn)) + .collect(); + let fresh: HashSet = (0..new.len()) + .filter(|&n| !was.contains_key(&new[n])) + .collect(); + let leave: Vec = merged.iter().map(Result::is_err).collect(); + let mut anims = vec![Anim::default(); merged.len()]; + match mode { + ViewMode::Details => { + // At the start entering rows have no height and leaving rows full height. + let mut y = 0.0; + for (r, m) in merged.iter().enumerate() { + let (enter, from) = match *m { + Ok(n) if fresh.contains(&n) => (true, 0.0), + Ok(n) => (false, was[&new[n]].y - y), + Err(o) => (false, old[o].drawn.y - y), + }; + anims[r] = Anim { + from: Pos { + y: from, + ..Pos::default() + }, + enter, + leave: leave[r], + ..Anim::default() + }; + if !enter { + y += 1.0; + } + } + } + ViewMode::Grid => { + let (_, slots) = grid(headers, &[], columns); + let (_, target) = grid(headers, &leave, columns); + for (r, m) in merged.iter().enumerate() { + let to = target[r] - slots[r]; + anims[r] = match *m { + // New cells appear where they end up. + Ok(n) if fresh.contains(&n) => Anim { + from: to, + to, + enter: true, + ..Anim::default() + }, + Ok(n) => Anim { + from: was[&new[n]] - slots[r], + to, + ..Anim::default() + }, + // Leaving cells fade where they were. + Err(o) => { + let from = old[o].drawn - slots[r]; + Anim { + from, + to: from, + leave: true, + ..Anim::default() + } + } + }; + } + } + } + let still = anims + .iter() + .all(|a| !a.enter && !a.leave && a.from == Pos::default() && a.to == Pos::default()); + (!still).then_some(anims) +} diff --git a/crates/tunal/src/folder/sort.rs b/crates/tunal/src/folder/sort.rs index 39d66d9..98c8589 100644 --- a/crates/tunal/src/folder/sort.rs +++ b/crates/tunal/src/folder/sort.rs @@ -6,6 +6,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tunal_core::playlist::Ranks; use super::Item; +use crate::ViewMode; use crate::icons::Category; #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -34,6 +35,8 @@ pub struct Settings { pub group: GroupBy, pub show_hidden: bool, pub filter: String, + /// Details or grid; per pane like the rest, carried over between folders. + pub mode: ViewMode, } impl Default for Settings { @@ -45,6 +48,11 @@ impl Default for Settings { group: GroupBy::None, show_hidden: false, filter: String::new(), + // `TUNAL_VIEW=grid` starts in the grid view (screenshots). + mode: match std::env::var("TUNAL_VIEW").as_deref() { + Ok("grid") => ViewMode::Grid, + _ => ViewMode::Details, + }, } } } diff --git a/crates/tunal/ui/components/icon.slint b/crates/tunal/ui/components/icon.slint index fa8ea85..8f2e951 100644 --- a/crates/tunal/ui/components/icon.slint +++ b/crates/tunal/ui/components/icon.slint @@ -30,6 +30,7 @@ export global Icons { out property search: "\u{e8b6}"; out property star: "\u{e838}"; out property grid-view: "\u{e9b0}"; + out property view-list: "\u{e8ef}"; out property music-note: "\u{e405}"; out property description: "\u{e873}"; out property chevron-right: "\u{e5cc}"; diff --git a/crates/tunal/ui/motion.slint b/crates/tunal/ui/motion.slint index 57ceab0..0280fd4 100644 --- a/crates/tunal/ui/motion.slint +++ b/crates/tunal/ui/motion.slint @@ -5,6 +5,9 @@ // Motion because easing properties can't be exported to Rust. export global MotionPrefs { in property reduced; + // Length of a list change (insert, remove, reorder), read by the folder model when it + // starts one; 0 under reduced motion, which makes the model skip the transition. + out property list-change: Motion.time(Motion.medium1); } export global Motion { @@ -47,7 +50,49 @@ export global Motion { // Hover time before a tooltip shows. A delay, not motion: reduced motion keeps it. out property tooltip-delay: 500ms; + // How far content slides when a folder opens in a direction of travel. + out property travel-shift: 32px; + public pure function time(d: duration) -> duration { reduced ? 0ms : d } + + // Position of a clock-driven transition (`MotionClock`) at progress t in 0..1: a cubic + // ease-out, the stand-in for emphasized-decelerate where Slint can't apply an easing. + // The folder model (Rust) uses the same curve when a transition is interrupted. + public pure function settle(t: float) -> float { + 1 - pow(1 - clamp(t, 0, 1), 3) + } +} + +// A transition clock: `progress` runs from 0 to 1 over `duration` after each change of +// `epoch`, and is 1 otherwise. It ticks only while running, so nothing repaints when idle. +// Use it where a value must jump to a start point and then settle (rows that change place), +// which a property `animate` can't express. +export component MotionClock { + in property epoch; + in property duration; + out property running; + out property progress: root.running ? (animation-tick() - root.start) / root.duration : 1; + callback settled; + + property start; + + changed epoch => { + if root.duration > 0ms { + root.start = animation-tick(); + root.running = true; + // A change while running starts over from here. + timer.restart(); + } + } + + timer := Timer { + running: root.running; + interval: root.duration; + triggered => { + root.running = false; + root.settled(); + } + } } diff --git a/crates/tunal/ui/views/details-view.slint b/crates/tunal/ui/views/details-view.slint index 6fa6cac..84f97f0 100644 --- a/crates/tunal/ui/views/details-view.slint +++ b/crates/tunal/ui/views/details-view.slint @@ -10,7 +10,11 @@ import { Chip, ChipKind } from "../components/chip.slint"; export enum SortColumn { name, size, type, modified, playlist } export enum Grouping { none, type, modified, size } export enum FolderStatus { loading, ready, error } -export enum NavKey { up, down, home, end, page-up, page-down } +export enum NavKey { up, down, left, right, home, end, page-up, page-down } +// How the folder shows its entries; kept per pane in the folder model. +export enum ViewMode { details, grid } +// Which way the last folder change went, for the direction its content slides in from. +export enum Travel { none, into, up, back, forward } // One row of the details list: a group header (only `name` set) or an entry. export struct DetailRow { @@ -23,6 +27,17 @@ export struct DetailRow { modified: string, selected: bool, cursor: bool, + // List motion, relative to the row's slot: it moves from `from` to `to` (details: rows, + // `from-y` only; grid: cells, cell lines and header lines), and grows in or collapses out. + // A leaving row is a copy of a removed one, kept until the change ends. + from-x: float, + from-y: float, + from-h: float, + to-x: float, + to-y: float, + to-h: float, + enter: bool, + leave: bool, } // What the view shows around the rows, set from Rust. @@ -39,10 +54,16 @@ export struct FolderState { // Entries shown, and entries left out because hidden files are off. items: int, hidden: int, + mode: ViewMode, + // Bumped when a list change starts that rows animate (see DetailRow). + motion: int, + travel: Travel, + // Bumped when a folder opens with a direction of travel. + travel-epoch: int, } // Column widths shared by the header and the rows. -global Columns { +export global Columns { out property size: 88px; out property kind: 128px; out property modified: 144px; @@ -80,7 +101,7 @@ component Arrow inherits Rectangle { // A column title: click sorts. The arrow fades in on the sorted column and slides to show // the direction; it sits on the side away from the text's alignment edge. -component HeaderCell inherits StateLayer { +export component HeaderCell inherits StateLayer { in property text; in property active; in property descending; @@ -172,7 +193,7 @@ component Cell inherits HorizontalLayout { } // Centred message for the loading, empty and error states. -component Message inherits VerticalLayout { +export component Message inherits VerticalLayout { in property glyph; in property title; in property body; @@ -208,11 +229,140 @@ component Message inherits VerticalLayout { } } +// The keyboard of a folder view: arrows move the cursor (`move`), typing filters, Ctrl+A +// selects all, Ctrl+H toggles hidden files, Enter opens, Esc clears the filter, then the +// selection. Left and Right only reach `move` when `horizontal` is set (the grid). +export component FolderKeys inherits FocusScope { + in property state; + in property horizontal; + callback move(NavKey, bool); + callback filter-typed(string); + callback filter-edited(string); + callback toggle-hidden(); + callback row-activated(int); + callback select-all(); + callback clear-selection(); + + key-pressed(event) => { + if event.modifiers.control && (event.text == "a" || event.text == "A") { + root.select-all(); + return accept; + } + if event.modifiers.control && (event.text == "h" || event.text == "H") { + root.toggle-hidden(); + return accept; + } + if event.modifiers.control || event.modifiers.alt || event.modifiers.meta { + return reject; + } + if event.text == Key.UpArrow { + root.move(NavKey.up, event.modifiers.shift); + } else if event.text == Key.DownArrow { + root.move(NavKey.down, event.modifiers.shift); + } else if root.horizontal && event.text == Key.LeftArrow { + root.move(NavKey.left, event.modifiers.shift); + } else if root.horizontal && event.text == Key.RightArrow { + root.move(NavKey.right, event.modifiers.shift); + } else if event.text == Key.Home { + root.move(NavKey.home, event.modifiers.shift); + } else if event.text == Key.End { + root.move(NavKey.end, event.modifiers.shift); + } else if event.text == Key.PageUp { + root.move(NavKey.page-up, event.modifiers.shift); + } else if event.text == Key.PageDown { + root.move(NavKey.page-down, event.modifiers.shift); + } else if event.text == Key.Return { + root.row-activated(-1); + } else if event.text == Key.Escape { + if root.state.filter != "" { + root.filter-edited(""); + } else { + root.clear-selection(); + } + } else if event.text == Key.Backspace { + root.filter-typed("\u{8}"); + } else if event.text != "" && event.text != Key.Tab && event.text != Key.Backtab + && event.text != Key.LeftArrow && event.text != Key.RightArrow { + root.filter-typed(event.text); + } else { + return reject; + } + accept + } +} + +// Filter chip: grows in while typing, collapses when cleared. +export component FilterChip inherits Rectangle { + in property state; + callback filter-edited(string); + + // Last non-empty filter, so the chip keeps its text while it collapses. + property chip-text; + changed state => { + if root.state.filter != "" { + root.chip-text = root.state.filter; + } + } + + height: root.state.filter != "" ? 32px + 2 * Theme.space-2 : 0; + clip: true; + animate height { duration: Motion.time(Motion.short4); easing: Motion.emphasized-decelerate; } + + HorizontalLayout { + y: 0; + height: 32px + 2 * Theme.space-2; + padding: Theme.space-2; + padding-left: Columns.inset + Theme.space-2; + alignment: start; + + Chip { + kind: ChipKind.assist; + icon: Icons.search; + text: "Filter: " + root.chip-text; + tooltip: "Clear the filter (Esc)"; + clicked => { + root.filter-edited(""); + } + } + } +} + +// The loading, empty and error states over a folder view's rows. +export component FolderMessages inherits Rectangle { + in property state; + in property row-count; + + if root.state.status == FolderStatus.error: Message { + glyph: Icons.error; + title: "Can't open this folder"; + body: root.state.error; + } + + if root.state.status == FolderStatus.loading && root.row-count == 0: Message { + title: "Loading…"; + } + + if root.state.status == FolderStatus.ready && root.state.items == 0: Message { + glyph: Icons.folder; + title: root.state.filter != "" ? "Nothing matches “" + root.state.filter + "”" + : root.state.hidden > 0 ? "Only hidden items here" + : "This folder is empty"; + body: root.state.filter != "" ? "Press Esc to clear the filter" + : root.state.hidden > 0 ? "Press Ctrl+H to show hidden files" + : ""; + } +} + // The details view of one folder: column header, filter chip, virtualized rows and the // loading/empty/error states. It owns the keyboard: arrows move the cursor, typing filters. export component DetailsView inherits Rectangle { in property <[DetailRow]> rows; in property state; + // List motion progress from the shared clock (1 when settled), and the slide and fade + // of a folder opening (see FolderView). + in property motion: 1; + in property travel-x; + in property travel-opacity: 1; callback sort-by(SortColumn); // Window coordinates of the point the sort menu should open at. @@ -226,28 +376,17 @@ export component DetailsView inherits Rectangle { callback row-activated(int); callback select-all(); callback clear-selection(); - // Moves the cursor; returns the new cursor row, or -1. + // Moves the cursor; returns the line to show (the cursor row), or -1. callback navigate(NavKey, bool, int) -> int; // Narrow views drop the Type column so names keep their room. property compact: root.width < 640px; + property settle: Motion.settle(root.motion); public function focus-view() { keys.focus(); } - // Last non-empty filter, so the chip keeps its text while it collapses. - property chip-text; - changed state => { - if root.state.filter != "" { - root.chip-text = root.state.filter; - } - } - - function move(key: NavKey, shift: bool) { - root.reveal(root.navigate(key, shift, floor(list.visible-height / Columns.row-height))); - } - // Scrolls just enough to show `row`. function reveal(row: int) { if row < 0 { @@ -264,47 +403,28 @@ export component DetailsView inherits Rectangle { background: Theme.surface; forward-focus: keys; - keys := FocusScope { - key-pressed(event) => { - if event.modifiers.control && (event.text == "a" || event.text == "A") { - root.select-all(); - return accept; - } - if event.modifiers.control && (event.text == "h" || event.text == "H") { - root.toggle-hidden(); - return accept; - } - if event.modifiers.control || event.modifiers.alt || event.modifiers.meta { - return reject; - } - if event.text == Key.UpArrow { - root.move(NavKey.up, event.modifiers.shift); - } else if event.text == Key.DownArrow { - root.move(NavKey.down, event.modifiers.shift); - } else if event.text == Key.Home { - root.move(NavKey.home, event.modifiers.shift); - } else if event.text == Key.End { - root.move(NavKey.end, event.modifiers.shift); - } else if event.text == Key.PageUp { - root.move(NavKey.page-up, event.modifiers.shift); - } else if event.text == Key.PageDown { - root.move(NavKey.page-down, event.modifiers.shift); - } else if event.text == Key.Return { - root.row-activated(-1); - } else if event.text == Key.Escape { - if root.state.filter != "" { - root.filter-edited(""); - } else { - root.clear-selection(); - } - } else if event.text == Key.Backspace { - root.filter-typed("\u{8}"); - } else if event.text != "" && event.text != Key.Tab && event.text != Key.Backtab { - root.filter-typed(event.text); - } else { - return reject; - } - accept + keys := FolderKeys { + state: root.state; + move(key, shift) => { + root.reveal(root.navigate(key, shift, floor(list.visible-height / Columns.row-height))); + } + filter-typed(text) => { + root.filter-typed(text); + } + filter-edited(text) => { + root.filter-edited(text); + } + toggle-hidden => { + root.toggle-hidden(); + } + row-activated(row) => { + root.row-activated(row); + } + select-all => { + root.select-all(); + } + clear-selection => { + root.clear-selection(); } VerticalLayout { @@ -395,115 +515,98 @@ export component DetailsView inherits Rectangle { background: Theme.outline-variant; } - // Filter chip: grows in while typing, collapses when cleared. - Rectangle { - height: root.state.filter != "" ? 32px + 2 * Theme.space-2 : 0; - clip: true; - animate height { duration: Motion.time(Motion.short4); easing: Motion.emphasized-decelerate; } - - HorizontalLayout { - y: 0; - height: 32px + 2 * Theme.space-2; - padding: Theme.space-2; - padding-left: Columns.inset + Theme.space-2; - alignment: start; - - Chip { - kind: ChipKind.assist; - icon: Icons.search; - text: "Filter: " + root.chip-text; - tooltip: "Clear the filter (Esc)"; - clicked => { - root.filter-edited(""); - keys.focus(); - } - } + FilterChip { + state: root.state; + filter-edited(text) => { + root.filter-edited(text); + keys.focus(); } } Rectangle { vertical-stretch: 1; - list := ListView { - visible: root.rows.length > 0; + Rectangle { + x: root.travel-x; + opacity: root.travel-opacity; - for row[i] in root.rows: Rectangle { - height: Columns.row-height; + list := ListView { + visible: root.rows.length > 0; - if row.header: Text { - x: Columns.inset + Theme.space-4; - width: parent.width - 2 * (Columns.inset + Theme.space-4); - height: parent.height; - text: row.name; - color: Theme.primary; - font-size: Theme.label-medium.size; - font-weight: Theme.label-medium.weight; - vertical-alignment: bottom; - overflow: elide; - accessible-role: text; - } - - if !row.header: ListRow { - x: Columns.inset; - width: parent.width - 2 * Columns.inset; - focusable: false; - icon: row.glyph; - badge: row.badge; - title: row.name; - selected: row.selected; - force-state: row.cursor && keys.has-focus ? ForceState.focused : ForceState.none; - clicked => { - keys.focus(); - root.row-clicked(i, self.modifiers.control, self.modifiers.shift); - } - double-clicked => { - root.row-activated(i); - } - - Cell { - width: Columns.size; - text: row.size; - end-aligned: true; - color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; - } - - if !root.compact: Cell { - width: Columns.kind; - text: row.kind; - color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; - } - - Cell { - width: Columns.modified; - text: row.modified; - color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; - } + for row[i] in root.rows: Rectangle { + // Entering rows grow from nothing, leaving rows collapse; both clip + // their content while they do. Others slide from where they were. + property size: row.enter ? root.settle : row.leave ? 1 - root.settle : 1; + height: Columns.row-height * self.size; + clip: row.enter || row.leave; Rectangle { - width: Columns.tools; + // Centred in the row while it grows or collapses. + y: Columns.row-height * (row.from-y * (1 - root.settle) - (1 - parent.size) / 2); + height: Columns.row-height; + opacity: parent.size; + + if row.header: Text { + x: Columns.inset + Theme.space-4; + width: parent.width - 2 * (Columns.inset + Theme.space-4); + height: parent.height; + text: row.name; + color: Theme.primary; + font-size: Theme.label-medium.size; + font-weight: Theme.label-medium.weight; + vertical-alignment: bottom; + overflow: elide; + accessible-role: text; + } + + if !row.header: ListRow { + x: Columns.inset; + width: parent.width - 2 * Columns.inset; + focusable: false; + icon: row.glyph; + badge: row.badge; + title: row.name; + selected: row.selected; + force-state: row.cursor && keys.has-focus ? ForceState.focused : ForceState.none; + clicked => { + keys.focus(); + root.row-clicked(i, self.modifiers.control, self.modifiers.shift); + } + double-clicked => { + root.row-activated(i); + } + + Cell { + width: Columns.size; + text: row.size; + end-aligned: true; + color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; + } + + if !root.compact: Cell { + width: Columns.kind; + text: row.kind; + color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; + } + + Cell { + width: Columns.modified; + text: row.modified; + color: row.selected ? Theme.on-secondary-container : Theme.on-surface-variant; + } + + Rectangle { + width: Columns.tools; + } + } } } } - } - if root.state.status == FolderStatus.error: Message { - glyph: Icons.error; - title: "Can't open this folder"; - body: root.state.error; - } - - if root.state.status == FolderStatus.loading && root.rows.length == 0: Message { - title: "Loading…"; - } - - if root.state.status == FolderStatus.ready && root.state.items == 0: Message { - glyph: Icons.folder; - title: root.state.filter != "" ? "Nothing matches “" + root.state.filter + "”" - : root.state.hidden > 0 ? "Only hidden items here" - : "This folder is empty"; - body: root.state.filter != "" ? "Press Esc to clear the filter" - : root.state.hidden > 0 ? "Press Ctrl+H to show hidden files" - : ""; + FolderMessages { + state: root.state; + row-count: root.rows.length; + } } } } diff --git a/crates/tunal/ui/views/grid-view.slint b/crates/tunal/ui/views/grid-view.slint new file mode 100644 index 0000000..96f6aa6 --- /dev/null +++ b/crates/tunal/ui/views/grid-view.slint @@ -0,0 +1,332 @@ +import { ListView } from "std-widgets.slint"; +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; +import { Icon, Icons } from "../components/icon.slint"; +import { ForceState, StateLayer } from "../components/state-layer.slint"; +import { IconButton } from "../components/icon-button.slint"; +import { + Columns, DetailRow, FilterChip, FolderKeys, FolderMessages, FolderState, HeaderCell, NavKey, + SortColumn, +} from "details-view.slint"; + +// One line of the grid: a group header (`rows[start]` is the header row) or up to `columns` +// cells for `rows[start .. start + count]`. Laid out by the folder model for the column count +// the view reports. +export struct GridRow { + header: bool, + start: int, + count: int, + // Header lines above this one, to find its top. + headers-before: int, +} + +global Grid { + out property min-cell-width: 112px; + out property cell-height: 116px; + out property icon-size: 48px; + // Gap around each cell's shape, inside its slot. + out property gap: Theme.space-1; +} + +// One entry of the grid: icon over a two-line name. Selection grows a tonal fill like a +// list row's; the cursor shows the focus ring while the view has focus. +component GridCell inherits StateLayer { + in property entry; + in property cursor-ring; + + property content: root.entry.selected ? Theme.on-secondary-container : Theme.on-surface-variant; + + focusable: false; + border-radius: Theme.corner-md; + squeeze: Motion.squeeze; + ring-offset: -Theme.focus-ring-width; + force-state: root.cursor-ring ? ForceState.focused : ForceState.none; + + accessible-role: list-item; + accessible-label: root.entry.name; + accessible-item-selectable: true; + accessible-item-selected: root.entry.selected; + accessible-action-default => { + self.activate(); + } + + Rectangle { + border-radius: root.border-radius; + background: Theme.secondary-container; + opacity: root.entry.selected ? 1 : 0; + transform-scale: root.entry.selected ? 1 : Motion.squeeze; + animate opacity, transform-scale { + duration: Motion.time(Motion.short4); + easing: Motion.emphasized-decelerate; + } + } + + VerticalLayout { + padding: Theme.space-2; + padding-top: Theme.space-3; + spacing: Theme.space-2; + + HorizontalLayout { + alignment: center; + + Rectangle { + width: Grid.icon-size; + height: Grid.icon-size; + + Icon { + glyph: root.entry.glyph; + size: Grid.icon-size; + color: root.content; + } + + if root.entry.badge != "": Icon { + x: parent.width - self.width; + y: parent.height - self.height; + glyph: root.entry.badge; + size: 18px; + color: root.entry.selected ? Theme.on-secondary-container : Theme.primary; + } + } + } + + Text { + height: 2 * Theme.body-small.line-height; + text: root.entry.name; + color: root.entry.selected ? Theme.on-secondary-container : Theme.on-surface; + font-size: Theme.body-small.size; + font-weight: Theme.body-small.weight; + horizontal-alignment: center; + vertical-alignment: top; + wrap: word-wrap; + overflow: elide; + } + } +} + +// The icon grid of one folder: virtualized lines of cells, as many columns as fit the width +// (reflowed by the model when that changes). Same selection and keyboard as the details view, +// plus Left and Right. +export component GridView inherits Rectangle { + in property <[DetailRow]> rows; + in property <[GridRow]> lines; + in property state; + in property motion: 1; + in property travel-x; + in property travel-opacity: 1; + + callback sort-by(SortColumn); + callback open-sort-menu(length, length); + callback filter-typed(string); + callback filter-edited(string); + callback toggle-hidden(); + callback row-clicked(int, bool, bool); + callback row-activated(int); + callback select-all(); + callback clear-selection(); + // Moves the cursor; returns the line to show, or -1. + callback navigate(NavKey, bool, int) -> int; + // The number of columns that fit, on every change of it. + callback columns-changed(int); + + out property columns: max(1, floor((list.visible-width - 2 * Columns.inset) / Grid.min-cell-width)); + property cell-width: (list.visible-width - 2 * Columns.inset) / root.columns; + property settle: Motion.settle(root.motion); + + // Vertical offset of a moving row from its slot (see DetailRow). + function shift-y(row: DetailRow) -> length { + Grid.cell-height * (row.to-y + (row.from-y - row.to-y) * (1 - root.settle)) + + Columns.row-height * (row.to-h + (row.from-h - row.to-h) * (1 - root.settle)) + } + + changed columns => { + root.columns-changed(root.columns); + } + + public function focus-view() { + keys.focus(); + } + + // Scrolls just enough to show `line` (header lines above it are shorter). + function reveal(line: int) { + if line < 0 || line >= root.lines.length { + return; + } + let headers = root.lines[line].headers-before; + let top = headers * Columns.row-height + (line - headers) * Grid.cell-height; + let height = root.lines[line].header ? Columns.row-height : Grid.cell-height; + if top < -list.content-y { + list.content-y = -top; + } else if top + height > -list.content-y + list.visible-height { + list.content-y = -(top + height - list.visible-height); + } + } + + background: Theme.surface; + forward-focus: keys; + + keys := FolderKeys { + state: root.state; + horizontal: true; + move(key, shift) => { + root.reveal(root.navigate(key, shift, max(1, floor(list.visible-height / Grid.cell-height)))); + } + filter-typed(text) => { + root.filter-typed(text); + } + filter-edited(text) => { + root.filter-edited(text); + } + toggle-hidden => { + root.toggle-hidden(); + } + row-activated(row) => { + root.row-activated(row); + } + select-all => { + root.select-all(); + } + clear-selection => { + root.clear-selection(); + } + + VerticalLayout { + // The sort in use (click flips its direction) and the sort menu, in the same strip + // as the details view's column header and as wide as the cells (they end at the + // scrollbar). + Rectangle { + height: Columns.header-height; + HorizontalLayout { + x: 0; + width: list.visible-width; + height: parent.height; + padding-left: Columns.inset + Grid.gap; + padding-right: Columns.inset + Theme.space-2; + + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + + HorizontalLayout { + alignment: start; + + HeaderCell { + text: root.state.sort == SortColumn.size ? "Size" + : root.state.sort == SortColumn.type ? "Type" + : root.state.sort == SortColumn.modified ? "Modified" + : root.state.sort == SortColumn.playlist ? "Playlist" + : "Name"; + active: true; + descending: root.state.descending; + clicked => { + root.sort-by(root.state.sort); + keys.focus(); + } + } + } + } + + VerticalLayout { + alignment: center; + width: Columns.tools; + + IconButton { + icon: Icons.sort; + size: Columns.tools; + icon-size: 20px; + tooltip: "Sort and view options"; + clicked => { + root.open-sort-menu( + self.absolute-position.x + self.width, + self.absolute-position.y + self.height); + } + } + } + } + } + + Rectangle { + height: Theme.hairline; + background: Theme.outline-variant; + } + + FilterChip { + state: root.state; + filter-edited(text) => { + root.filter-edited(text); + keys.focus(); + } + } + + Rectangle { + vertical-stretch: 1; + + Rectangle { + x: root.travel-x; + opacity: root.travel-opacity; + + list := ListView { + visible: root.lines.length > 0; + + for line in root.lines: Rectangle { + height: line.header ? Columns.row-height : Grid.cell-height; + + if line.header: Text { + property entry: root.rows[line.start]; + x: Columns.inset + Theme.space-4; + width: parent.width - 2 * (Columns.inset + Theme.space-4); + y: root.shift-y(self.entry); + height: parent.height; + text: self.entry.name; + color: Theme.primary; + font-size: Theme.label-medium.size; + font-weight: Theme.label-medium.weight; + vertical-alignment: bottom; + overflow: elide; + opacity: self.entry.enter ? root.settle : self.entry.leave ? 1 - root.settle : 1; + accessible-role: text; + } + + if !line.header: Rectangle { + for c in line.count: Rectangle { + property index: line.start + c; + property entry: root.rows[self.index]; + // Entering cells fade and grow in, leaving ones fade and + // shrink out; the rest slide from their old slot. + property size: self.entry.enter ? root.settle : self.entry.leave ? 1 - root.settle : 1; + x: Columns.inset + root.cell-width + * (c + self.entry.to-x + (self.entry.from-x - self.entry.to-x) * (1 - root.settle)); + y: root.shift-y(self.entry); + width: root.cell-width; + height: Grid.cell-height; + opacity: self.size; + transform-scale: Motion.enter-scale + (1 - Motion.enter-scale) * self.size; + + GridCell { + x: Grid.gap; + y: Grid.gap; + width: parent.width - 2 * Grid.gap; + height: parent.height - 2 * Grid.gap; + entry: parent.entry; + cursor-ring: parent.entry.cursor && keys.has-focus; + clicked => { + keys.focus(); + root.row-clicked(parent.index, self.modifiers.control, self.modifiers.shift); + } + double-clicked => { + root.row-activated(parent.index); + } + } + } + } + } + } + + FolderMessages { + state: root.state; + row-count: root.rows.length; + } + } + } + } + } +} diff --git a/crates/tunal/ui/views/view-switch.slint b/crates/tunal/ui/views/view-switch.slint new file mode 100644 index 0000000..db41b6b --- /dev/null +++ b/crates/tunal/ui/views/view-switch.slint @@ -0,0 +1,232 @@ +import { Theme } from "../theme.slint"; +import { Motion, MotionClock, MotionPrefs } from "../motion.slint"; +import { Icon, Icons } from "../components/icon.slint"; +import { StateLayer } from "../components/state-layer.slint"; +import { DetailRow, DetailsView, FolderState, NavKey, SortColumn, Travel, ViewMode } from "details-view.slint"; +import { GridRow, GridView } from "grid-view.slint"; + +global Segments { + out property width: 40px; + out property height: 32px; +} + +// One icon segment of the switch: tint and squeeze, no fill of its own (the pill slides +// under it). +component Segment inherits StateLayer { + in property icon; + in property active; + + width: Segments.width; + height: Segments.height; + border-radius: Theme.corner-full(self.height); + squeeze: Motion.squeeze-small; + tint: root.active ? Theme.on-secondary-container : Theme.on-surface-variant; + accessible-role: button; + accessible-label: root.tooltip; + accessible-checkable: true; + accessible-checked: root.active; + accessible-action-default => { + self.activate(); + } + + Icon { + x: (root.width - self.width) / 2; + y: (root.height - self.height) / 2; + glyph: root.icon; + size: 20px; + color: root.tint; + animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; } + } +} + +// Segmented control for the view mode: details or grid. The selected pill slides between +// the segments. +export component ViewSwitch inherits Rectangle { + in property mode; + callback selected(ViewMode); + + width: 2 * Segments.width + 2 * Theme.hairline; + height: Segments.height + 2 * Theme.hairline; + border-radius: Theme.corner-full(self.height); + border-width: Theme.hairline; + border-color: Theme.outline-variant; + + Rectangle { + x: Theme.hairline + (root.mode == ViewMode.grid ? Segments.width : 0); + y: Theme.hairline; + width: Segments.width; + height: Segments.height; + border-radius: Theme.corner-full(self.height); + background: Theme.secondary-container; + animate x { duration: Motion.time(Motion.short4); easing: Motion.emphasized-decelerate; } + } + + HorizontalLayout { + padding: Theme.hairline; + + Segment { + icon: Icons.view-list; + tooltip: "Details view"; + active: root.mode == ViewMode.details; + clicked => { + root.selected(ViewMode.details); + } + } + + Segment { + icon: Icons.grid-view; + tooltip: "Grid view"; + active: root.mode == ViewMode.grid; + clicked => { + root.selected(ViewMode.grid); + } + } + } +} + +// One pane's folder: the details and grid views over the same rows, cross-faded when the +// mode (`state.mode`, kept by the folder model) changes. Owns the two transition clocks: +// list changes (rows) and folder opening (content slides in the direction of travel). +export component FolderView inherits Rectangle { + in property <[DetailRow]> rows; + in property <[GridRow]> lines; + in property state; + + callback sort-by(SortColumn); + callback open-sort-menu(length, length); + callback filter-typed(string); + callback filter-edited(string); + callback toggle-hidden(); + callback row-clicked(int, bool, bool); + callback row-activated(int); + callback select-all(); + callback clear-selection(); + callback navigate(NavKey, bool, int) -> int; + callback columns-changed(int); + // The list change of `state.motion` has ended: leaving rows can go. + callback motion-settled(); + + property grid: root.state.mode == ViewMode.grid; + + public function focus-view() { + if root.grid { + grid.focus-view(); + } else { + details.focus-view(); + } + } + + changed grid => { + root.focus-view(); + } + + list-clock := MotionClock { + epoch: root.state.motion; + duration: MotionPrefs.list-change; + settled => { + root.motion-settled(); + } + } + + travel-clock := MotionClock { + epoch: root.state.travel-epoch; + duration: Motion.time(Motion.medium1); + } + + property travel-settle: Motion.settle(travel-clock.progress); + property travel-side: root.state.travel == Travel.into || root.state.travel == Travel.forward ? 1 + : root.state.travel == Travel.none ? 0 : -1; + property travel-x: Motion.travel-shift * root.travel-side * (1 - root.travel-settle); + property travel-opacity: travel-clock.running ? root.travel-settle : 1; + + background: Theme.surface; + + details := DetailsView { + rows: root.rows; + state: root.state; + motion: list-clock.progress; + travel-x: root.travel-x; + travel-opacity: root.travel-opacity; + opacity: root.grid ? 0 : 1; + visible: self.opacity > 0; + animate opacity { duration: Motion.time(Motion.short4); easing: Motion.standard; } + sort-by(column) => { + root.sort-by(column); + } + open-sort-menu(x, y) => { + root.open-sort-menu(x, y); + } + filter-typed(text) => { + root.filter-typed(text); + } + filter-edited(text) => { + root.filter-edited(text); + } + toggle-hidden => { + root.toggle-hidden(); + } + row-clicked(row, ctrl, shift) => { + root.row-clicked(row, ctrl, shift); + } + row-activated(row) => { + root.row-activated(row); + } + select-all => { + root.select-all(); + } + clear-selection => { + root.clear-selection(); + } + navigate(key, shift, page) => { + root.navigate(key, shift, page) + } + } + + grid := GridView { + rows: root.rows; + lines: root.lines; + state: root.state; + motion: list-clock.progress; + travel-x: root.travel-x; + travel-opacity: root.travel-opacity; + opacity: root.grid ? 1 : 0; + visible: self.opacity > 0; + animate opacity { duration: Motion.time(Motion.short4); easing: Motion.standard; } + sort-by(column) => { + root.sort-by(column); + } + open-sort-menu(x, y) => { + root.open-sort-menu(x, y); + } + filter-typed(text) => { + root.filter-typed(text); + } + filter-edited(text) => { + root.filter-edited(text); + } + toggle-hidden => { + root.toggle-hidden(); + } + row-clicked(row, ctrl, shift) => { + root.row-clicked(row, ctrl, shift); + } + row-activated(row) => { + root.row-activated(row); + } + select-all => { + root.select-all(); + } + clear-selection => { + root.clear-selection(); + } + navigate(key, shift, page) => { + root.navigate(key, shift, page) + } + columns-changed(n) => { + root.columns-changed(n); + } + init => { + root.columns-changed(self.columns); + } + } +} diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 6b56fa7..61eb541 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -34,3 +34,4 @@ D-029 — 2026-11-18 — Orchestration: backend-only plans whose dependencies ar D-030 — 2026-11-18 — Playlist sort refined (supersedes D-021's details, keeps its UI): candidate playlists come from the viewed folder and from /Playlists (also playlists/Playlist/playlist); only playlists with ≥ 1 track in the viewed folder are offered, one "Playlist sort" option each; preselected = the playlist named after the folder, else the one with most tracks from it; subfolders sort by their first listed track; tracks that moved still match by file name; formats .m3u .m3u8 .pls .xspf .wpl, text decoded utf-8 → utf-16 → cp1252 → latin-1; ordering stays listed-first in playlist order, rest natural name order, desc reverses — orchestrator, from the user's old prototype behaviour (D-028) — S008. D-031 — 2026-11-18 — Floating surfaces don't use `PopupWindow` (it closes without exit motion): `Menu` and `Dialog` inherit `Overlay` and `ToastStack` is a plain layer, each placed last in the window at `width: 100%; height: 100%` in the order ToastStack, Dialog, Menu; they open with window coordinates and play exit motion by animating a `progress` that reverses mid-flight. Dialogs never close themselves (owner calls `close()` from `action`); toast models are owned outside (`closing` ends one, `removed(index)` drops it). Tooltips stay on `PopupWindow` (fade in, leave at once) — S005 — every UI plan with menus, dialogs or toasts (S010–S013, S018–S031). D-032 — 2026-11-18 — Folder views use `folder::FolderModel` (one per view, `Rc`, a Slint `Model` of `DetailRow`s formatted on demand; worker results reach it through `upgrade_in_event_loop` + `as_any` downcast and carry a generation); selection is a set of raw names (`click`, `navigate`, `select_all`); sort menus are built in Rust as `[MenuItem]` and opened at window level (D-031); list rows set `StateLayer.focusable: false` and the view's `FocusScope` owns the keys; watch events are hints (unchanged stat is ignored: the local backend also reports reads) — S008 — S009–S015. +D-033 — 2026-11-18 — View mode and list motion: `ViewMode { details, grid }` (views/details-view.slint) lives in `folder::Settings::mode`, so one per `FolderModel` = per pane, carried over between folders like the sort, and reaches the views as `FolderState.mode` (`set_mode`); `.directory` view settings read and write that field. `FolderView` (views/view-switch.slint) stacks both views and cross-fades them; `ViewSwitch` is the segmented control. List changes (sort, filter, hidden, watch, playlist re-sort; not listing chunks) animate from Rust-computed per-row `from`/`to` offsets and leaving copies, drawn from one `MotionClock` (motion.slint, `animation-tick()` while running only), length `MotionPrefs.list-change` (0 under reduced motion = no transition); instant above 2000 rows. Opening with `open_travel(uri, Travel)` slides content from the right (into, forward) or left (up, back) — S009 — S010, S015, S018 (grid thumbnails in `GridCell`). diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 33de0f0..271d826 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -85,5 +85,12 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Not done: audible check not done (volume 0); cancel path of waveforms exercised only by code; mid-stream spec changes skip the packet; device loss mid-play reports `Output` error and stops (no reconnect). - Later: waveform worker pool instead of a thread per request; resume on default-device change. +## S009 — Icon grid view and list motion +- Done: `views/grid-view.slint` `GridView` (ListView of `GridRow { header, start, count, headers-before }` lines from `FolderModel::grid_lines()`; columns = visible width / 112 px, reported by `columns-changed` → `set_columns`; cells stretch; 48 px icon, two-line word-wrapped elided name, selection fill grows like ListRow, cursor ring; Left/Right/Up/Down/Page/Home/End by grid line). `views/view-switch.slint` `ViewSwitch { mode; selected(ViewMode) }` (sliding pill) and `FolderView` (both views over one model, cross-fade, list and travel clocks; same callbacks as DetailsView + `columns-changed`, `motion-settled`, in `lines`). Shared `FolderKeys`, `FilterChip`, `FolderMessages`, `HeaderCell`, `Columns` exported from details-view.slint; `NavKey.left/right`; `Travel`, `ViewMode`. +- `folder/motion.rs`: keys per row (raw name / header label), leaving copies merged after their old neighbour, details `from-y` (rows) with grow/collapse heights, grid `from`/`to` in cells, cell lines and header lines; interruptions continue from drawn positions; > 2000 rows instant. Model API: `set_mode`, `set_columns`, `grid_lines`, `motion_settled`, `set_list_time`, `open_travel` (`activate` = `Travel::Into`). Tokens: `MotionPrefs.list-change`, `Motion.travel-shift`, `Motion.settle()`, `MotionClock`; icon `view-list`. Mode location: D-033. +- Verified: real tree (with S010's shell, which wires FolderView/ViewSwitch): workspace build, clippy -D warnings, fmt --check, literal grep empty; details + grid screenshots light + dark in the shell (grid only after keeping the Shell alive in a scratch copy: S010's screenshot path drops it, reported). In a scratch copy with S010 reverted: screenshots details/grid light + dark, 720×480 grouped grid, selection + cursor; a dump of row motion data for sort flip, filter, interrupted filter, grid sort and grid filter; first frame after a sort flip draws the old order (clock starts before paint) in both views; with `TUNAL_REDUCED_MOTION=1` the new order at once. Literal grep empty. +- Not done: navigation slide and live motion not watched (no event loop offscreen; S035); `tunal --screenshot` in the grid view shows one column until S010 keeps the Shell alive in its screenshot path. Screenshot env `TUNAL_VIEW=grid` added. +- Later: a live switch to reduced motion during a change leaves its leaving rows until the next change; entering rows interrupted mid-growth jump to full height; grid thumbnails (S018) go in `GridCell`. + ## Later -