Merge pull request #2939 from davidmann4/fix/about-float-room

Dialogs: a layer's body leaves its footer room when it fills (photocraft#16326)
This commit is contained in:
David Mann
2026-11-22 01:37:30 +01:00
committed by GitHub
3 changed files with 85 additions and 1 deletions
@@ -329,6 +329,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
// is laid out as given the room, at the footer and header this run measured, so the children that fill share
// it; its record of the content height lets later runs of the pass and kept transcripts lay it out the same.
None if self.capped(&self.props, at.env, at.at) => self.measure_capped(comp, at, cx, plan),
None if self.footed_layer() => self.measure_footed_layer(comp, at, cx, plan),
None => self.measure_run(comp, at, cx, plan.key, None),
};
self.measured_took(took, pad, vertical)
@@ -1924,6 +1925,26 @@ impl BodyHooks<'_> {
}
}
/// Whether the container is a layer with a footer: its body is laid out before the footer runs, so a body that
/// fills the layer's room takes the footer's height too, unless the run knows the footer from an earlier one.
fn footed_layer(&self) -> bool {
overlay_of(&self.props).is_some() && self.props.footer.is_some() && self.room.y.is_finite()
}
/// The measuring run of a layer with a footer (photocraft#16326): while what the regions took fits the room it
/// stands; taller (a body that fills, such as a scrolling list, took the room the footer needs), the run is taken
/// back and the body is laid out again beside the footer this run measured, so the layer keeps to its room with
/// the footer as its last row.
fn measure_footed_layer<C: Container>(&mut self, comp: &mut C, at: &Measuring<'_, '_>, cx: &mut Cx<'_, C>, plan: MeasurePlan) -> Vec2 {
let fits = self.room.y + plan.tolerance;
let (took, kept) = crate::contract::draft(&plan.ctx, || self.measure_run(comp, at, cx, plan.key.clone(), None), |took| took.y <= fits);
if kept {
return took;
}
self.measured_footer = self.footer_size.unwrap_or(Vec2::ZERO);
self.measure_run(comp, at, cx, plan.key, None)
}
/// The extent a measuring run reports from what its regions `took`.
fn measured_took(&mut self, took: Vec2, pad: Vec2, vertical: bool) -> Vec2 {
// A layer hung from an opener or a rect is at least as wide as its overlay asks for, in the measuring run too,
@@ -2,8 +2,10 @@
use craft_behavior::{DisplayOrder, ItemSource};
use craft_ui::contract::{Bind, ShowCollection as _, ShowContainer as _};
use craft_ui::contract::{Scroll, Show as _};
use craft_ui::dialog::Dialog;
use craft_ui::layout_components::Row;
use craft_ui::display::Text;
use craft_ui::layout_components::{Row, Stack};
use craft_ui::list::{List, ListRow};
use craft_ui::sections::{DialogRole, FooterButton};
use craft_ui::testing::{Fixture, trial};
@@ -53,3 +55,28 @@ fn a_dialog_with_a_filling_body_keeps_its_footer_below_the_body_and_inside_the_s
assert!(craft_ui::testing::relations::above(body, button.rect), "{label} is below the body: {:?} under {body:?}", button.rect);
}
}
/// photocraft#16326: a dialog whose body holds a scrolling stack that fills, under a line of other content, keeps to
/// its share of the screen with the footer as its last row: the body leaves the footer its height instead of taking
/// the whole room and pushing the footer past it.
#[trial]
fn a_dialog_with_a_filling_scroll_body_keeps_to_its_room_with_the_footer_last() {
let mut fixture = Fixture::new(move |ui| {
let mut open = true;
Dialog::new("Pick").opened(Bind::bound(&mut open)).buttons([FooterButton::new("OK", DialogRole::Accept)]).show(ui, |ui, _| {
Text::new("Pick a row").show(ui);
Stack::new().scroll(Scroll::vertical()).fill().show(ui, |ui, _| {
for at in 0..ROWS {
Text::new(format!("Row {at}")).show(ui);
}
});
});
});
fixture.room(egui::Vec2::new(1200.0, 700.0)).settle();
let screen = fixture.ctx().content_rect();
let dialog = fixture.by_role(craft_ui::contract::Role::DIALOG).first().expect("the dialog shows").rect;
let ok = fixture.by_label("OK").expect("the footer's OK").rect;
assert!(screen.contains_rect(dialog), "the dialog is inside the screen: {dialog:?} in {screen:?}");
assert!(dialog.height() <= 0.9 * screen.height() + 1.0, "the dialog keeps to its share of the screen: {dialog:?} in {screen:?}");
assert!(dialog.bottom() - ok.bottom() < 20.0, "OK is the dialog's last row: {ok:?} in {dialog:?}");
}
@@ -287,3 +287,39 @@ fn names_sort_without_at_and_case_and_undated_contributors_sort_last_both_ways()
sort_by(&mut fixture, "Name");
assert_eq!(rows(&fixture, &["@zed", "Ann", "@alice", "@carol"]), ["@alice", "Ann", "@carol", "@zed"], "a display name sorts among the usernames");
}
/// A crowd of contributors whose grab bag is taller than a small window.
static CROWD: LazyLock<Credits> = LazyLock::new(|| {
let people: Vec<Contributor> = (0..400).map(|at| Contributor::new(format!("contributor-number-{at}")).counts(1, 1)).collect();
Credits::new(people, Vec::new(), 400)
});
/// photocraft#16326: in a small window the Contributors tab, whose grab bag fills the room it is offered, keeps the
/// About dialog inside the window, and back on About the dialog stands centred again, as it opened.
#[trial]
fn about_stays_inside_a_small_window_on_contributors_and_comes_back_to_the_middle() {
let host = Rc::new(RefCell::new(DialogHost::new()));
let shown = Rc::clone(&host);
let mut fixture = Fixture::new(move |ui| shown.borrow_mut().run(ui));
fixture.room(Vec2::new(1200.0, 700.0));
let id = host.borrow_mut().open(HostedAbout::new(AboutInfo::new("PhotoCraft", "An image editor.", "1.0"), CROWD.clone()));
fixture.settle();
let screen = fixture.ctx().content_rect();
let dialog = |fixture: &Fixture| fixture.by_role(Role::DIALOG).first().expect("the dialog shows").rect;
let opened = dialog(&fixture);
assert!((opened.center().y - screen.center().y).abs() < 1.0, "About opens centred: {opened:?} in {screen:?}");
let ctx = fixture.ctx().clone();
host.borrow_mut().set_json_field(&ctx, id, "tab", json!("contributors")).expect("`tab` takes Contributors");
fixture.settle();
let tall = dialog(&fixture);
assert!(screen.contains_rect(tall), "Contributors keeps the dialog inside the window: {tall:?} in {screen:?}");
let ok = fixture.by_label("OK").expect("the footer's OK").rect;
assert!(tall.bottom() - ok.bottom() < 20.0, "OK is the dialog's last row: {ok:?} in {tall:?}");
assert!(tall.height() <= 0.9 * screen.height() + 1.0, "the dialog keeps to its share of the window: {tall:?} in {screen:?}");
host.borrow_mut().set_json_field(&ctx, id, "tab", json!("about")).expect("`tab` takes About");
fixture.settle();
let back = dialog(&fixture);
assert!((back.center().y - screen.center().y).abs() < 1.0, "back on About the dialog is centred again: {back:?} in {screen:?}");
}