LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
refactor(ui-egui): shorten functions that format localized messages
Dylan M. Taylor620826cac0b7
diff --git a/crates/ui-egui/src/dialogs/import/task.rs b/crates/ui-egui/src/dialogs/import/task.rsindex da2c1574f..e1f506d5b 100644--- a/crates/ui-egui/src/dialogs/import/task.rs+++ b/crates/ui-egui/src/dialogs/import/task.rs@@ -422,19 +422,14 @@ fn xmp_warnings_text(warnings: &[ImportWarning]) -> String {)}-/// `s` for a count other than one.-fn plural(n: usize) -> &'static str {- if n == 1 { "" } else { "s" }-}-/// The name of the import's one undo step.fn undo_label(task: &ImportTask) -> String {if task.imported == 0 && task.restored > 0 {- crate::i18n::tr_format!("Restore {} Photo{}", task.restored, plural(task.restored))+ crate::i18n::tr_format!("Restore {} Photo{}", task.restored, crate::i18n::plural_s(task.restored))} else if task.restored > 0 {- crate::i18n::tr_format!("Add {} Photo{}, restore {}", task.imported, plural(task.imported), task.restored)+ crate::i18n::tr_format!("Add {} Photo{}, restore {}", task.imported, crate::i18n::plural_s(task.imported), task.restored)} else {- crate::i18n::tr_format!("Add {} Photo{}", task.imported, plural(task.imported))+ crate::i18n::tr_format!("Add {} Photo{}", task.imported, crate::i18n::plural_s(task.imported))}}@@ -481,20 +476,20 @@ fn quiet_finish(app: &mut LightcraftApp, ctx: &egui::Context, task: &ImportTask)if !task.warnings.is_empty() {app.toast_for(ctx, xmp_warnings_text(&task.warnings), 8.0);} else if task.auto && task.imported > 0 {- app.toast(ctx, crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, plural(task.imported)));+ app.toast(ctx, crate::i18n::tr_format!("Auto Import: added {} photo{}", task.imported, crate::i18n::plural_s(task.imported)));} else if !task.auto && task.failed > 0 {- app.toast(ctx, crate::i18n::tr_format!("{} photo{} not readable", task.failed, plural(task.failed)));+ app.toast(ctx, crate::i18n::tr_format!("{} photo{} not readable", task.failed, crate::i18n::plural_s(task.failed)));}}/// What an import did, in a sentence.fn import_summary(app: &LightcraftApp, task: &ImportTask) -> String {let mut msg = if task.cancelled {- crate::i18n::tr_format!("Import cancelled · {} photo{} added", task.imported, plural(task.imported))+ crate::i18n::tr_format!("Import cancelled · {} photo{} added", task.imported, crate::i18n::plural_s(task.imported))} else if task.imported == 0 && task.restored > 0 {- crate::i18n::tr_format!("Restored {} photo{} from Recently Deleted", task.restored, plural(task.restored))+ crate::i18n::tr_format!("Restored {} photo{} from Recently Deleted", task.restored, crate::i18n::plural_s(task.restored))} else {- crate::i18n::tr_format!("Imported {} photo{}", task.imported, plural(task.imported))+ crate::i18n::tr_format!("Imported {} photo{}", task.imported, crate::i18n::plural_s(task.imported))};if task.restored > 0 && (task.imported > 0 || task.cancelled) {msg.push_str(&crate::i18n::tr_format!(" · {} restored from Recently Deleted", task.restored));@@ -502,11 +497,11 @@ fn import_summary(app: &LightcraftApp, task: &ImportTask) -> String {if task.params["mode"] == "move" {msg.push_str(&crate::i18n::tr_format!(" · {} moved", task.moved));if task.kept > 0 {- msg.push_str(&crate::i18n::tr_format!(" · {} original{} left at the source", task.kept, plural(task.kept)));+ msg.push_str(&crate::i18n::tr_format!(" · {} original{} left at the source", task.kept, crate::i18n::plural_s(task.kept)));}}if task.duplicates > 0 {- msg.push_str(&crate::i18n::tr_format!(" · {} duplicate{} skipped", task.duplicates, plural(task.duplicates)));+ msg.push_str(&crate::i18n::tr_format!(" · {} duplicate{} skipped", task.duplicates, crate::i18n::plural_s(task.duplicates)));let deleted = deleted_of(app, &task.existing).len();if deleted > 0 {msg.push_str(&crate::i18n::tr_format!(" ({} in Recently Deleted)", deleted));diff --git a/crates/ui-egui/src/export_task.rs b/crates/ui-egui/src/export_task.rsindex 1aec84820..206161102 100644--- a/crates/ui-egui/src/export_task.rs+++ b/crates/ui-egui/src/export_task.rs@@ -232,6 +232,35 @@ pub fn poll_photos(app: &mut LightcraftApp, ctx: &egui::Context) {#[cfg(target_arch = "wasm32")]pub fn poll_photos(_: &mut LightcraftApp, _: &egui::Context) {}+/// What a finished export says: how many files were written, skipped or failed, and the Apple Photos note.+fn export_summary(files: &[Value], photos: Option<&Value>, total: usize, cancelled: bool) -> String {+ let sheet = files.first().filter(|f| f["contactSheet"] == true);+ let ok = files.iter().filter(|f| f.get("path").is_some()).count();+ let failed: Vec<&Value> = files.iter().filter(|f| f.get("error").is_some()).collect();+ let skipped = files.iter().filter(|f| f.get("skipped").is_some()).count();+ let mut m = crate::i18n::tr_format!("Exported {ok} of {total} photo{}", if total == 1 { "" } else { "s" }, ok = ok, total = total);+ if let Some(sheet) = sheet {+ m = format!("Exported contact sheet: {} photos, {} pages", sheet["photos"], sheet["pages"]);+ }+ if let Some(pdf) = files.first().filter(|f| f["print"] == true) {+ m = format!("Printed to PDF: {} photos, {} pages", pdf["photos"], pdf["pages"]);+ }+ if skipped > 0 {+ m += &crate::i18n::tr_format!(" · {skipped} skipped (file exists)", skipped = skipped);+ }+ if let Some(first) = failed.first() {+ m += &crate::i18n::tr_format!(" · {} failed: {}", failed.len(), first["error"].as_str().unwrap_or("error"));+ }+ if cancelled {+ m += " · cancelled";+ }+ if let Some(photos) = photos {+ m += " · ";+ m += &apple_photos_note(photos);+ }+ m+}+/// Per frame: keep the activity row up to date; when the batch finishes, report it.pub fn poll(app: &mut LightcraftApp, ctx: &egui::Context) {let Some(task) = &app.export else { return };@@ -244,31 +273,7 @@ pub fn poll(app: &mut LightcraftApp, ctx: &egui::Context) {let photos_failed = matches!(&r, Ok((_, Some(p), _)) if p.get("error").is_some());let msg = match r {Ok((files, photos, _)) => {- let sheet = files.first().filter(|f| f["contactSheet"] == true);- let ok = files.iter().filter(|f| f.get("path").is_some()).count();- let failed: Vec<&Value> = files.iter().filter(|f| f.get("error").is_some()).collect();- let skipped = files.iter().filter(|f| f.get("skipped").is_some()).count();- let mut m =- crate::i18n::tr_format!("Exported {ok} of {total} photo{}", if total == 1 { "" } else { "s" }, ok = ok, total = total);- if let Some(sheet) = sheet {- m = format!("Exported contact sheet: {} photos, {} pages", sheet["photos"], sheet["pages"]);- }- if let Some(pdf) = files.first().filter(|f| f["print"] == true) {- m = format!("Printed to PDF: {} photos, {} pages", pdf["photos"], pdf["pages"]);- }- if skipped > 0 {- m += &crate::i18n::tr_format!(" · {skipped} skipped (file exists)", skipped = skipped);- }- if let Some(first) = failed.first() {- m += &crate::i18n::tr_format!(" · {} failed: {}", failed.len(), first["error"].as_str().unwrap_or("error"));- }- if cancelled {- m += " · cancelled";- }- if let Some(photos) = &photos {- m += " · ";- m += &apple_photos_note(photos);- }+ let m = export_summary(&files, photos.as_ref(), total, cancelled);app.last_export_result = Some(json!({"files": files, "cancelled": cancelled, "applePhotos": photos}));m}diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rsindex 8be0b3e8e..a7df011c2 100644--- a/crates/ui-egui/src/i18n.rs+++ b/crates/ui-egui/src/i18n.rs@@ -262,6 +262,12 @@ fn catalog_verbatim(language: Locale) -> BTreeMap<String, &'static str> {language.catalog().iter().map(|(key, value)| (key.clone(), value.as_str())).collect()}+/// `"s"` for a count other than one: the plural ending of English messages. Computed before a [`tr_format!`] rather+/// than inside it, since the macro repeats its arguments once per language.+pub(crate) fn plural_s(n: usize) -> &'static str {+ if n == 1 { "" } else { "s" }+}+// `tr_format!` (one arm per message, one `format!` per language) is generated by `build.rs` from// `locales/*-formats.json`.include!(concat!(env!("OUT_DIR"), "/tr-formats.rs"));diff --git a/crates/ui-egui/src/menus/run.rs b/crates/ui-egui/src/menus/run.rsindex ed45cbcb4..c88a50207 100644--- a/crates/ui-egui/src/menus/run.rs+++ b/crates/ui-egui/src/menus/run.rs@@ -1869,11 +1869,6 @@ fn failed_files(v: &Value) -> impl Iterator<Item = String> + '_ {})}-/// `s` for a count other than one.-fn plural(n: usize) -> &'static str {- if n == 1 { "" } else { "s" }-}-/// Import the `.cube` LUTs (and those inside zips / folders) as profiles; the answer to report back.fn import_luts(app: &mut LightcraftApp, lut_paths: &[&String], news: &mut ImportNews) -> Value {match app.session.execute("profile.import", &json!({"paths": lut_paths})) {@@ -1882,7 +1877,7 @@ fn import_luts(app: &mut LightcraftApp, lut_paths: &[&String], news: &mut Importif profiles > 0 {news.parts.push(crate::i18n::tr_format!("Imported {profiles} profile{} (Profile browser ▸ their groups)",- plural(profiles),+ crate::i18n::plural_s(profiles),profiles = profiles));}@@ -1922,8 +1917,14 @@ fn presets_sentence(v: &Value, profile_news: bool) -> Option<String> {// a zip of LUTs (or only local presets): the other half already says what happened(0, 0) if profile_news => return None,(0, 0) => "No new presets".to_string(),- (n, 0) => crate::i18n::tr_format!("Imported {n} preset{}", plural(n), n = n),- (n, f) => crate::i18n::tr_format!("Imported {n} preset{}, {f} file{} not readable", plural(n), plural(f), f = f, n = n),+ (n, 0) => crate::i18n::tr_format!("Imported {n} preset{}", crate::i18n::plural_s(n), n = n),+ (n, f) => crate::i18n::tr_format!(+ "Imported {n} preset{}, {f} file{} not readable",+ crate::i18n::plural_s(n),+ crate::i18n::plural_s(f),+ f = f,+ n = n+ ),};Some(msg + ¬_carried_over(v))}@@ -2131,11 +2132,11 @@ fn file_import_curve_presets_command(app: &mut LightcraftApp, ctx: &egui::Contexfn curve_import_message(v: &Value) -> String {let n = v["imported"].as_array().map_or(0, Vec::len);let failed = v["failed"].as_array().map_or(0, Vec::len);- let imported = crate::i18n::tr_format!("Imported {n} point curve preset{}", plural(n), n = n);+ let imported = crate::i18n::tr_format!("Imported {n} point curve preset{}", crate::i18n::plural_s(n), n = n);if failed == 0 {return imported;}- imported + &crate::i18n::tr_format!(", {failed} file{} not readable", plural(failed), failed = failed)+ imported + &crate::i18n::tr_format!(", {failed} file{} not readable", crate::i18n::plural_s(failed), failed = failed)}/// The `file.exportCurvePresets` command.diff --git a/crates/ui-egui/src/panels/chips.rs b/crates/ui-egui/src/panels/chips.rsindex c18b3ad72..42640503e 100644--- a/crates/ui-egui/src/panels/chips.rs+++ b/crates/ui-egui/src/panels/chips.rs@@ -29,6 +29,31 @@ fn chip_width(ui: &egui::Ui, label: &str, font: egui::FontId) -> f32 {ui.painter().layout_no_wrap(label.to_string(), font, egui::Color32::WHITE).size().x + 12.0 + 22.0}+/// The colour labels a label chip names, in words ("Red or Blue").+fn label_names(filter: &lightcraft_catalog::Filter, catalog: &lightcraft_catalog::Catalog) -> String {+ use crate::i18n::tr;+ let shown = filter.labels_shown().unwrap_or_default();+ let name = |label: &lightcraft_catalog::ColorLabel| crate::i18n::color_label(catalog, *label);+ let or = |labels: &[lightcraft_catalog::ColorLabel]| labels.iter().map(name).collect::<Vec<_>>().join(&format!(" {} ", tr("or")));+ if !shown.is_empty() {+ return or(&shown);+ }+ let plural = if filter.labels.len() > 1 { format!("({})", or(&filter.labels)) } else { or(&filter.labels) };+ format!("{} {} {plural}", filter.label.as_ref().map(name).unwrap_or_default(), tr("and"))+}++/// The value of a `prefix: value` chip, localised.+fn prefixed_value(prefix: &str, value: &str, filter: &lightcraft_catalog::Filter) -> String {+ use crate::i18n::{date_group_label, tr};+ let date = match prefix {+ "Flag" | "Type" => return tr(value).to_string(),+ "Date" => &filter.date,+ "Imported" => &filter.imported,+ _ => return value.to_string(),+ };+ date.as_ref().map_or_else(|| value.to_string(), |date| date_group_label(date, false))+}+/// Localise generated chip labels without rewriting search text or metadata values.pub(crate) fn display_label(chip: &FilterChip, filter: &lightcraft_catalog::Filter, catalog: &lightcraft_catalog::Catalog) -> String {use crate::i18n::{date_group_label, rules_label, tr};@@ -41,16 +66,7 @@ pub(crate) fn display_label(chip: &FilterChip, filter: &lightcraft_catalog::Filtreturn format!("{}: {}", tr("Rules"), rules_label(rules, catalog));}if chip.clear.get("label").is_some() {- let shown = filter.labels_shown().unwrap_or_default();- let name = |label: &lightcraft_catalog::ColorLabel| crate::i18n::color_label(catalog, *label);- let or = |labels: &[lightcraft_catalog::ColorLabel]| labels.iter().map(name).collect::<Vec<_>>().join(&format!(" {} ", tr("or")));- let names = if shown.is_empty() {- let plural = if filter.labels.len() > 1 { format!("({})", or(&filter.labels)) } else { or(&filter.labels) };- format!("{} {} {plural}", filter.label.as_ref().map(name).unwrap_or_default(), tr("and"))- } else {- or(&shown)- };- return format!("{}: {names}", tr("Label"));+ return format!("{}: {}", tr("Label"), label_names(filter, catalog));}if chip.clear.get("dateFrom").is_some() || chip.clear.get("dateTo").is_some() {return match (&filter.date_from, &filter.date_to) {@@ -64,16 +80,7 @@ pub(crate) fn display_label(chip: &FilterChip, filter: &lightcraft_catalog::Filtreturn format!("{} {}", tr("Only"), crate::i18n::tr_format!("{n} photos", n = if filter.only_none { 0 } else { filter.only.len() }));}if let Some((prefix, value)) = chip.label.split_once(": ") {- let value = if matches!(prefix, "Flag" | "Type") {- tr(value).to_string()- } else if prefix == "Date" {- filter.date.as_ref().map_or_else(|| value.to_string(), |date| date_group_label(date, false))- } else if prefix == "Imported" {- filter.imported.as_ref().map_or_else(|| value.to_string(), |date| date_group_label(date, false))- } else {- value.to_string()- };- return format!("{}: {value}", tr(prefix));+ return format!("{}: {}", tr(prefix), prefixed_value(prefix, value, filter));}if let Some(value) = chip.label.strip_prefix("Rating ") {return format!("{} {value}", tr("Rating"));diff --git a/crates/ui-egui/src/panels/compare.rs b/crates/ui-egui/src/panels/compare.rsindex 829500da4..9b9a23673 100644--- a/crates/ui-egui/src/panels/compare.rs+++ b/crates/ui-egui/src/panels/compare.rs@@ -197,6 +197,17 @@ fn area_and_filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui) -> Rect {canvas}+/// Ask for the render of a tile (about `want` pixels on its long edge) and for the thumbnail shown meanwhile.+fn request_tile_renders(app: &mut LightcraftApp, id: PhotoId, slot: Slot, want: usize, aspect: f32) {+ let (rw, rh) = if aspect >= 1.0 { (want, (want as f32 / aspect) as usize) } else { ((want as f32 * aspect) as usize, want) };+ if let Some(job) = app.session.render_job(id, rw.max(8), rh.max(8), false, true) {+ app.renderer.request(slot, job, 60);+ }+ if let Some(job) = app.session.thumb_job(id, 256) {+ app.renderer.request(Slot::Thumb(id), job, 30);+ }+}+/// Draw one photo fitted into `area` (rendered at its display size into `slot`), with its caption/// strip below. Returns the image rect and the click/drag response.fn photo_tile(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, slot: Slot, area: Rect, label: &str, zoom: Zoom) -> (Rect, egui::Response) {@@ -230,13 +241,7 @@ fn photo_tile(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, slot: Slolet texture_side = super::detail::texture_side(ui.ctx());let want =(img.width().max(img.height()).min(img_area.width().max(img_area.height()) * 4.0) * ppp).min(2560.0_f32.min(texture_side as f32)) as usize;- let (rw, rh) = if aspect >= 1.0 { (want, (want as f32 / aspect) as usize) } else { ((want as f32 * aspect) as usize, want) };- if let Some(job) = app.session.render_job(id, rw.max(8), rh.max(8), false, true) {- app.renderer.request(slot, job, 60);- }- if let Some(job) = app.session.thumb_job(id, 256) {- app.renderer.request(Slot::Thumb(id), job, 30);- }+ request_tile_renders(app, id, slot, want, aspect);// zoomed past what that render holds (1:1 to check focus): the part on screen as a window, as// in the loupe. Compare and Reference only; Survey tiles are fit views.let pane = match slot {diff --git a/crates/ui-egui/src/panels/mask_effects.rs b/crates/ui-egui/src/panels/mask_effects.rsindex 86f3796b9..d1c4fe1f4 100644--- a/crates/ui-egui/src/panels/mask_effects.rs+++ b/crates/ui-egui/src/panels/mask_effects.rs@@ -683,23 +683,38 @@ pub fn manage_body(}}+/// The distinct values, sorted.+fn distinct<'a>(values: impl Iterator<Item = &'a str>) -> Vec<&'a str> {+ let mut v: Vec<&str> = values.collect();+ v.sort_unstable();+ v.dedup();+ v+}+/// The toast after an import (`preset.import` / `mask.importEffects` result): how many effects,/// in how many groups, and the settings they carry that LightCraft can't apply.pub fn import_toast(v: &Value) -> String {let rows: Vec<&Value> = v["effects"].as_array().or_else(|| v["imported"].as_array()).into_iter().flatten().collect();- let n = rows.len();- let mut msg = crate::i18n::tr_format!("Imported {e} mask effect{} (Masking ▸ Effect)", if n == 1 { "" } else { "s" }, e = n);- let mut groups: Vec<&str> = rows.iter().filter_map(|r| r["group"].as_str()).filter(|g| !g.is_empty()).collect();- groups.sort_unstable();- groups.dedup();+ let mut msg = imported_effects_message(rows.len());+ let groups = distinct(rows.iter().filter_map(|r| r["group"].as_str()).filter(|g| !g.is_empty()));if !groups.is_empty() {- msg += &crate::i18n::tr_format!(" in {g} group{}", if groups.len() == 1 { "" } else { "s" }, g = groups.len());+ msg += &in_groups_message(groups.len());}- let mut skipped: Vec<&str> = rows.iter().flat_map(|r| r["unmapped"].as_array().into_iter().flatten()).filter_map(Value::as_str).collect();- skipped.sort_unstable();- skipped.dedup();+ let skipped = distinct(rows.iter().flat_map(|r| r["unmapped"].as_array().into_iter().flatten()).filter_map(Value::as_str));if !skipped.is_empty() {- msg += &crate::i18n::tr_format!(" — kept but not applied: {}", skipped.join(", "));+ msg += ¬_applied_message(&skipped);}msg}++fn imported_effects_message(n: usize) -> String {+ crate::i18n::tr_format!("Imported {e} mask effect{} (Masking ▸ Effect)", crate::i18n::plural_s(n), e = n)+}++fn in_groups_message(groups: usize) -> String {+ crate::i18n::tr_format!(" in {g} group{}", crate::i18n::plural_s(groups), g = groups)+}++fn not_applied_message(settings: &[&str]) -> String {+ crate::i18n::tr_format!(" — kept but not applied: {}", settings.join(", "))+}diff --git a/crates/ui-egui/src/panels/notices.rs b/crates/ui-egui/src/panels/notices.rsindex 4dbbc1fd9..96e356bb4 100644--- a/crates/ui-egui/src/panels/notices.rs+++ b/crates/ui-egui/src/panels/notices.rs@@ -40,6 +40,22 @@ pub fn gpu_notice(reason: Option<&str>, enabled: bool) -> Option<String> {Some(text)}+/// The quit prompt's text while `count` cancellable tasks run (`names` lists them).+fn tasks_message(count: usize, names: &str) -> String {+ if count == 1 {+ crate::i18n::tr_format!("1 task is still running: {names}. Quitting stops it.", names = names)+ } else {+ crate::i18n::tr_format!("{n} tasks are still running: {names}. Quitting stops them.", n = count, names = names)+ }+}++/// The quit prompt's text when `n` changes couldn't be written to disk, for the reason `e`.+fn unsaved_message(n: usize, e: &str) -> String {+ let s = crate::i18n::plural_s(n);+ let lost = if n == 1 { "it is" } else { "they are" };+ crate::i18n::tr_format!("{n} change{} couldn't be written to disk: {e}\nIf you quit now, {} lost.", s, lost, n = n, e = e)+}+/// The window may close now (`true`), or the quit prompt is shown (`false`). Running tasks that/// can be cancelled (an import, an export…) are asked about first; then changes that couldn't be/// written are retried — the log, then a snapshot of everything in memory.@@ -51,11 +67,7 @@ pub fn may_close(app: &mut LightcraftApp) -> bool {let running = app.session.activity.running_cancellable();if !running.is_empty() {let names = running.iter().map(|t| crate::i18n::tr(&t.label)).collect::<Vec<_>>().join(", ");- app.quit_prompt = Some(QuitPrompt::Tasks(if running.len() == 1 {- crate::i18n::tr_format!("1 task is still running: {names}. Quitting stops it.", names = names)- } else {- crate::i18n::tr_format!("{n} tasks are still running: {names}. Quitting stops them.", n = running.len(), names = names)- }));+ app.quit_prompt = Some(QuitPrompt::Tasks(tasks_message(running.len(), &names)));return false;}if app.session.unsaved().is_none() {@@ -70,13 +82,7 @@ pub fn may_close(app: &mut LightcraftApp) -> bool {match app.session.unsaved() {None => true,Some((n, e)) => {- app.quit_prompt = Some(QuitPrompt::Unsaved(crate::i18n::tr_format!(- "{n} change{} couldn't be written to disk: {e}\nIf you quit now, {} lost.",- if n == 1 { "" } else { "s" },- if n == 1 { "it is" } else { "they are" },- n = n,- e = e- )));+ app.quit_prompt = Some(QuitPrompt::Unsaved(unsaved_message(n, e)));false}}diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 558edfe8d..513208066 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -337,24 +337,9 @@ pub(crate) fn shown_value(spec: &ControlSpec, v: f64) -> String {/// scrub rather than a click that types a value.const SCRUB_START: f32 = 3.0;-/// The radius of a slider's hollow ring thumb.-const THUMB_RING: f32 = 7.0;--/// A Lightroom slider row (label + value above a track with a hollow ring thumb).-/// Double-click the label or thumb to reset (hovering either says so). Shift-drag = fine adjustment.-/// Scroll sideways over it to nudge it. Click the value to type one: Return or clicking away applies it,-/// Esc keeps the old one. Drag the value sideways to scrub it, as if dragging the thumb (Shift: a tenth-/// as far).-pub fn slider(ui: &mut Ui, spec: &ControlSpec, value: f64, enabled: bool, label_override: Option<&str>) -> SliderOut {- let t = Tokens::get(ui.ctx());- let w = ui.available_width();- let (row, _) = ui.allocate_exact_size(vec2(w, t.slider_row_h), Sense::hover());- let pad_l = 24.0;- let pad_r = 22.0;- let label_rect = Rect::from_min_size(pos2(row.left() + pad_l, row.top() + 4.0), vec2(w - pad_l - pad_r, 18.0));- let track_rect = Rect::from_min_max(pos2(row.left() + pad_l, row.top() + 22.0), pos2(row.right() - pad_r, row.top() + 40.0));- let id = ui.scope_id().with(spec.id);- let resp = ui.interact(track_rect.expand2(vec2(8.0, 2.0)), id, if enabled { Sense::click_and_drag() } else { Sense::hover() });+/// Which slider the vertical wheel edits: clicking or dragging a slider arms it (and disarms the others), leaving+/// its row or its focus disarms it. Returns whether this slider is armed, and whether the pointer is in its row.+fn update_wheel_arming(ui: &mut Ui, id: egui::Id, resp: &egui::Response, row: Rect, enabled: bool) -> (bool, bool) {// Keyboard focus survives leaving the row; vertical wheel edits need a fresh click or drag// in it (at most one slider is armed: `wheel_slider_key`).let wheel_id = id.with("wheel-rem");@@ -394,6 +379,29 @@ pub fn slider(ui: &mut Ui, spec: &ControlSpec, value: f64, enabled: bool, label_});wheel_armed = false;}+ (wheel_armed, pointer_in_row)+}++/// The radius of a slider's hollow ring thumb.+const THUMB_RING: f32 = 7.0;++/// A Lightroom slider row (label + value above a track with a hollow ring thumb).+/// Double-click the label or thumb to reset (hovering either says so). Shift-drag = fine adjustment.+/// Scroll sideways over it to nudge it. Click the value to type one: Return or clicking away applies it,+/// Esc keeps the old one. Drag the value sideways to scrub it, as if dragging the thumb (Shift: a tenth+/// as far).+pub fn slider(ui: &mut Ui, spec: &ControlSpec, value: f64, enabled: bool, label_override: Option<&str>) -> SliderOut {+ let t = Tokens::get(ui.ctx());+ let w = ui.available_width();+ let (row, _) = ui.allocate_exact_size(vec2(w, t.slider_row_h), Sense::hover());+ let pad_l = 24.0;+ let pad_r = 22.0;+ let label_rect = Rect::from_min_size(pos2(row.left() + pad_l, row.top() + 4.0), vec2(w - pad_l - pad_r, 18.0));+ let track_rect = Rect::from_min_max(pos2(row.left() + pad_l, row.top() + 22.0), pos2(row.right() - pad_r, row.top() + 40.0));+ let id = ui.scope_id().with(spec.id);+ let resp = ui.interact(track_rect.expand2(vec2(8.0, 2.0)), id, if enabled { Sense::click_and_drag() } else { Sense::hover() });+ let wheel_id = id.with("wheel-rem");+ let (wheel_armed, pointer_in_row) = update_wheel_arming(ui, id, &resp, row, enabled);// screen readers: a slider named after its control, with its valuelet label_text = crate::i18n::tr(label_override.unwrap_or(spec.label)).to_string();resp.widget_info(|| egui::WidgetInfo::slider(enabled, value, label_text.clone()));diff --git a/crates/ui-egui/src/widgets/text_field.rs b/crates/ui-egui/src/widgets/text_field.rsindex cb150080b..6b5c60c55 100644--- a/crates/ui-egui/src/widgets/text_field.rs+++ b/crates/ui-egui/src/widgets/text_field.rs@@ -162,14 +162,10 @@ impl<'a> TextField<'a> {self}- /// Draw the field and return its response, any ending this frame, and whether an edit is- /// under way. Per-frame state keeps the pre-edit text for Esc, the selection across the- /// context menu, and select-on-focus; single-line Enter ends the edit, and focus loss ends it- /// except when the focus went to the field's own menu (a choice from the menu resumes the- /// edit). The menu offers cut/copy/paste/select-all (paste is omitted on the web; egui also- /// handles their keyboard shortcuts), and a field not drawn on the previous pass starts clean.- pub fn show(self, ui: &mut Ui) -> TextFieldResponse {- let id = id(self.widget);+ /// The field's remembered state at the start of a pass: a field not drawn on the previous pass starts afresh,+ /// a begun edit or a choice made from the menu last frame is carried out, and a field focused by the previous+ /// pass selects its text when it asks to.+ fn prepare(&self, ui: &mut Ui, id: egui::Id) -> Memo {let mut memo: Memo = ui.data_mut(|d| d.get_temp(id.with("memo"))).unwrap_or_default();// a field not drawn last frame (its dialog or panel closed) starts afresh: an edit, a menu// or a choice from it that was under way is gone with it@@ -207,6 +203,19 @@ impl<'a> TextField<'a> {memo.before = Some(self.text.clone());select_all(ui.ctx(), id, self.text);}+ memo+ }++ /// Draw the field and return its response, any ending this frame, and whether an edit is+ /// under way. Per-frame state keeps the pre-edit text for Esc, the selection across the+ /// context menu, and select-on-focus; single-line Enter ends the edit, and focus loss ends it+ /// except when the focus went to the field's own menu (a choice from the menu resumes the+ /// edit). The menu offers cut/copy/paste/select-all (paste is omitted on the web; egui also+ /// handles their keyboard shortcuts), and a field not drawn on the previous pass starts clean.+ pub fn show(self, ui: &mut Ui) -> TextFieldResponse {+ let id = id(self.widget);+ let pass = ui.ctx().cumulative_pass_nr();+ let mut memo = self.prepare(ui, id);let name = self.label.clone().or_else(|| self.hint.clone());let mut edit = if self.multiline { egui::TextEdit::multiline(self.text) } else { egui::TextEdit::singleline(self.text) };edit = edit.id(id);