LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
LR-BEHAV-BG-TASKS: the SAM download bar keeps its name while the size is unknown
Nathaniel Ledford1e65f52e7939
diff --git a/crates/ui-egui/src/panels/masking.rs b/crates/ui-egui/src/panels/masking.rsindex cab821913..fc2ff8ef3 100644--- a/crates/ui-egui/src/panels/masking.rs+++ b/crates/ui-egui/src/panels/masking.rs@@ -180,15 +180,9 @@ pub fn show(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {if download.running && app.ui.dialog.is_none() {ui.add_space(4.0);ui.horizontal(|ui| {- let pct = if download.total > 0 { download.done as f64 / download.total as f64 } else { 0.0 };// the bar takes what the Details button leaveslet details = ui.spacing().interact_size.x + 30.0;- crate::progress::Progress::new(crate::progress::fraction_of(download.done, download.total))- // no percentage to say while the size is unknown- .label(if download.total > 0 { format!("SAM 3: {} %", (pct * 100.0).floor()) } else { String::new() })- .width((ui.available_width() - details).max(96.0))- .widget("maskSamProgress")- .show(ui);+ sam_download_bar(ui, download.done, download.total, (ui.available_width() - details).max(96.0));if text_button(ui, "maskSamDetails", crate::i18n::tr("Details"), false).clicked() {app.offer_sam_download(None);}@@ -767,12 +761,23 @@ pub(crate) fn start_describe(app: &mut LightcraftApp, op: &str) {app.ui.describe = Some((op.to_string(), String::new()));}-/// The Describe field: type what to select ("sky", "the red car") and press Return.+/// The SAM model's download, `width` wide. The label is a percentage once the size is known and+/// just the model's name before, so the bar keeps its height and its accessible name.+pub(crate) fn sam_download_bar(ui: &mut egui::Ui, done: u64, total: u64, width: f32) -> egui::Response {+ let fraction = crate::progress::fraction_of(done, total);+ let label = match fraction {+ Some(f) => format!("SAM 3: {} %", (f64::from(f) * 100.0).floor()),+ None => "SAM 3".to_string(),+ };+ crate::progress::Progress::new(fraction).label(label).width(width).widget("maskSamProgress").show(ui)+}+/// Enter in the Describe field is the Select button: it starts nothing while the segmenter works.fn enter_submits(working: bool, lost_focus: bool, enter_pressed: bool) -> bool {!working && lost_focus && enter_pressed}+/// The Describe field: type what to select ("sky", "the red car") and press Return.fn describe_field(app: &mut LightcraftApp, ui: &mut egui::Ui, new_mask: bool) {let Some((op, mut text)) = app.ui.describe.clone() else { return };// a new mask's field sits under the tiles; one that combines, under the selected maskdiff --git a/crates/ui-egui/src/tests_progress.rs b/crates/ui-egui/src/tests_progress.rsindex 8ceb61109..8319278cc 100644--- a/crates/ui-egui/src/tests_progress.rs+++ b/crates/ui-egui/src/tests_progress.rs@@ -207,6 +207,19 @@ fn a_failed_filmstrip_thumbnail_is_announced_with_its_reason() {assert_eq!(spoken(true).as_deref(), Some("IMG_0001.jpg, This photo can't be opened"));}+#[test]+fn the_sam_bar_keeps_its_name_and_height_while_the_size_is_unknown() {+ let (nodes, _, (known, unknown)) = frames(Vec::new(), |ui| {+ let known = crate::panels::masking::sam_download_bar(ui, 5, 10, 200.0).rect.height();+ let unknown = crate::panels::masking::sam_download_bar(ui, 0, 0, 200.0).rect.height();+ (known, unknown)+ });+ assert_eq!(known, unknown);+ let bars: Vec<_> = nodes.iter().filter(|n| n.role == "ProgressIndicator").collect();+ assert_eq!(bars.len(), 2, "{nodes:?}");+ assert!(bars.iter().all(|b| b.label.starts_with("SAM 3")), "{bars:?}");+}+#[test]fn the_denoise_bars_keep_their_widths_in_a_wide_container() {let (_, ids, (detail, settings, unknown)) = frames(Vec::new(), |ui| {