LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-BEHAV-BG-TASKS: activity bars are named after their task, denoise percentage matches its announced value, Describe waits for a pending detail pass
Nathaniel Ledford0198375edf0f
diff --git a/crates/ui-egui/src/panels/activity.rs b/crates/ui-egui/src/panels/activity.rsindex ed3c57cf8..7fa9570fe 100644--- a/crates/ui-egui/src/panels/activity.rs+++ b/crates/ui-egui/src/panels/activity.rs@@ -146,8 +146,11 @@ fn row(ui: &mut egui::Ui, t: &Tokens, task: &TaskInfo, width: f32) -> bool {clicked}-/// The progress bar; while the amount of work isn't known, a segment sweeps across.-fn bar(ui: &mut egui::Ui, task: &TaskInfo, width: f32) {+/// The progress bar, named after its task for screen readers; while the amount of work isn't+/// known, a segment sweeps across.+pub(crate) fn bar(ui: &mut egui::Ui, task: &TaskInfo, width: f32) -> egui::Response {let fraction = (task.total > 0).then(|| (task.done as f64 / task.total as f64) as f32);- crate::progress::Progress::new(fraction).width(width).dimmed(task.cancelling).show(ui);+ let response = crate::progress::Progress::new(fraction).width(width).dimmed(task.cancelling).show(ui);+ crate::widgets::screen_reader_name(ui.ctx(), response.id, tr(&task.label));+ response}diff --git a/crates/ui-egui/src/panels/denoise.rs b/crates/ui-egui/src/panels/denoise.rsindex 69e31dead..59a54364f 100644--- a/crates/ui-egui/src/panels/denoise.rs+++ b/crates/ui-egui/src/panels/denoise.rs@@ -142,11 +142,12 @@ pub fn detail_toggle(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId, on}/// The bar under the Denoise slider while a photo's picture is made: at most 240 px wide, and-/// sweeping while the number of tiles is not known yet.+/// sweeping while the number of tiles is not known yet. The percentage is floored, as the bar's+/// accessible value is (and the SAM bar's text): 100 % only once done.pub(crate) fn detail_bar(ui: &mut egui::Ui, done: u64, total: u64) -> egui::Response {let fraction = crate::progress::fraction_of(done, total);let text = match fraction {- Some(f) => tr_format!("Making the denoised picture… {}%", (f * 100.0).round() as u32),+ Some(f) => tr_format!("Making the denoised picture… {}%", (f * 100.0).floor() as u32),None => tr("Starting…").to_string(),};crate::progress::Progress::new(fraction).label(text).width(ui.available_width().min(240.0)).widget("denoise:progress").show(ui)diff --git a/crates/ui-egui/src/panels/masking.rs b/crates/ui-egui/src/panels/masking.rsindex 517452e06..5c1781e82 100644--- a/crates/ui-egui/src/panels/masking.rs+++ b/crates/ui-egui/src/panels/masking.rs@@ -772,9 +772,10 @@ pub(crate) fn sam_download_bar(ui: &mut egui::Ui, done: u64, total: u64, width:crate::progress::Progress::new(fraction).label(label).width(width).widget("maskSamProgress").show(ui)}-/// Whether the segmenter has work (loading, analyzing, a request, a detail pass): nothing new starts then.-fn segmenter_working(analyzing: bool, busy: bool, detail_busy: bool) -> bool {- analyzing || busy || detail_busy+/// Whether the segmenter has work (loading, analyzing, a request, a detail pass running or waiting+/// to start): nothing new starts then.+fn segmenter_working(analyzing: bool, busy: bool, detail_busy: bool, detail_due: bool) -> bool {+ analyzing || busy || detail_busy || detail_due}/// Enter in the Describe field is the Select button: it starts nothing while the segmenter works.@@ -800,7 +801,7 @@ fn describe_field(app: &mut LightcraftApp, ui: &mut egui::Ui, new_mask: bool) {// the (translated) Select button is placed first, at the right; the field takes what is leftui.allocate_ui_with_layout(vec2(ui.available_width(), 24.0), egui::Layout::right_to_left(egui::Align::Center), |ui| {let seg = &app.session.segmenter;- let working = segmenter_working(seg.analyzing(), seg.busy(), seg.detail_busy());+ let working = segmenter_working(seg.analyzing(), seg.busy(), seg.detail_busy(), app.ui.detail_due.is_some());if crate::button::Button::new("Select").small().busy(working).widget("button:maskDescribeGo").show(ui).clicked() {submit = true;}@@ -924,10 +925,16 @@ mod tests {#[test]fn a_detail_pass_counts_as_the_segmenter_working() {- assert!(segmenter_working(false, false, true));- assert!(segmenter_working(true, false, false));- assert!(segmenter_working(false, true, false));- assert!(!segmenter_working(false, false, false));+ assert!(segmenter_working(false, false, true, false));+ assert!(segmenter_working(true, false, false, false));+ assert!(segmenter_working(false, true, false, false));+ assert!(!segmenter_working(false, false, false, false));+ }++ #[test]+ fn a_pending_detail_pass_counts_as_the_segmenter_working() {+ // a new prompt finishing before it starts would replace its target, and that mask never refines+ assert!(segmenter_working(false, false, false, true));}#[test]diff --git a/crates/ui-egui/src/tests_progress.rs b/crates/ui-egui/src/tests_progress.rsindex 7d906bc81..41f779e0e 100644--- a/crates/ui-egui/src/tests_progress.rs+++ b/crates/ui-egui/src/tests_progress.rs@@ -237,3 +237,34 @@ fn the_denoise_bars_keep_their_widths_in_a_wide_container() {assert_eq!((detail, settings, unknown), (240.0, 380.0, 240.0));assert!(ids.iter().any(|(id, _)| id == "denoise:settingsProgress"));}++#[test]+fn the_denoise_bar_label_and_its_accessible_value_agree() {+ // 3 of 7 is 42.86 %: the number drawn on the bar is the one announced+ let (nodes, _, _) = frames(Vec::new(), |ui| {+ crate::panels::denoise::detail_bar(ui, 3, 7);+ });+ let bar = nodes.iter().find(|n| n.role == "ProgressIndicator").unwrap_or_else(|| panic!("{nodes:?}"));+ let shown: f64 = bar.label.rsplit(' ').next().unwrap().trim_end_matches('%').parse().unwrap();+ assert_eq!(bar.value, Some(shown), "{bar:?}");+}++#[test]+fn an_activity_bar_is_named_after_its_task() {+ let task = lightcraft_engine::activity::TaskInfo {+ id: 1,+ kind: "export",+ label: "Exporting".into(),+ done: 3,+ total: 25,+ unit: lightcraft_engine::activity::Unit::Count,+ detail: String::new(),+ cancellable: true,+ cancelling: false,+ age_ms: 600,+ };+ let (nodes, _, _) = frames(Vec::new(), |ui| crate::panels::activity::bar(ui, &task, 200.0).rect.width());+ let bar = nodes.iter().find(|n| n.role == "ProgressIndicator").unwrap_or_else(|| panic!("{nodes:?}"));+ assert_eq!(bar.label, "Exporting");+ assert_eq!(bar.value, Some(12.0));+}