Feature dialog: draw the busy spinner in the footer row (#8362)
With the dialog buttons at the bottom, the spinner shown while the preview computes or OK applies was painted on its own after the footer: at the card's left edge and one control height up from its bottom. The footer insets its row by 12 pt at the sides and 10 pt above and below and centres the buttons, so the spinner sat outside that inset and about 10 pt below the buttons' centre line. Panel::feature now draws the spinner through the footer's left slot, so it shares the row's inset and vertical centre, in the space the footer already leaves for it before the status text. The rect is published as dialog:footer:spinner, and a panel test checks it lies in the footer row, at its left inset and on the OK button's centre line. The spinner in the title row (buttons at the top) is unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -807,23 +807,25 @@ impl<'a> Panel<'a> {
|
||||
return (close, action);
|
||||
}
|
||||
let corners = self.positioned_frame(ui.ctx()).corner_radius;
|
||||
let action = super::footer(
|
||||
// The spinner sits in the footer's own row, at its side inset and on the buttons' centre
|
||||
// line, in the slot the status text leaves for it.
|
||||
let action = super::actions::footer_with_left(
|
||||
ui,
|
||||
self.ok,
|
||||
self.cancel,
|
||||
valid && !state.applying,
|
||||
super::Footer { apply: heading.apply_label, status: state.text.as_deref(), corners: Some(corners), ..Default::default() },
|
||||
|ui| {
|
||||
if state.busy {
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(t.space_16, ui.available_height()), egui::Sense::hover());
|
||||
egui::Spinner::new().size(t.space_14).paint_at(ui, rect);
|
||||
scenario::publish_rect("dialog:footer:spinner", rect);
|
||||
let status = state.text.as_deref().unwrap_or_else(|| crate::i18n::tr_label("Updating the preview"));
|
||||
ui.interact(rect, ui.id().with("compute_status"), egui::Sense::hover()).on_hover_text(status);
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
},
|
||||
);
|
||||
if state.busy {
|
||||
let rect = egui::Rect::from_min_size(
|
||||
egui::pos2(ui.min_rect().left(), ui.min_rect().bottom() - super::row_height()),
|
||||
vec2(t.space_16, super::row_height()),
|
||||
);
|
||||
egui::Spinner::new().size(t.space_14).paint_at(ui, rect);
|
||||
let status = state.text.as_deref().unwrap_or_else(|| crate::i18n::tr_label("Updating the preview"));
|
||||
ui.interact(rect, ui.id().with("compute_status"), egui::Sense::hover()).on_hover_text(status);
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
super::Container::finish_content(ui, self.positioned_frame(ui.ctx()));
|
||||
(close, action)
|
||||
})
|
||||
|
||||
@@ -265,6 +265,50 @@ fn top_placement_shows_the_compute_status_in_the_title_row() {
|
||||
assert!(scenario::rect_of("dialog:header").unwrap().contains_rect(scenario::rect_of("dialog:cancel").unwrap()));
|
||||
}
|
||||
|
||||
/// With the buttons in the footer, the busy spinner sits in the footer's row: at its side inset
|
||||
/// and on the buttons' centre line, not against the card's edge (it used to hang there).
|
||||
#[test]
|
||||
fn bottom_placement_puts_the_busy_spinner_in_the_footer_row() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
let vp = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(640.0, 480.0));
|
||||
for _ in 0..3 {
|
||||
scenario::clear_handles();
|
||||
crate::test_support::frame(&ctx, egui::RawInput { screen_rect: Some(vp), ..Default::default() }, |_| {
|
||||
DialogButtons::Bottom.publish(&ctx);
|
||||
let side = crate::frame::Side::Right;
|
||||
let anchor = egui::pos2(vp.right() - crate::shell::SHELL_GAP, vp.top());
|
||||
let panel = Panel::new(
|
||||
"Fillet",
|
||||
egui::Id::new("bottom_status"),
|
||||
anchor,
|
||||
vp,
|
||||
side,
|
||||
Panel::feature_frame(&ctx, crate::shell::LayoutMode::Floating, side),
|
||||
);
|
||||
panel.window(&ctx).show(&ctx, |ui| {
|
||||
let heading = FeatureOptions {
|
||||
icon: "fillet",
|
||||
title: "Fillet",
|
||||
drag_key: "bottom_status",
|
||||
moved: egui::Vec2::ZERO,
|
||||
docked: anchor,
|
||||
apply_label: None,
|
||||
};
|
||||
panel.feature(ui, heading, true, true, |ui| {
|
||||
text(ui, "Input", Text::Note("row"));
|
||||
ComputeStatus { text: Some("Computing… 3 s".into()), busy: true, applying: true }
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
let spinner = scenario::rect_of("dialog:footer:spinner").expect("the spinner shows while busy");
|
||||
let actions = scenario::rect_of("dialog:footer:actions").unwrap();
|
||||
let ok = scenario::rect_of("dialog:ok").unwrap();
|
||||
assert!(actions.contains_rect(spinner), "{spinner:?} inside the footer row {actions:?}");
|
||||
assert!((spinner.left() - actions.left()).abs() < 0.5, "at the footer's inset: {spinner:?} {actions:?}");
|
||||
assert!((spinner.center().y - ok.center().y).abs() < 0.5, "on the buttons' line: {spinner:?} {ok:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn top_placement_keeps_a_managers_fold_beside_the_actions() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
|
||||
Reference in New Issue
Block a user