mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Memoized views keep the row line they stand on, so a memoized bar fills its slot
A memoized view starts a layout room of its own (`start_view_room`), which dropped the row line of the row around it. A fill-width row shown through a memoized view (an app's options bar in the shell's options slot) then measured its content with its padding on top and bottom instead of taking the slot's line: its members sat below the slot's middle and the bottom of a text button's outline was cut off. The view now keeps the line as a levelled unit does (`places: false`): its content fills the line without taking slots on it. Fixes storytold/photocraft#16405. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0130c9090f
commit
1aabfe2baf
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Rect> = 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::<Rect>));
|
||||
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:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user