thing-core: a Button's content is a row in Cells as in Pixels
Finding button-content-mode-split. Cells made the Button content a stretch column and Pixels the default row, so one document laid out differently by mode beyond measuring and the f01 restart label spanned the whole content box (46 or 48 wide) instead of hugging (7). The axis is the row in both; a tall Button still centres its label between the borders, now by alignment (align_items centre) rather than by switching the axis. f01 Cells layout re-blessed: restart-label 48 -> 7 wide. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a91cafce43
commit
217ea54190
3 changed files with 34 additions and 6 deletions
|
|
@ -200,15 +200,14 @@ impl<'a> Builder<'a, '_> {
|
|||
}
|
||||
Node::Button(b) => {
|
||||
if !self.hidden(&b.common.id) {
|
||||
// In Cells a Button's content keeps clear of its border (`cells_inset`), centred
|
||||
// between the top and bottom borders of a tall one. Pixels: render draws the chrome behind it.
|
||||
// In Cells a Button's content keeps clear of its border (`cells_inset`). Its axis is a
|
||||
// row as in Pixels; a tall Button centres its items between the borders by alignment.
|
||||
// Pixels: render draws the chrome behind it.
|
||||
let style = if self.dev.cells() {
|
||||
let side = taffy::LengthPercentage::length(cells_inset(0.0).0);
|
||||
let none = taffy::LengthPercentage::length(0.0);
|
||||
Style {
|
||||
display: taffy::Display::Flex,
|
||||
flex_direction: taffy::FlexDirection::Column,
|
||||
justify_content: taffy::AlignContent::CENTER,
|
||||
align_items: taffy::AlignItems::CENTER,
|
||||
padding: taffy::Rect { left: side, right: side, top: none, bottom: none },
|
||||
..Style::default()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@ minds#6:mind-1/mind-name 51 0 49 1
|
|||
minds#6:mind-2/mind-name 0 2 50 1
|
||||
minds#6:mind-3/mind-name 51 2 49 1
|
||||
restart 0 3 50 1
|
||||
restart-label 1 3 48 1
|
||||
restart-label 1 3 7 1
|
||||
|
|
|
|||
|
|
@ -1265,3 +1265,32 @@ fn a_px_length_in_cells_is_cells_at_the_cell_metric_per_axis() {
|
|||
assert_eq!((rect(&laid, "a").2, rect(&laid, "a").3), (3.0, 2.0), "tracks: 24 px across, 32 px down");
|
||||
assert_eq!(rect(&laid, "b").0, 5.0, "the gap across is 16 px: 2 cells");
|
||||
}
|
||||
|
||||
/// A Button of `label` Text children inside a root of `size` (None: the root hugs it), laid in
|
||||
/// `frame` with the engine the frame names.
|
||||
fn laid_button(labels: &[(&str, &str)], size: Option<(f64, f64)>, frame: &LayoutFrame) -> LaidTree {
|
||||
let content = labels.iter().map(|(id, content)| text(id, content)).collect();
|
||||
let button = Node::Button(ButtonNode { common: common("btn"), content, on_activate: command("dismiss"), enabled: lit_bool(true) });
|
||||
let style = size.map_or_else(plain, |(w, h)| sized(w, h));
|
||||
let tree = bind(&mut MemState::new(), &surface_of(bx("root", style, vec![button]))).expect("resolves");
|
||||
let mut measure: Box<dyn Measure> = match frame.metrics {
|
||||
Metrics::Cells => Box::new(FixedMeasure::cells()),
|
||||
Metrics::Pixels => Box::new(FixedMeasure::pixels()),
|
||||
};
|
||||
layout(&tree, frame, &mut *measure).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_buttons_content_runs_in_a_row_in_both_metrics_and_is_centred_by_alignment() {
|
||||
// Two items side by side, as in Pixels; the label is one item, so a tall Button centres it
|
||||
// between the borders by alignment, never by changing the axis.
|
||||
for frame in [cells(40.0, 10.0), pixels(640.0, 160.0, 1.0)] {
|
||||
let laid = laid_button(&[("ab", "ab"), ("cd", "cd")], None, &frame);
|
||||
let (ab, cd) = (rect(&laid, "ab"), rect(&laid, "cd"));
|
||||
assert_eq!(ab.1, cd.1, "{:?}: one row", frame.metrics);
|
||||
assert_eq!(cd.0, ab.0 + ab.2, "{:?}: cd follows ab across", frame.metrics);
|
||||
}
|
||||
let tall = laid_button(&[("go", "Go")], Some((160.0, 80.0)), &cells(40.0, 10.0));
|
||||
assert_eq!(rect(&tall, "btn").3, 5.0);
|
||||
assert_eq!(rect(&tall, "go").1, 2.0, "the label is centred between the borders of a 5-row Button");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue