diff --git a/crates/thing-core/tests/layout.rs b/crates/thing-core/tests/layout.rs index 5f4fc08..74a4045 100644 --- a/crates/thing-core/tests/layout.rs +++ b/crates/thing-core/tests/layout.rs @@ -1437,3 +1437,27 @@ fn a_nonzero_border_side_is_at_least_one_cell_in_cells_so_content_never_sits_und assert_eq!((one.0, one.1), (across, down), "a {width} px border: content starts at ({across}, {down})"); } } + +#[test] +fn a_margin_and_a_min_size_convert_each_side_at_its_own_axis_in_cells() { + // Every side of the two slots with a different Px length down than across, so an axis swap on + // any one moves a rect: margin-bottom 32 px is 2 rows (not 4), min-height 48 px is 3 rows (not 6). + let column = BoxStyle { direction: Direction::Column, align_items: ItemAlign::Start, ..sized(160.0, 160.0) }; + let a_style = BoxStyle { + size: size2(px(8.0), px(16.0)), + margin: Edges { top: px(16.0), right: px(24.0), bottom: px(32.0), left: px(8.0) }, + ..plain() + }; + let b_style = BoxStyle { min_size: size2(px(24.0), px(48.0)), ..plain() }; + let laid = lay_with(&mut MemState::new(), bx("root", column, vec![bx("a", a_style, vec![]), bx("b", b_style, vec![])]), &cells(40.0, 20.0)); + assert_eq!(rect(&laid, "a"), (1.0, 1.0, 1.0, 1.0), "margin left 8 px is 1 cell across, top 16 px is 1 row down"); + assert_eq!(rect(&laid, "b").1, 1.0 + 1.0 + 2.0, "a's top margin, a, then its 32 px bottom margin: 2 rows"); + assert_eq!((rect(&laid, "b").2, rect(&laid, "b").3), (3.0, 3.0), "min size 24 px across is 3 cells, 48 px down is 3 rows"); + let row = BoxStyle { align_items: ItemAlign::Start, ..sized(160.0, 160.0) }; + let right = lay_with(&mut MemState::new(), bx("root", row, vec![bx("a", a_style_with_margin_right(), vec![]), bx("b", plain(), vec![])]), &cells(40.0, 20.0)); + assert_eq!(rect(&right, "b").0, 1.0 + 1.0 + 3.0, "a's 8 px left margin, a (1 cell), then its 24 px right margin: 3 cells"); +} + +fn a_style_with_margin_right() -> BoxStyle { + BoxStyle { size: size2(px(8.0), px(16.0)), margin: Edges { top: px(0.0), right: px(24.0), bottom: px(0.0), left: px(8.0) }, ..plain() } +}