mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 22:37:12 +00:00
craft-ui: a memoized view's content keeps the axes its body sizes from its content
start_room cleared the enclosing body's content axes, so a fill-width child in a view shown in a content-sized column took the room instead of its measured size: the tool rail's slot grid filled the Liquify and Vanishing Point dialogs' rows and left their canvases no width. The axes stay, like cell_fills and least, and the scope key holds them. Trial: a view in a content-sized column lays its fill-width row out as outside a view.
This commit is contained in:
@@ -373,13 +373,14 @@ impl Scoped {
|
||||
self.inherited_mut().values.set(InBar(false));
|
||||
}
|
||||
|
||||
/// Ends the layout room of the enclosing body: its flow grid and content column.
|
||||
/// Ends the layout room of the enclosing body: its flow grid and content column. The axes the body sizes from its
|
||||
/// content stay (`content`): like `cell_fills` and `least`, they say what a child that fills takes there, its
|
||||
/// measured size or the room, and the scope key holds them.
|
||||
pub(crate) fn start_room(&mut self) {
|
||||
self.grid = None;
|
||||
self.grid_top = false;
|
||||
self.content_column = false;
|
||||
self.given_column = false;
|
||||
self.content = (false, false);
|
||||
self.row_room = None;
|
||||
self.row_line = None;
|
||||
self.first_line = None;
|
||||
@@ -401,7 +402,7 @@ impl Scoped {
|
||||
use crate::contract::{MemoKey, MemoProps as _};
|
||||
let mut key = MemoKey::of_view(&self.ctx);
|
||||
key.feed_hash(&(self.enabled, self.read_only, self.size, self.glyphs, self.ink, self.surface, self.wheel));
|
||||
key.feed_hash(&(self.direction, self.text_direction, self.ids_stable, self.cell_fills, self.least, self.unbounded));
|
||||
key.feed_hash(&(self.direction, self.text_direction, self.ids_stable, self.cell_fills, self.least, self.unbounded, self.content));
|
||||
key.feed_hash(&(self.arena, self.roving, self.item, self.row, self.scroll_owner.map(|owner| (owner.id, owner.view))));
|
||||
self.transform.map(|transform| (transform.scale, transform.offset)).key(&mut key);
|
||||
self.footer_slot.map(|slot| (slot.owner, slot.size)).key(&mut key);
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_ui::buttons::Button;
|
||||
use craft_ui::choice::Checkbox;
|
||||
use craft_ui::contract::{Bind, MemoProps, MemoView, Props as _, Show as _, ShowContainer as _, Tracked};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::runtime::env::{BodyMode, RevealEdge, ShellCx, WindowKey};
|
||||
use craft_ui::runtime::memory::{SaveKey, set_saved_value};
|
||||
use craft_ui::runtime::{frame, inspect};
|
||||
@@ -1083,3 +1083,48 @@ fn a_view_replayed_for_frames_keeps_the_layout_memory_it_kept() {
|
||||
assert_eq!(runs_of(&frames, "Measured"), [MemoRun::Ran], "a new prop runs the view");
|
||||
assert_eq!(after_replays, after_a_run, "the replays kept the stack's measurements alive");
|
||||
}
|
||||
|
||||
#[derive(MemoProps)]
|
||||
struct Centred {
|
||||
label: String,
|
||||
}
|
||||
|
||||
/// A row that fills its width, around one button.
|
||||
fn centred(props: &mut Centred, ui: &mut Ui) {
|
||||
Row::new().fill_width().show(ui, |ui, _| {
|
||||
Button::new(props.label.clone()).show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// A memoized view in a column that takes its width from its content (beside a sibling that fills a row) lays out its
|
||||
/// fill-width row as the same content outside a view does: the column stays as narrow as its button, and the sibling
|
||||
/// takes the rest of the row.
|
||||
#[trial]
|
||||
fn a_view_in_a_content_sized_column_lays_out_its_fill_width_row_as_outside_a_view() {
|
||||
let shown = |memo: bool| {
|
||||
let mut frames = Frames::new();
|
||||
let mut rects = (Rect::NOTHING, Rect::NOTHING);
|
||||
for _ in 0..WARM {
|
||||
frames.frame(vec![], |ui| {
|
||||
in_region(ui, OUTSIDE.union(region(0)), |ui| {
|
||||
Row::new().fill().show(ui, |ui, _| {
|
||||
let column = Stack::new().show(ui, |ui, _| {
|
||||
let mut props = Centred { label: "Open".to_owned() };
|
||||
if memo {
|
||||
MemoView::new("centred", props, centred).show(ui);
|
||||
} else {
|
||||
centred(&mut props, ui);
|
||||
}
|
||||
});
|
||||
let rest = Stack::new().fill().show(ui, |ui, _| Button::new("Rest").show(ui));
|
||||
rects = (column.output.rect, rest.output.rect);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
rects
|
||||
};
|
||||
let (outside, inside) = (shown(false), shown(true));
|
||||
assert!(outside.0.width() < outside.1.width(), "the column outside a view is as narrow as its button: {outside:?}");
|
||||
assert_eq!(inside, outside, "the view's column and its sibling lie as without the view");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user