Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

LR-BEHAV-BG-TASKS: review fixes for progress and busy buttons

Nathaniel Ledford3de9654e3956
diff --git a/crates/ui-egui/src/button.rs b/crates/ui-egui/src/button.rs
index 3dbd368b1..4e23f1c16 100644
--- a/crates/ui-egui/src/button.rs
+++ b/crates/ui-egui/src/button.rs
@@ -341,7 +341,18 @@ impl<'a> Button<'a> {
};
// a button in a disabled part of the window is disabled too
let enabled = self.enabled && ui.is_enabled();
- let resp = ui.interact(rect, id, if enabled && !self.busy { Sense::click() } else { Sense::hover() });
+ let resp = ui.interact(
+ rect,
+ id,
+ if !enabled {
+ Sense::hover()
+ } else if self.busy {
+ // still reachable by the keyboard, but nothing to press
+ Sense::focusable_noninteractive()
+ } else {
+ Sense::click()
+ },
+ );
let words = crate::i18n::tr(self.name.or(self.text).unwrap_or_default()).to_string();
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, words.clone()));
if self.busy {
@@ -392,8 +403,10 @@ impl<'a> Button<'a> {
if has_slot {
let slot_rect = Rect::from_center_size(pos2(x + slot / 2.0, rect.center().y), vec2(slot, slot));
if self.busy {
- crate::progress::paint_spinner(p, slot_rect, lk.content, ui.input(|i| i.time));
- ui.ctx().request_repaint_after(std::time::Duration::from_millis(33));
+ if ui.is_rect_visible(rect) {
+ crate::progress::paint_spinner(p, slot_rect, lk.content, ui.input(|i| i.time));
+ ui.ctx().request_repaint_after(std::time::Duration::from_millis(33));
+ }
} else if let Some(icon) = self.icon {
paint(p, slot_rect, icon, lk.content);
}
diff --git a/crates/ui-egui/src/import.rs b/crates/ui-egui/src/import.rs
index 323d8d902..36300bcda 100644
--- a/crates/ui-egui/src/import.rs
+++ b/crates/ui-egui/src/import.rs
@@ -1336,7 +1336,7 @@ fn candidate_cell(app: &mut LightcraftApp, ui: &mut egui::Ui, d: &mut ImportDial
crate::widgets::announce(&resp, c.name.clone());
register(ui.ctx(), format!("import:{i}"), img);
let p = ui.painter();
- p.rect_filled(img, 3.0, Color32::from_gray(30));
+ p.rect_filled(img, 3.0, t.skeleton);
// thumbnail (background job; the grid only asks for the cells in view)
let slot = Slot::Import(i as u32);
if !app.renderer.textures.contains_key(&slot)
diff --git a/crates/ui-egui/src/panels/denoise.rs b/crates/ui-egui/src/panels/denoise.rs
index 08ad533f0..38ef6a78c 100644
--- a/crates/ui-egui/src/panels/denoise.rs
+++ b/crates/ui-egui/src/panels/denoise.rs
@@ -451,7 +451,11 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
} else {
tr_format!("{} of {} from {host}", mb(Some(got)), mb(Some(total)), host = host)
};
- crate::progress::Progress::new(Some(frac)).label(text).widget(format!("denoise:progress:{id}")).show(ui);
+ crate::progress::Progress::new(Some(frac))
+ .label(text)
+ .width(crate::progress::ROW_WIDTH.min(ui.available_width()))
+ .widget(format!("denoise:progress:{id}"))
+ .show(ui);
}
(Some("done" | "installing"), _) => {
ui.horizontal(|ui| {
diff --git a/crates/ui-egui/src/panels/detail.rs b/crates/ui-egui/src/panels/detail.rs
index 3a15e3f79..9b72e65de 100644
--- a/crates/ui-egui/src/panels/detail.rs
+++ b/crates/ui-egui/src/panels/detail.rs
@@ -1323,7 +1323,7 @@ fn navigator(app: &mut LightcraftApp, ui: &mut egui::Ui, canvas: Rect, img: Rect
p.rect_filled(frame.expand(5.0), 4.0, Color32::from_black_alpha(190));
match tex {
Some(t) => p.image(t.tex.id(), frame, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE),
- None => p.rect_filled(frame, 0.0, Color32::from_gray(40)),
+ None => p.rect_filled(frame, 0.0, Tokens::get(ui.ctx()).skeleton),
};
// the visible part of the photo, in normalized image coordinates
let vis = canvas.intersect(img);
@@ -2859,10 +2859,14 @@ pub(crate) fn filmstrip(app: &mut LightcraftApp, ui: &mut egui::Ui, r: Rect) {
}
let img_area = Rect::from_min_max(cr.min + vec2(10.0, 22.0), cr.max - vec2(10.0, 8.0));
super::grid::request_thumb(app, *id, (256.0 * ppp.min(2.0) / 2.0) as usize * 2, 8);
- if app.renderer.thumb(*id).is_none() {
+ let thumb = app.renderer.thumb(*id);
+ if thumb.is_none() {
p.rect_filled(img_area, 0.0, t.skeleton);
+ if app.renderer.failure(Slot::Thumb(*id)).is_some() {
+ p.text(img_area.center(), Align2::CENTER_CENTER, "!", t.semibold(14.0), t.text_dim);
+ }
}
- if let Some(tex) = app.renderer.thumb(*id) {
+ if let Some(tex) = thumb {
let [tw, th] = tex.size;
let s = (img_area.width() / tw as f32).min(img_area.height() / th as f32);
let fr = Rect::from_center_size(img_area.center(), vec2(tw as f32 * s, th as f32 * s));
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index 061826ba8..3ad982cf5 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -133,7 +133,14 @@ fn watermark_preview(
Ok(img) => img,
Err(e) => {
let note = if e.is_some() { "Preview unavailable" } else { "Loading preview…" };
- let r = ui.label(egui::RichText::new(crate::i18n::tr(note)).color(t.text_dim));
+ let r = ui
+ .horizontal(|ui| {
+ if e.is_none() {
+ crate::progress::spinner(ui, 12.0);
+ }
+ ui.label(egui::RichText::new(crate::i18n::tr(note)).color(t.text_dim))
+ })
+ .inner;
if let Some(e) = e {
r.on_hover_text(e);
}
@@ -611,7 +618,10 @@ pub fn show(app: &mut LightcraftApp, ctx: &egui::Context) {
});
}
None => {
- ui.label(egui::RichText::new(crate::i18n::tr("Checking names…")).color(t.text_dim));
+ ui.horizontal(|ui| {
+ crate::progress::spinner(ui, 12.0);
+ ui.label(egui::RichText::new(crate::i18n::tr("Checking names…")).color(t.text_dim));
+ });
}
}
let more = total.saturating_sub(RENAME_PREVIEW_ROWS);
diff --git a/crates/ui-egui/src/panels/faces.rs b/crates/ui-egui/src/panels/faces.rs
index 4f6febb93..9bc39a4b0 100644
--- a/crates/ui-egui/src/panels/faces.rs
+++ b/crates/ui-egui/src/panels/faces.rs
@@ -190,6 +190,9 @@ fn gpu_section(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, gpu: &Val
};
ui.horizontal(|ui| {
ui.label(RichText::new(crate::i18n::tr(label)).color(t.text_dim));
+ if st["checking"] == true {
+ crate::progress::spinner(ui, 12.0);
+ }
let r = ui.label(text);
register(ui.ctx(), format!("faces:device:{what}"), r.rect);
if let Some(why) = why {
@@ -364,7 +367,11 @@ fn model_row(app: &mut LightcraftApp, ui: &mut egui::Ui, t: &Tokens, m: &Value,
} else {
format!("{} of {} from {host}", mb(Some(got)), mb(Some(total)))
};
- crate::progress::Progress::new(Some(frac)).label(text).widget(format!("faces:progress:{id}")).show(ui);
+ crate::progress::Progress::new(Some(frac))
+ .label(text)
+ .width(crate::progress::ROW_WIDTH.min(ui.available_width()))
+ .widget(format!("faces:progress:{id}"))
+ .show(ui);
}
(Some("done"), _) => {
ui.horizontal(|ui| {
diff --git a/crates/ui-egui/src/print_view.rs b/crates/ui-egui/src/print_view.rs
index a18e1f691..037d619c7 100644
--- a/crates/ui-egui/src/print_view.rs
+++ b/crates/ui-egui/src/print_view.rs
@@ -856,7 +856,8 @@ fn paint_cell(
clip.add(egui::Shape::mesh(mesh));
}
None => {
- clip.rect_filled(shown, 0.0, if photo.is_some() { Color32::from_gray(52) } else { Color32::from_gray(200) });
+ let t = Tokens::get(painter.ctx());
+ clip.rect_filled(shown, 0.0, if photo.is_some() { t.skeleton } else { t.track });
}
}
if im.stroke_enabled && im.stroke_width_pt > 0.0 {
diff --git a/crates/ui-egui/src/progress.rs b/crates/ui-egui/src/progress.rs
index 01ec92a1b..ed2964395 100644
--- a/crates/ui-egui/src/progress.rs
+++ b/crates/ui-egui/src/progress.rs
@@ -18,6 +18,8 @@ use egui::{Color32, Pos2, Rect, Response, Sense, Shape, Stroke, Ui, pos2, vec2};
use crate::theme::Tokens;
+/// A bar in a model row: it leaves the row's Cancel button its place.
+pub const ROW_WIDTH: f32 = 260.0;
/// The narrowest a bar that fills the available width is drawn.
const MIN_WIDTH: f32 = 96.0;
/// Height of a bar that carries text.
diff --git a/crates/ui-egui/src/tests_progress.rs b/crates/ui-egui/src/tests_progress.rs
index bd2c28e28..ebdbda756 100644
--- a/crates/ui-egui/src/tests_progress.rs
+++ b/crates/ui-egui/src/tests_progress.rs
@@ -133,6 +133,20 @@ fn a_busy_button_ignores_clicks_and_is_announced_busy() {
assert!(!nodes.iter().any(|n| n.busy), "{nodes:?}");
}
+#[test]
+fn a_busy_button_stays_reachable_by_the_keyboard() {
+ let place = Rect::from_min_size(Pos2::ZERO, vec2(120.0, 30.0));
+ let mut asked = false;
+ let (_, _, focused) = frames(Vec::new(), |ui| {
+ let r = Button::new("Analyze").busy(true).show_at(ui, place);
+ if !std::mem::replace(&mut asked, true) {
+ r.request_focus();
+ }
+ r.has_focus()
+ });
+ assert!(focused, "focus is kept while it works");
+}
+
#[test]
fn a_button_keeps_its_width_while_busy() {
for (text, icon) in [("Analyze", None), ("Analyze", Some(Icon::Trash)), ("", Some(Icon::Trash))] {
@@ -159,7 +173,7 @@ fn a_button_keeps_its_width_while_busy() {
fn the_thumbnail_placeholder_stands_apart_in_every_theme() {
for kind in ThemeKind::ALL {
let t = Tokens::for_kind(kind);
- for (name, behind) in [("grid", t.grid_bg), ("cell", t.cell), ("canvas", t.canvas)] {
+ for (name, behind) in [("grid", t.grid_bg), ("cell", t.cell), ("selected cell", t.cell_selected), ("canvas", t.canvas)] {
let c = contrast(t.skeleton, behind);
assert!(c >= 1.1, "{kind:?}: the placeholder on the {name} is {c:.2}:1");
}
diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs
index 132797a3c..95e042e39 100644
--- a/crates/ui-egui/src/theme.rs
+++ b/crates/ui-egui/src/theme.rs
@@ -128,7 +128,7 @@ impl Default for Tokens {
grid_bg: Color32::from_rgb(0x0f, 0x0f, 0x0f),
cell: Color32::from_rgb(0x1c, 0x1c, 0x1c),
cell_selected: Color32::from_rgb(0x2d, 0x2d, 0x2d),
- skeleton: Color32::from_rgb(0x26, 0x26, 0x26),
+ skeleton: Color32::from_rgb(0x25, 0x25, 0x25),
divider: Color32::from_rgb(0x1c, 0x1c, 0x1c),
inset: Color32::from_rgb(0x23, 0x23, 0x23),
field: Color32::from_rgb(0x22, 0x22, 0x22),
@@ -176,7 +176,7 @@ impl Tokens {
grid_bg: rgb(0x080808),
cell: rgb(0x121212),
cell_selected: rgb(0x262626),
- skeleton: rgb(0x202020),
+ skeleton: rgb(0x1d1d1d),
divider: rgb(0x0e0e0e),
inset: rgb(0x181818),
field: rgb(0x161616),
@@ -194,7 +194,7 @@ impl Tokens {
grid_bg: rgb(0xd9d9d9),
cell: rgb(0xcbcbcb),
cell_selected: rgb(0xb4b4b4),
- skeleton: rgb(0xb8b8b8),
+ skeleton: rgb(0xbfbfbf),
divider: rgb(0xc4c4c4),
inset: rgb(0xdcdcdc),
field: rgb(0xf6f6f6),
@@ -225,7 +225,7 @@ impl Tokens {
grid_bg: rgb(0xf2f2f2),
cell: rgb(0xe8e8e8),
cell_selected: rgb(0xd2d2d2),
- skeleton: rgb(0xd6d6d6),
+ skeleton: rgb(0xdddddd),
divider: rgb(0xe0e0e0),
inset: rgb(0xf0f0f0),
field: rgb(0xffffff),