diff --git a/crates/ui-contract/src/runtime/env.rs b/crates/ui-contract/src/runtime/env.rs index 9c1cd92ef..7131b4c20 100644 --- a/crates/ui-contract/src/runtime/env.rs +++ b/crates/ui-contract/src/runtime/env.rs @@ -473,8 +473,13 @@ impl Scoped { let fits = self.view_fits(); let row_unit = matches!(self.shrink, Some(Shrink::Count(_) | Shrink::Least(_) | Shrink::Apply(_))); let (content_column, given_column, egui_cell) = (self.content_column, self.given_column, self.egui_cell); + // The view stands on the line of the row around it only to fill it, as a levelled unit does: a fill-width row in + // it (a bar in a shell slot) takes the line's height and centres on it, as shown without the view; its children + // take no slots on the line (photocraft#16405). + let line = self.row_line.map(|line| RowLine { places: false, ..line }); self.start_room(); (self.content_column, self.given_column, self.egui_cell) = (content_column, given_column, egui_cell); + self.row_line = line; if fits { self.shrink = Some(Shrink::Fit); } diff --git a/crates/ui-shell/tests/it/shell/app_shell.rs b/crates/ui-shell/tests/it/shell/app_shell.rs index cd4bc8a6e..bbd10972c 100644 --- a/crates/ui-shell/tests/it/shell/app_shell.rs +++ b/crates/ui-shell/tests/it/shell/app_shell.rs @@ -696,3 +696,49 @@ fn a_page_takes_the_windows_keys_with_nothing_focused() { } assert_eq!(printed.get(), 1, "Enter with nothing focused runs the page's command once"); } + +/// What a memoized options bar shows: one text button, as an app's tool options. +#[derive(MemoProps)] +struct MemoBar { + version: u64, +} + +thread_local! { + /// The rect the memoized bar's button took when it last ran. + static MEMO_BUTTON: Cell = const { Cell::new(Rect::NOTHING) }; +} + +fn memo_bar(_: &mut MemoBar, ui: &mut Ui) { + let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| { + let rect = Button::new("Straighten").show(ui).rect; + MEMO_BUTTON.with(|button| button.set(rect)); + }); +} + +/// photocraft#16405: an options bar the app shows through a memoized view sits on the slot's line as one shown directly +/// does: its text button is drawn whole, centred in the slot, not cut off at the bottom. +#[trial] +fn a_memoized_options_bar_centres_its_button_in_the_slot() { + for ppp in [1.0, 1.25, 1.5] { + let seen = Rc::new(Cell::new(None::)); + let out = Rc::clone(&seen); + let mut fixture = Fixture::new(move |ui| { + let shown = AppShell::new(WindowKey::main()) + .options_bar(true, |ui, _, _: &mut ()| { + let _ = MemoView::new("options", MemoBar { version: 0 }, memo_bar).show(ui); + }) + .body(|_, _, _| {}) + .show(ui, &mut ()); + if let Some(slot) = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect) { + out.set(Some(slot)); + } + }); + fixture.ctx().set_pixels_per_point(ppp); + fixture.room(Vec2::new(600.0, 300.0)).settle(); + let slot = seen.get().expect("the options slot shows"); + let button = MEMO_BUTTON.with(Cell::get); + assert!(button.height() > 0.0, "{ppp}: the button shows: {button:?}"); + assert!(button.max.y <= slot.max.y + 0.01 && button.min.y >= slot.min.y - 0.01, "{ppp}: the button {button:?} lies inside the slot {slot:?}"); + assert!((button.center().y - slot.center().y).abs() <= 1.0, "{ppp}: the button {button:?} sits on the slot's middle {slot:?}"); + } +}