From 3dbb289460105c265031a3ebf2c0b8b5c28919ec Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 21 Nov 2026 16:59:54 +0100 Subject: [PATCH] Status bar: keep the bar the slot's direct child, memoize its body and trailing group One memoized view around the whole status bar made the bar a child of the status slot's row: since craft-libs 02be56cfbb a memoized view in a row moves down onto the row's line, so the bar was shifted about 5 px and its readout was clipped at the window's bottom edge. The bar now stays the slot's direct child, as on main, and its body (readout, message) and trailing group (render path, redraw, job) are a memoized view each, as the options bar's lead is. --- crates/ui-egui/src/menu_floor_trials.rs | 29 +++++ crates/ui-egui/src/panels/status_bar.rs | 159 +++++++++++++----------- 2 files changed, 113 insertions(+), 75 deletions(-) diff --git a/crates/ui-egui/src/menu_floor_trials.rs b/crates/ui-egui/src/menu_floor_trials.rs index 333f8b484c2..9fdb3eb08af 100644 --- a/crates/ui-egui/src/menu_floor_trials.rs +++ b/crates/ui-egui/src/menu_floor_trials.rs @@ -6,6 +6,7 @@ use craft::ui::runtime::measure::{MemoRun, last_frame_derived_builds, last_frame_memo_runs, last_pass_memo_key_bytes}; use egui::{Event, Pos2, vec2}; use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT as _, Queryable as _}; use serde_json::json; use crate::PhotocraftApp; @@ -156,3 +157,31 @@ fn the_held_menu_model_equals_a_fresh_build_after_each_step() { h.state_mut().session.saved_to("/tmp/Renamed.psd".into()); held_is_fresh(&mut h, "a save that renames the document"); } + +#[test] +fn the_status_bar_sits_inside_the_window_when_its_views_run_and_replay() { + let mut h = harness(1, 0, 0); + let screen = h.ctx.content_rect(); + // The status bar's zoom field: the lowest node named Zoom that shows the percentage as its value. + let field = |h: &H| { + h.query_all_by_label("Zoom") + .filter(|n| { + let a = n.accesskit_node(); + a.role() != egui::accesskit::Role::Slider && a.value().is_some() && a.bounding_box().is_some() + }) + .map(|n| n.rect()) + .max_by(|a, b| a.bottom().total_cmp(&b.bottom())) + }; + // A settled frame replays the bar's views; a status message runs its body again. + for step in ["settled", "a status message"] { + if step == "a status message" { + h.state_mut().ui.status = "Saved".into(); + } + h.run_steps(2); + let Some(field) = field(&h) else { panic!("{step}: the status bar shows its zoom field") }; + assert!( + field.bottom() <= screen.bottom() && field.top() >= screen.bottom() - 40.0, + "{step}: the zoom field {field:?} sits in the status bar inside the window {screen:?}, not moved down past its edge" + ); + } +} diff --git a/crates/ui-egui/src/panels/status_bar.rs b/crates/ui-egui/src/panels/status_bar.rs index e7a87005f80..9ca8bd15dac 100644 --- a/crates/ui-egui/src/panels/status_bar.rs +++ b/crates/ui-egui/src/panels/status_bar.rs @@ -33,7 +33,7 @@ impl Progress { } } -/// Every input of the status bar. +/// Every input of the status bar's body: the readout and the status message. #[derive(MemoProps)] struct StatusProps<'a> { values: StatusValues, @@ -42,6 +42,12 @@ struct StatusProps<'a> { /// The active document's main canvas as its last pass showed it; a document not yet shown has no readout. view: Option, message: Option, + out: Outbox<'a, StatusEvent>, +} + +/// Every input of the status bar's trailing group: the render-path note, the background redraw and the job. +#[derive(MemoProps)] +struct TrailingProps<'a> { render_path: Option, redraw: Option, job: Option, @@ -62,91 +68,94 @@ enum StatusEvent { /// The status bar, in the shell's status slot: the zoom readout of the active document and the latest status /// message, and at the far end the render-path note, the background redraw and the background jobs' progress with -/// Cancel (#210). One view holds the whole bar, so a frame where none of it changed replays it. +/// Cancel (#210). The body and the trailing group are a memoized view each, so a frame where neither changed replays +/// them. The bar itself stays the slot's direct child: it fills the slot's height and centres its content there, where +/// a memoized view around it would be moved down onto the slot row's line and clipped at the window's bottom edge. pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let job = crate::jobs_ui::status_job(app); - let mut sent = Vec::new(); - let props = StatusProps { - values: chrome_ui::status_values(app), - item: chrome_ui::status_item(&app.ui.chrome), - document: app.session.active().map(|st| Size::new(st.doc.size.width as f64, st.doc.size.height as f64)), - view: crate::canvas::active_view(app), - message: (!app.ui.status.is_empty()) - .then(|| StatusMessage::new(app.ui.status.clone()).tone(if app.ui.status_error { Tone::Warn } else { Tone::Neutral })), - render_path: chrome_ui::render_path_label(app) - .map(|(label, tip, command)| StatusMessage::new(label).tone(Tone::Warn).command(CommandRef::new(command)).tooltip(tip)), - redraw: crate::background_redraw::progress(app), - job: job.as_ref().map(|(_, progress)| progress.clone()), - out: Outbox::new(&mut sent), - }; - let _ = MemoView::new("status-bar", props, status_view).show(ui); - let mut invalid_zoom = None; - for event in sent { + let values = chrome_ui::status_values(app); + let item = chrome_ui::status_item(&app.ui.chrome); + let document = app.session.active().map(|st| Size::new(st.doc.size.width as f64, st.doc.size.height as f64)); + let view = crate::canvas::active_view(app); + let message = + (!app.ui.status.is_empty()).then(|| StatusMessage::new(app.ui.status.clone()).tone(if app.ui.status_error { Tone::Warn } else { Tone::Neutral })); + let render_path = chrome_ui::render_path_label(app) + .map(|(label, tip, command)| StatusMessage::new(label).tone(Tone::Warn).command(CommandRef::new(command)).tooltip(tip)); + let redraw = crate::background_redraw::progress(app); + let progress = job.as_ref().map(|(_, progress)| progress.clone()); + // The bar may run each group more than once in a pass (it measures the trailing group first); each run sends into + // its group's outbox, and the last of each kind of event applies below. + let (mut body_sent, mut trailing_sent) = (Vec::new(), Vec::new()); + Bar::new("", BarKind::Status) + .trailing(|ui, _| { + let props = TrailingProps { render_path: render_path.clone(), redraw: redraw.clone(), job: progress.clone(), out: Outbox::new(&mut trailing_sent) }; + let _ = MemoView::new("status-bar-trailing", props, trailing_view).show(ui); + }) + .show(ui, |ui, _| { + let props = StatusProps { values: values.clone(), item, document, view, message: message.clone(), out: Outbox::new(&mut body_sent) }; + let _ = MemoView::new("status-bar", props, body_view).show(ui); + }); + let (mut picked, mut edited, mut invalid_zoom, mut cancelled) = (None, None, None, false); + for event in body_sent.into_iter().chain(trailing_sent) { match event { - StatusEvent::Item(picked) => chrome_ui::set_status_item(&mut app.ui.chrome, picked), - StatusEvent::View(new) => { - if let Some(i) = app.session.active_index() { - let ppp = app.canvas_ppp(); - app.ui.views[i].set_from(&new, ppp); - } - } + StatusEvent::Item(item) => picked = Some(item), + StatusEvent::View(new) => edited = Some(new), StatusEvent::InvalidZoom(invalid) => invalid_zoom = Some(invalid), - StatusEvent::CancelJob => { - if let Some((id, _)) = &job { - crate::jobs_ui::cancel(app, *id); - } - } + StatusEvent::CancelJob => cancelled = true, } } + if let Some(picked) = picked { + chrome_ui::set_status_item(&mut app.ui.chrome, picked); + } + if let Some(new) = edited + && let Some(i) = app.session.active_index() + { + let ppp = app.canvas_ppp(); + app.ui.views[i].set_from(&new, ppp); + } + if cancelled && let Some((id, _)) = &job { + crate::jobs_ui::cancel(app, *id); + } chrome_ui::zoom_alert(app, invalid_zoom); } -/// The status bar's view. -fn status_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { - let mut cancelled = false; - let mut picked = None; - let mut invalid_zoom = None; - let mut edited = None; - Bar::new("", BarKind::Status) - .trailing(|ui, _| { - if let Some(shown) = &props.render_path { - shown.show(ui); - } - if let Some(progress) = &props.redraw { - progress.widget().show(ui); - } - if let Some(progress) = &props.job { - cancelled |= progress.widget().show(ui).cancelled; - } - }) - .show(ui, |ui, _| { - match (props.document, props.view) { - (Some(size), Some(view)) => { - let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui); - picked = out.item.or(picked); - invalid_zoom = out.invalid_zoom.or(invalid_zoom.take()); - edited = out.view.value().copied().or(edited); - } - (Some(_), None) => {} - (None, _) => { - StatusMessage::new(tl!("No document")).show(ui); - } - } - // A command run with no document open still reports here (#1567: File › Automate › Batch). - if let Some(shown) = &props.message { - shown.show(ui); - } - }); - if let Some(picked) = picked { - props.out.send(StatusEvent::Item(picked)); +/// The status bar's trailing group. +fn trailing_view(props: &mut TrailingProps<'_>, ui: &mut egui::Ui) { + if let Some(shown) = &props.render_path { + shown.show(ui); } - if let Some(view) = edited { - props.out.send(StatusEvent::View(view)); + if let Some(progress) = &props.redraw { + progress.widget().show(ui); } - if let Some(invalid) = invalid_zoom { - props.out.send(StatusEvent::InvalidZoom(invalid)); - } - if cancelled { + if let Some(progress) = &props.job + && progress.widget().show(ui).cancelled + { props.out.send(StatusEvent::CancelJob); } } + +/// The status bar's body. +fn body_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) { + match (props.document, props.view) { + (Some(size), Some(view)) => { + let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui); + if let Some(picked) = out.item { + props.out.send(StatusEvent::Item(picked)); + } + if let Some(view) = out.view.value().copied() { + props.out.send(StatusEvent::View(view)); + } + if let Some(invalid) = out.invalid_zoom { + props.out.send(StatusEvent::InvalidZoom(invalid)); + } + } + (Some(_), None) => {} + (None, _) => { + StatusMessage::new(tl!("No document")).show(ui); + } + } + // A command run with no document open still reports here (#1567: File › Automate › Batch). + if let Some(shown) = &props.message { + shown.show(ui); + } +}