File presets in folders that open and close, as collections do
The presets menu and sheet listed every preset under flat section headings, seventy rows to scroll past. They now list folders, closed until opened, with how many presets each holds; opening one shows what is inside it, folders and presets indented beneath. A category is spelled in the name: "Portraits/Warm skin" is Warm skin in a Portraits folder under Yours. The file format does not change, so an older build lists the whole path as the name; renaming a preset is how it moves, and saving or renaming into a folder opens the way to it. A Lightroom import names what it reads after the folders below the one chosen, and a "/" in a displayed name becomes "∕" so it files nothing. The shipped film sections become Film › Colour, Cinema and Black and white. The tree is built and flattened in Rust (PresetTree), each row carrying its depth, and which folders are open is remembered for the session. A PopupWindow keeps the size it was shown at, so a folder opened in the menu pushed its contents under "Save or manage…"; the menu is shown again after each toggle to take its new height. That is a function on the rail because Slint 1.17 generates Rust that does not compile for a popup's close() reached from inside the popup. The sheet's list takes a preferred height of up to 400px, since a Flickable reports next to nothing and an opened folder showed three rows. The manual describes the folders and naming. Its pictures show the menu with Film › Colour open, and a black-and-white stock applied from Film › Black and white; the scenes aim popup rows from the rail's entry, and pick the menu's "Film" over the develop column's film chooser.
This commit is contained in:
+333
-27
@@ -723,6 +723,11 @@ pub fn wire(
|
||||
pub struct NamedPresets {
|
||||
store: PresetStore,
|
||||
library: RefCell<PresetLibrary>,
|
||||
/// The category folders the photographer has opened, by key (see
|
||||
/// [`PresetTree`]). Every folder starts closed, so a list of seventy
|
||||
/// presets arrives as six lines; for the session, not saved, as the
|
||||
/// collections tree remembers what it had open.
|
||||
open: RefCell<std::collections::HashSet<String>>,
|
||||
}
|
||||
|
||||
impl NamedPresets {
|
||||
@@ -755,6 +760,7 @@ impl NamedPresets {
|
||||
Rc::new(Self {
|
||||
store,
|
||||
library: RefCell::new(library),
|
||||
open: RefCell::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -813,33 +819,77 @@ impl NamedPresets {
|
||||
dr_pipeline::bundled::lookup(&self.library.borrow(), name)
|
||||
}
|
||||
|
||||
/// Every row the sheet lists, headings included.
|
||||
/// Every row the menu and the sheet list: the category folders, and
|
||||
/// the presets inside the ones that are open.
|
||||
///
|
||||
/// The photographer's own section is left out while it is empty: a
|
||||
/// heading over nothing reads as a list that failed to load.
|
||||
/// folder over nothing reads as a list that failed to load.
|
||||
pub fn rows(&self) -> Vec<crate::PresetRow> {
|
||||
use dr_pipeline::bundled::Origin;
|
||||
let mut rows = Vec::new();
|
||||
for section in dr_pipeline::bundled::listing(&self.library.borrow()) {
|
||||
if section.rows.is_empty() {
|
||||
continue;
|
||||
let open = self.open.borrow();
|
||||
self.tree().flatten(&|key| open.contains(key))
|
||||
}
|
||||
|
||||
/// Every row with every folder open — what the tests read.
|
||||
#[cfg(test)]
|
||||
pub fn all_rows(&self) -> Vec<crate::PresetRow> {
|
||||
self.tree().flatten(&|_| true)
|
||||
}
|
||||
|
||||
/// Open a closed folder, or close an open one.
|
||||
pub fn toggle(&self, key: &str) {
|
||||
let mut open = self.open.borrow_mut();
|
||||
if !open.remove(key) {
|
||||
open.insert(key.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
/// Open every folder `name` is filed in, so a preset just saved or
|
||||
/// renamed is on screen rather than inside a closed folder.
|
||||
fn reveal(&self, name: &str) {
|
||||
let name = name.trim();
|
||||
// A changed copy lists in its shipped section, which the name does
|
||||
// not say; your own are filed by the name's own categories.
|
||||
let keys = match dr_pipeline::bundled::sections()
|
||||
.into_iter()
|
||||
.find(|section| section.presets.contains(name))
|
||||
{
|
||||
Some(section) => PresetTree::keys(SHIPPED, section.title),
|
||||
None => {
|
||||
let mut keys = vec![YOURS.to_string()];
|
||||
if let Some((folders, _)) = name.rsplit_once('/') {
|
||||
keys.extend(PresetTree::keys(YOURS, folders));
|
||||
}
|
||||
keys
|
||||
}
|
||||
rows.push(crate::PresetRow {
|
||||
heading: section.title.into(),
|
||||
name: Default::default(),
|
||||
origin: crate::PresetOrigin::Shipped,
|
||||
});
|
||||
rows.extend(section.rows.into_iter().map(|row| crate::PresetRow {
|
||||
heading: Default::default(),
|
||||
name: row.name.into(),
|
||||
origin: match row.origin {
|
||||
};
|
||||
self.open.borrow_mut().extend(keys);
|
||||
}
|
||||
|
||||
/// The listing, filed into folders.
|
||||
fn tree(&self) -> PresetTree {
|
||||
use dr_pipeline::bundled::Origin;
|
||||
let mut tree = PresetTree::default();
|
||||
for section in dr_pipeline::bundled::listing(&self.library.borrow()) {
|
||||
for row in section.rows {
|
||||
let origin = match row.origin {
|
||||
Origin::Yours => crate::PresetOrigin::Yours,
|
||||
Origin::Shipped => crate::PresetOrigin::Shipped,
|
||||
Origin::Changed => crate::PresetOrigin::Changed,
|
||||
},
|
||||
}));
|
||||
};
|
||||
match section.id {
|
||||
// Your own are filed by their names' own categories,
|
||||
// under one folder of their own.
|
||||
None => tree.file(YOURS, section.title, &row.name, origin),
|
||||
// A shipped preset's name is a name, not a path: the
|
||||
// section title is its category.
|
||||
Some(_) => {
|
||||
let (root, label) = (SHIPPED, section.title);
|
||||
tree.file_in(root, label, &row.name, &row.name, origin)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
rows
|
||||
tree
|
||||
}
|
||||
|
||||
/// Whether a preset is stored under `name`.
|
||||
@@ -936,6 +986,183 @@ fn import_presets(w: &AppWindow, named: &Rc<NamedPresets>, path: &Path) {
|
||||
render_named(w, named);
|
||||
}
|
||||
|
||||
/// The key of the photographer's own folder, and the prefix of every
|
||||
/// folder inside it. Keys are never shown; they only have to stay the same
|
||||
/// while the list is rebuilt around them.
|
||||
const YOURS: &str = "yours";
|
||||
/// The prefix of every shipped folder's key.
|
||||
const SHIPPED: &str = "shipped";
|
||||
|
||||
/// TRACES: FR-DEV-6
|
||||
/// The presets filed into folders, before they are flattened into rows.
|
||||
///
|
||||
/// # Categories are paths
|
||||
///
|
||||
/// A preset called `Portraits/Warm skin` is `Warm skin`, filed in
|
||||
/// `Portraits`. The category is spelled in the name rather than stored
|
||||
/// beside it, which costs nothing in the file format: an older build reads
|
||||
/// the same file and lists the whole path as the name. Renaming is how a
|
||||
/// preset moves, and a Lightroom import names what it reads after the
|
||||
/// folders it was in (`dr_preset_xmp::read_path`). Shipped sections use the
|
||||
/// same spelling for their titles, so `Film/Colour` is a folder in `Film`.
|
||||
///
|
||||
/// # Flattened in Rust, as the collections tree is
|
||||
///
|
||||
/// Slint cannot nest a repeater inside a `Flickable` with no layout to size
|
||||
/// it, so the rows arrive flat, each carrying its depth, and the list draws
|
||||
/// indentation from that integer.
|
||||
#[derive(Default)]
|
||||
struct PresetTree {
|
||||
/// Top-level folders, in the order they were first filed into.
|
||||
folders: Vec<Folder>,
|
||||
}
|
||||
|
||||
struct Folder {
|
||||
key: String,
|
||||
label: String,
|
||||
folders: Vec<Folder>,
|
||||
presets: Vec<(String, String, crate::PresetOrigin)>,
|
||||
}
|
||||
|
||||
impl Folder {
|
||||
fn new(key: String, label: &str) -> Self {
|
||||
Self {
|
||||
key,
|
||||
label: label.to_string(),
|
||||
folders: Vec::new(),
|
||||
presets: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The folder labelled `label` directly inside this one, made if absent.
|
||||
fn child(&mut self, label: &str) -> &mut Folder {
|
||||
let at = match self.folders.iter().position(|f| f.label == label) {
|
||||
Some(at) => at,
|
||||
None => {
|
||||
let key = format!("{}/{label}", self.key);
|
||||
self.folders.push(Folder::new(key, label));
|
||||
self.folders.len() - 1
|
||||
}
|
||||
};
|
||||
&mut self.folders[at]
|
||||
}
|
||||
|
||||
/// How many presets this folder holds, however deep.
|
||||
fn count(&self) -> usize {
|
||||
self.presets.len() + self.folders.iter().map(Folder::count).sum::<usize>()
|
||||
}
|
||||
}
|
||||
|
||||
impl PresetTree {
|
||||
/// The keys of `path`'s folders under `root`, outermost first — what
|
||||
/// has to be open for something filed at `path` to be on screen.
|
||||
fn keys(root: &str, path: &str) -> Vec<String> {
|
||||
let mut key = root.to_string();
|
||||
let mut keys = Vec::new();
|
||||
for part in path.split('/').filter(|p| !p.is_empty()) {
|
||||
key = format!("{key}/{part}");
|
||||
keys.push(key.clone());
|
||||
}
|
||||
keys
|
||||
}
|
||||
|
||||
/// The top-level folder `label`, under the key prefix `root`.
|
||||
fn top(&mut self, key: String, label: &str) -> &mut Folder {
|
||||
let at = match self.folders.iter().position(|f| f.key == key) {
|
||||
Some(at) => at,
|
||||
None => {
|
||||
self.folders.push(Folder::new(key, label));
|
||||
self.folders.len() - 1
|
||||
}
|
||||
};
|
||||
&mut self.folders[at]
|
||||
}
|
||||
|
||||
/// File `name` into `root`'s folder called `title`, its own categories
|
||||
/// taken from the name.
|
||||
fn file(&mut self, root: &str, title: &str, name: &str, origin: crate::PresetOrigin) {
|
||||
let mut folder = self.top(root.to_string(), title);
|
||||
let mut parts: Vec<&str> = name.split('/').map(str::trim).collect();
|
||||
// A name that is all separators still has to be applicable: its
|
||||
// leaf is the whole name.
|
||||
let leaf = parts.pop().filter(|l| !l.is_empty()).unwrap_or(name);
|
||||
for part in parts.into_iter().filter(|p| !p.is_empty()) {
|
||||
folder = folder.child(part);
|
||||
}
|
||||
folder
|
||||
.presets
|
||||
.push((leaf.to_string(), name.to_string(), origin));
|
||||
}
|
||||
|
||||
/// File `name`, shown as `label`, at the category path `path`.
|
||||
fn file_in(
|
||||
&mut self,
|
||||
root: &str,
|
||||
path: &str,
|
||||
label: &str,
|
||||
name: &str,
|
||||
origin: crate::PresetOrigin,
|
||||
) {
|
||||
let mut parts = path.split('/').filter(|p| !p.is_empty());
|
||||
let Some(first) = parts.next() else { return };
|
||||
let mut folder = self.top(format!("{root}/{first}"), first);
|
||||
for part in parts {
|
||||
folder = folder.child(part);
|
||||
}
|
||||
folder
|
||||
.presets
|
||||
.push((label.to_string(), name.to_string(), origin));
|
||||
}
|
||||
|
||||
/// The rows, with the contents of every folder `open` says is open.
|
||||
///
|
||||
/// Folders before presets at each level, each in the order filed —
|
||||
/// which for your own is by name, as the library stores them.
|
||||
fn flatten(&self, open: &dyn Fn(&str) -> bool) -> Vec<crate::PresetRow> {
|
||||
fn visit(
|
||||
folder: &Folder,
|
||||
depth: i32,
|
||||
open: &dyn Fn(&str) -> bool,
|
||||
rows: &mut Vec<crate::PresetRow>,
|
||||
) {
|
||||
let expanded = open(&folder.key);
|
||||
rows.push(crate::PresetRow {
|
||||
folder: true,
|
||||
key: folder.key.clone().into(),
|
||||
label: folder.label.clone().into(),
|
||||
depth,
|
||||
expanded,
|
||||
count: folder.count() as i32,
|
||||
name: Default::default(),
|
||||
origin: crate::PresetOrigin::Shipped,
|
||||
});
|
||||
if !expanded {
|
||||
return;
|
||||
}
|
||||
for child in &folder.folders {
|
||||
visit(child, depth + 1, open, rows);
|
||||
}
|
||||
for (label, name, origin) in &folder.presets {
|
||||
rows.push(crate::PresetRow {
|
||||
folder: false,
|
||||
key: Default::default(),
|
||||
label: label.clone().into(),
|
||||
depth: depth + 1,
|
||||
expanded: false,
|
||||
count: 0,
|
||||
name: name.clone().into(),
|
||||
origin: *origin,
|
||||
});
|
||||
}
|
||||
}
|
||||
let mut rows = Vec::new();
|
||||
for folder in self.folders.iter().filter(|f| f.count() > 0) {
|
||||
visit(folder, 0, open, &mut rows);
|
||||
}
|
||||
rows
|
||||
}
|
||||
}
|
||||
|
||||
/// Push the listing onto the window.
|
||||
pub fn render_named(window: &AppWindow, named: &Rc<NamedPresets>) {
|
||||
window.set_preset_rows(slint::ModelRc::new(slint::VecModel::from(named.rows())));
|
||||
@@ -963,6 +1190,17 @@ pub fn wire_named(
|
||||
|
||||
render_named(window, &named);
|
||||
|
||||
// --- open and close a category folder ---------------------------------
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let named = named.clone();
|
||||
window.on_toggle_preset_folder(move |key| {
|
||||
let Some(w) = weak.upgrade() else { return };
|
||||
named.toggle(&key);
|
||||
render_named(&w, &named);
|
||||
});
|
||||
}
|
||||
|
||||
// --- save the open edit under a name ---------------------------------
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
@@ -980,6 +1218,7 @@ pub fn wire_named(
|
||||
match named.insert(&name, preset) {
|
||||
Ok(()) => {
|
||||
w.set_preset_name_error(Default::default());
|
||||
named.reveal(&name);
|
||||
render_named(&w, &named);
|
||||
}
|
||||
Err(e) => w.set_preset_name_error(e.message().into()),
|
||||
@@ -1134,6 +1373,9 @@ pub fn wire_named(
|
||||
// name it had, which is what this restores.
|
||||
let from = from.to_string();
|
||||
let to = to.to_string();
|
||||
// Renaming is how a preset changes folder, so the one it
|
||||
// moved into is opened to show where it went.
|
||||
named.reveal(&to);
|
||||
if let Err(e) = named.persist(move |library| {
|
||||
let _ = library.rename(&to, &from);
|
||||
}) {
|
||||
@@ -1509,14 +1751,18 @@ mod tests {
|
||||
(NamedPresets::open_at(dir.join("presets.drpl")), dir)
|
||||
}
|
||||
|
||||
/// The rows under the heading `title`, as (name, origin).
|
||||
/// The presets directly inside the folder labelled `title`, as (name,
|
||||
/// origin), with every folder open.
|
||||
fn section(presets: &NamedPresets, title: &str) -> Vec<(String, crate::PresetOrigin)> {
|
||||
presets
|
||||
.rows()
|
||||
.into_iter()
|
||||
.skip_while(|r| r.heading != title)
|
||||
.skip(1)
|
||||
.take_while(|r| r.heading.is_empty())
|
||||
let rows = presets.all_rows();
|
||||
let Some(at) = rows.iter().position(|r| r.folder && r.label == title) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let depth = rows[at].depth;
|
||||
rows[at + 1..]
|
||||
.iter()
|
||||
.take_while(|r| r.depth > depth)
|
||||
.filter(|r| !r.folder && r.depth == depth + 1)
|
||||
.map(|r| (r.name.to_string(), r.origin))
|
||||
.collect()
|
||||
}
|
||||
@@ -1536,7 +1782,7 @@ mod tests {
|
||||
#[test]
|
||||
fn an_empty_section_of_your_own_is_not_listed() {
|
||||
let (presets, _dir) = named("no-yours");
|
||||
assert!(presets.rows().iter().all(|r| r.heading != "Yours"));
|
||||
assert!(presets.all_rows().iter().all(|r| r.label != "Yours"));
|
||||
presets.insert("Mine", Preset::default()).unwrap();
|
||||
assert_eq!(
|
||||
section(&presets, "Yours"),
|
||||
@@ -1569,6 +1815,66 @@ mod tests {
|
||||
.all(|(_, origin)| *origin == crate::PresetOrigin::Shipped));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_folder_starts_closed_and_opens_on_its_own() {
|
||||
// Seventy shipped presets arrive as the handful of folders they are
|
||||
// filed in, and opening one lists what is in it and nothing else.
|
||||
let (presets, _dir) = named("closed");
|
||||
let rows = presets.rows();
|
||||
assert!(rows.iter().all(|r| r.folder && r.depth == 0), "{rows:?}");
|
||||
let labels: Vec<_> = rows.iter().map(|r| r.label.to_string()).collect();
|
||||
assert_eq!(labels, ["Essentials", "Skies", "Film"]);
|
||||
|
||||
presets.toggle("shipped/Film");
|
||||
let film: Vec<_> = presets
|
||||
.rows()
|
||||
.into_iter()
|
||||
.filter(|r| r.depth == 1)
|
||||
.map(|r| r.label.to_string())
|
||||
.collect();
|
||||
assert_eq!(film, ["Colour", "Cinema", "Black and white"]);
|
||||
|
||||
presets.toggle("shipped/Film");
|
||||
assert_eq!(presets.rows().len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_slash_in_your_name_files_it_in_a_folder_of_that_name() {
|
||||
let (presets, _dir) = named("categories");
|
||||
presets
|
||||
.insert("Portraits/Warm skin", Preset::default())
|
||||
.unwrap();
|
||||
presets.insert("Loose", Preset::default()).unwrap();
|
||||
|
||||
// The category's own presets, shown by their last part and applied
|
||||
// by the whole name.
|
||||
assert_eq!(
|
||||
section(&presets, "Portraits"),
|
||||
vec![(
|
||||
"Portraits/Warm skin".to_string(),
|
||||
crate::PresetOrigin::Yours
|
||||
)]
|
||||
);
|
||||
let rows = presets.all_rows();
|
||||
let yours = rows.iter().find(|r| r.label == "Yours").unwrap();
|
||||
assert_eq!(yours.count, 2);
|
||||
let warm = rows
|
||||
.iter()
|
||||
.find(|r| r.name == "Portraits/Warm skin")
|
||||
.unwrap();
|
||||
assert_eq!((warm.label.as_str(), warm.depth), ("Warm skin", 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saving_into_a_folder_opens_the_way_to_it() {
|
||||
let (presets, _dir) = named("reveal");
|
||||
presets
|
||||
.insert("Travel/Night/Neon", Preset::default())
|
||||
.unwrap();
|
||||
presets.reveal("Travel/Night/Neon");
|
||||
assert!(presets.rows().iter().any(|r| r.name == "Travel/Night/Neon"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saving_over_a_shipped_name_changes_it_and_deleting_reverts() {
|
||||
let (presets, _dir) = named("override");
|
||||
|
||||
@@ -521,6 +521,8 @@ export component AppWindow inherits Window {
|
||||
callback rename-preset(string, string);
|
||||
callback delete-preset(string);
|
||||
callback preset-name-edited(string);
|
||||
/// A category folder in the preset menu or sheet was opened or closed.
|
||||
callback toggle-preset-folder(string);
|
||||
|
||||
/// TRACES: FR-DEV-6
|
||||
/// Which kinds of edit a copy, paste or preset carries.
|
||||
@@ -1798,6 +1800,7 @@ in property <bool> panel-visible: true;
|
||||
root.apply-preset(name);
|
||||
}
|
||||
manage-presets => { Transfer.open-presets(); }
|
||||
folder-toggled(key) => { root.toggle-preset-folder(key); }
|
||||
}
|
||||
|
||||
// The canvas: compute output composited directly. No CPU
|
||||
@@ -3454,6 +3457,7 @@ in property <bool> panel-visible: true;
|
||||
remove(name) => { root.delete-preset(name); }
|
||||
name-edited(text) => { root.preset-name-edited(text); }
|
||||
dismiss => { root.presets-open = false; }
|
||||
folder-toggled(key) => { root.toggle-preset-folder(key); }
|
||||
}
|
||||
|
||||
// TRACES: FR-EXP-7 | FR-UI-5
|
||||
|
||||
+99
-15
@@ -1,7 +1,8 @@
|
||||
import { Theme } from "theme.slint";
|
||||
import { Button, Field, Caption, PanelHeading } from "widgets.slint";
|
||||
import { Button, Field, Caption, PanelHeading, Label } from "widgets.slint";
|
||||
import { ChoiceChip } from "controls.slint";
|
||||
import { Pickers } from "pickers.slint";
|
||||
import { Icon } from "icons.slint";
|
||||
|
||||
// TRACES: FR-DEV-6
|
||||
// One kind of edit, and whether a copy carries it.
|
||||
@@ -30,18 +31,86 @@ export enum PresetOrigin {
|
||||
}
|
||||
|
||||
// TRACES: FR-DEV-6
|
||||
// One row of the preset sheet: a section heading, or a preset.
|
||||
// One row of the preset tree: a category folder, or a preset inside one.
|
||||
//
|
||||
// One flat list with the headings in it rather than a list of sections, for
|
||||
// the reason the rows are placed by index below: a nested `for` inside a
|
||||
// `Flickable` has no layout to size it, and the arithmetic stays one line.
|
||||
// One flat list with the folders in it rather than a tree, for the reason the
|
||||
// rows are placed by index below: a nested `for` inside a `Flickable` has no
|
||||
// layout to size it, and the arithmetic stays one line. Rust flattens the
|
||||
// tree (`PresetTree` in `presets.rs`) and leaves out whatever is inside a
|
||||
// closed folder, exactly as the collections tree arrives.
|
||||
export struct PresetRow {
|
||||
// Non-empty on a heading row, which names no preset.
|
||||
heading: string,
|
||||
// A category folder rather than a preset.
|
||||
folder: bool,
|
||||
// The folder's identity, handed back when it is opened or closed. Empty
|
||||
// on a preset.
|
||||
key: string,
|
||||
// What the row says: the folder's name, or the preset's name without the
|
||||
// categories it is filed in.
|
||||
label: string,
|
||||
// How many folders deep, from 0 for the top level.
|
||||
depth: int,
|
||||
// Whether a folder is open.
|
||||
expanded: bool,
|
||||
// How many presets a folder holds, however deep.
|
||||
count: int,
|
||||
// The preset's whole name — categories and all — which is what applying,
|
||||
// renaming and deleting it are asked for by. Empty on a folder.
|
||||
name: string,
|
||||
origin: PresetOrigin,
|
||||
}
|
||||
|
||||
// TRACES: FR-DEV-6
|
||||
// A category folder: the disclosure arrow, its name and how many presets it
|
||||
// holds. The whole row opens and closes it — unlike a collection, a folder
|
||||
// here is nothing to select, so there is no second target to keep apart.
|
||||
export component PresetFolderRow inherits TouchArea {
|
||||
in property <PresetRow> entry;
|
||||
in property <length> indent: Theme.indent;
|
||||
|
||||
mouse-cursor: pointer;
|
||||
accessible-role: button;
|
||||
accessible-label: root.entry.label;
|
||||
accessible-description: root.entry.count + " presets";
|
||||
accessible-expandable: true;
|
||||
accessible-expanded: root.entry.expanded;
|
||||
|
||||
Rectangle {
|
||||
border-radius: Theme.radius;
|
||||
background: root.pressed ? Theme.pressed
|
||||
: (root.has-hover ? Theme.hover : transparent);
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.gap-sm + root.entry.depth * root.indent;
|
||||
padding-right: Theme.gap;
|
||||
spacing: Theme.gap-sm;
|
||||
|
||||
Rectangle {
|
||||
width: 14px;
|
||||
Icon {
|
||||
name: root.entry.expanded ? "chevron-down" : "chevron-right";
|
||||
ink: Theme.ink-faint;
|
||||
size: 10px;
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
text: root.entry.label;
|
||||
emphasised: true;
|
||||
horizontal-stretch: 1;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
Caption {
|
||||
text: root.entry.count;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TRACES: FR-DEV-6 | FR-UI-2
|
||||
// Which kinds of edit travel: a multi-select block of chips that wraps.
|
||||
//
|
||||
@@ -125,6 +194,8 @@ export component PresetSheet inherits Rectangle {
|
||||
callback rename(string, string);
|
||||
callback remove(string);
|
||||
callback dismiss();
|
||||
/// A category folder was opened or closed, by its key.
|
||||
callback folder-toggled(string);
|
||||
/// Every keystroke in the name field, so the shell can clear a refusal the
|
||||
/// user has started correcting.
|
||||
callback name-edited(string);
|
||||
@@ -191,8 +262,10 @@ export component PresetSheet inherits Rectangle {
|
||||
if root.can-save: VerticalLayout {
|
||||
spacing: Theme.gap-sm;
|
||||
|
||||
// A `/` files it: "Portraits/Warm skin" goes in a folder
|
||||
// called Portraits, under Yours.
|
||||
name := Field {
|
||||
placeholder: "Name this edit and press return";
|
||||
placeholder: "Name this edit, or Folder/Name, and press return";
|
||||
accepted(text) => {
|
||||
root.save(text);
|
||||
// Cleared only once the shell has accepted it. A
|
||||
@@ -226,6 +299,11 @@ export component PresetSheet inherits Rectangle {
|
||||
// A floor, so the list is not squeezed out of existence by the
|
||||
// field and the button around it on a short window.
|
||||
min-height: 120px;
|
||||
// As tall as the rows, up to a limit: the card is sized from
|
||||
// what it holds, and a Flickable reports next to nothing, so
|
||||
// without this an opened folder showed three rows and hid the
|
||||
// rest behind a scroll.
|
||||
preferred-height: min(root.rows.length * (Theme.touch-target + 2px), 400px);
|
||||
viewport-height: root.rows.length * (Theme.touch-target + 2px);
|
||||
|
||||
for entry[i] in root.rows: Rectangle {
|
||||
@@ -233,15 +311,18 @@ export component PresetSheet inherits Rectangle {
|
||||
width: parent.width;
|
||||
height: Theme.touch-target;
|
||||
|
||||
if entry.heading != "": PanelHeading {
|
||||
text: entry.heading;
|
||||
if entry.folder: PresetFolderRow {
|
||||
entry: entry;
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
vertical-alignment: bottom;
|
||||
clicked => { root.folder-toggled(entry.key); }
|
||||
}
|
||||
|
||||
if entry.heading == "" && root.renaming != entry.name: HorizontalLayout {
|
||||
if !entry.folder && root.renaming != entry.name: HorizontalLayout {
|
||||
spacing: Theme.gap-sm;
|
||||
// Under its folder's name, as the collections tree
|
||||
// indents a child.
|
||||
padding-left: Theme.gap-sm + entry.depth * Theme.indent;
|
||||
|
||||
// The name is the apply button rather than a label
|
||||
// beside one. Applying is what this list is for, and a
|
||||
@@ -249,8 +330,8 @@ export component PresetSheet inherits Rectangle {
|
||||
// gets pressed by accident and then distrusted.
|
||||
Button {
|
||||
text: entry.origin == PresetOrigin.changed
|
||||
? entry.name + " · changed"
|
||||
: entry.name;
|
||||
? entry.label + " · changed"
|
||||
: entry.label;
|
||||
horizontal-stretch: 1;
|
||||
clicked => { root.apply(entry.name); }
|
||||
}
|
||||
@@ -276,8 +357,11 @@ export component PresetSheet inherits Rectangle {
|
||||
// Renaming in place rather than in a second sheet: a
|
||||
// dialogue over a dialogue is where a user loses track of
|
||||
// which one Escape closes.
|
||||
if entry.heading == "" && root.renaming == entry.name: HorizontalLayout {
|
||||
// The whole name, categories and all: renaming is how a
|
||||
// preset moves to another folder.
|
||||
if !entry.folder && root.renaming == entry.name: HorizontalLayout {
|
||||
spacing: Theme.gap-sm;
|
||||
padding-left: Theme.gap-sm + entry.depth * Theme.indent;
|
||||
|
||||
rename-field := Field {
|
||||
text: entry.name;
|
||||
|
||||
+34
-11
@@ -53,8 +53,8 @@
|
||||
import { Theme } from "theme.slint";
|
||||
import { Icon } from "icons.slint";
|
||||
import { ViewMode } from "session.slint";
|
||||
import { PresetRow, PresetOrigin } from "presets.slint";
|
||||
import { PanelHeading, Label, ScrollBar } from "widgets.slint";
|
||||
import { PresetRow, PresetOrigin, PresetFolderRow } from "presets.slint";
|
||||
import { Label, ScrollBar } from "widgets.slint";
|
||||
|
||||
// One tool. A struct rather than four parallel arrays so a row cannot be
|
||||
// half-added — the compiler will not let a new entry omit its icon.
|
||||
@@ -137,6 +137,8 @@ export component ToolRail inherits Rectangle {
|
||||
in property <[PresetRow]> presets;
|
||||
callback preset-picked(string);
|
||||
callback manage-presets();
|
||||
/// A category folder in the menu was opened or closed, by its key.
|
||||
callback folder-toggled(string);
|
||||
|
||||
/// The groups this rail actually draws.
|
||||
///
|
||||
@@ -217,6 +219,15 @@ export component ToolRail inherits Rectangle {
|
||||
// scrolls.
|
||||
private property <length> foot-height: Theme.rail-entry-height + 1px;
|
||||
|
||||
// Show the presets menu again, so it takes the height its rows now want.
|
||||
// A function on the rail rather than the two calls in the row that needs
|
||||
// them: Slint 1.17 generates Rust that does not compile for a popup's
|
||||
// `close()` reached from an element nested inside that popup.
|
||||
function remeasure-menu() {
|
||||
preset-menu.close();
|
||||
preset-menu.show();
|
||||
}
|
||||
|
||||
// One row of the presets menu. Shorter than a touch target for the reason
|
||||
// the film list gives: a row's neighbours are other rows.
|
||||
private property <length> menu-row-height: 32px;
|
||||
@@ -540,15 +551,24 @@ export component ToolRail inherits Rectangle {
|
||||
width: parent.width;
|
||||
height: root.menu-row-height;
|
||||
|
||||
if entry.heading != "": PanelHeading {
|
||||
x: Theme.gap;
|
||||
width: parent.width - 2 * Theme.gap;
|
||||
// Opening a folder rebuilds the rows, and so the
|
||||
// height the menu wants. A PopupWindow takes its
|
||||
// geometry once, when shown — a folder opened in
|
||||
// place stayed the old size and pushed what it
|
||||
// held under "Save or manage…" — so the menu is
|
||||
// shown again, measured afresh, its foot still on
|
||||
// the entry and growing upward.
|
||||
if entry.folder: PresetFolderRow {
|
||||
entry: entry;
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
text: entry.heading;
|
||||
vertical-alignment: bottom;
|
||||
clicked => {
|
||||
root.folder-toggled(entry.key);
|
||||
root.remeasure-menu();
|
||||
}
|
||||
}
|
||||
|
||||
if entry.heading == "": row := TouchArea {
|
||||
if !entry.folder: row := TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
clicked => {
|
||||
root.preset-picked(entry.name);
|
||||
@@ -567,12 +587,15 @@ export component ToolRail inherits Rectangle {
|
||||
: (row.has-hover ? Theme.hover : transparent);
|
||||
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.gap;
|
||||
// Past the folder's arrow, so a preset
|
||||
// lines up with its folder's name.
|
||||
padding-left: Theme.gap-sm + 14px + Theme.gap-sm
|
||||
+ (entry.depth - 1) * Theme.indent;
|
||||
padding-right: Theme.gap;
|
||||
Label {
|
||||
text: entry.origin == PresetOrigin.changed
|
||||
? entry.name + " · changed"
|
||||
: entry.name;
|
||||
? entry.label + " · changed"
|
||||
: entry.label;
|
||||
emphasised: row.has-hover;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
|
||||
Reference in New Issue
Block a user