From 9e53f03adea2b770d68954e404d2fa407dfc7d40 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 23 Nov 2022 19:32:32 +0000 Subject: [PATCH] Implement "gap" property for flexbox algorithm (#248) * Consistently use camelCase in test_helper.js * Add support for parsing grid style properties to test_helper.js * Add support for generating Taffy Grid styles in tests to gentest main.rs * Add generated tests for flexbox gap * Add gap property to style module * Implement gap property for flexbox algorthim * Add gap to changelog * Add tests for percentage gutters with defined parent node size * Add test for percentage gap with undefined parent node size * Fix percentage main-axis column gaps in containers with undefined main size * Gentest: delete generated tests before recreating (ensures tests are deleted if fixture is deleted) * Cargo fmt * Add test for percentage row gap in a flex-wrap container with undefined height * gentest: fix clippy warnings * Add more small benchmarks + harmonise benchmarks names with 0.1 benchmarks * Create helper function for summing axis total gap * Add flexbox-gap example * Add test for fixed gaps with undefined parent size * Remove commented out code in gentest script Co-authored-by: Alice Cecile * Use Size::UNDEFINED as the default for the gap style property * Fix fixed size column gaps with undefined parent width * Add additional flexbox gap test Co-authored-by: Alice Cecile --- RELEASES.md | 1 + benches/big_tree.rs | 29 +- .../generated/gap_column_gap_child_margins.rs | 66 ++++ benches/generated/gap_column_gap_flexible.rs | 55 ++++ ...ap_column_gap_flexible_undefined_parent.rs | 51 +++ .../generated/gap_column_gap_inflexible.rs | 45 +++ ..._column_gap_inflexible_undefined_parent.rs | 41 +++ .../gap_column_gap_justify_center.rs | 46 +++ .../gap_column_gap_justify_flex_end.rs | 46 +++ .../gap_column_gap_justify_flex_start.rs | 45 +++ .../gap_column_gap_justify_space_around.rs | 46 +++ .../gap_column_gap_justify_space_between.rs | 46 +++ .../gap_column_gap_justify_space_evenly.rs | 46 +++ .../gap_column_gap_mixed_flexible.rs | 47 +++ ..._percentage_cyclic_partially_shrinkable.rs | 54 ++++ ...column_gap_percentage_cyclic_shrinkable.rs | 52 +++ ...lumn_gap_percentage_cyclic_unshrinkable.rs | 55 ++++ .../gap_column_gap_percentage_flexible.rs | 55 ++++ .../gap_column_gap_percentage_inflexible.rs | 45 +++ ...rs => gap_column_gap_wrap_align_center.rs} | 33 +- .../gap_column_gap_wrap_align_flex_end.rs | 102 ++++++ .../gap_column_gap_wrap_align_flex_start.rs | 102 ++++++ ...gap_column_gap_wrap_align_space_around.rs} | 31 +- ...ap_column_gap_wrap_align_space_between.rs} | 31 +- .../gap_column_gap_wrap_align_stretch.rs | 69 ++++ .../generated/gap_column_row_gap_wrapping.rs | 136 ++++++++ .../gap_percentage_row_gap_wrapping.rs | 136 ++++++++ .../generated/gap_row_gap_align_items_end.rs | 78 +++++ .../gap_row_gap_align_items_stretch.rs | 77 +++++ .../gap_row_gap_column_child_margins.rs | 67 ++++ .../gap_row_gap_row_wrap_child_margins.rs | 61 ++++ benches/generated/mod.rs | 58 ++++ examples/flexbox-gap.rs | 30 ++ scripts/gentest/Cargo.toml | 1 + scripts/gentest/src/main.rs | 306 ++++++++++++++---- scripts/gentest/test_helper.js | 214 ++++++++---- src/compute/flexbox.rs | 212 ++++++++---- src/resolve.rs | 9 + src/style.rs | 6 + .../gap_column_gap_child_margins.html | 19 ++ test_fixtures/gap_column_gap_flexible.html | 19 ++ ..._column_gap_flexible_undefined_parent.html | 19 ++ test_fixtures/gap_column_gap_inflexible.html | 19 ++ ...olumn_gap_inflexible_undefined_parent.html | 19 ++ .../gap_column_gap_justify_center.html | 19 ++ .../gap_column_gap_justify_flex_end.html | 19 ++ .../gap_column_gap_justify_flex_start.html | 19 ++ .../gap_column_gap_justify_space_around.html | 19 ++ .../gap_column_gap_justify_space_between.html | 19 ++ .../gap_column_gap_justify_space_evenly.html | 19 ++ .../gap_column_gap_mixed_flexible.html | 19 ++ ...ercentage_cyclic_partially_shrinkable.html | 19 ++ ...lumn_gap_percentage_cyclic_shrinkable.html | 19 ++ ...mn_gap_percentage_cyclic_unshrinkable.html | 19 ++ .../gap_column_gap_percentage_flexible.html | 19 ++ .../gap_column_gap_percentage_inflexible.html | 19 ++ .../gap_column_gap_wrap_align_center.html | 22 ++ .../gap_column_gap_wrap_align_flex_end.html | 22 ++ .../gap_column_gap_wrap_align_flex_start.html | 22 ++ ...ap_column_gap_wrap_align_space_around.html | 22 ++ ...p_column_gap_wrap_align_space_between.html | 22 ++ .../gap_column_gap_wrap_align_stretch.html | 21 ++ .../gap_column_row_gap_wrapping.html | 25 ++ .../gap_percentage_row_gap_wrapping.html | 25 ++ .../gap_row_gap_align_items_end.html | 22 ++ .../gap_row_gap_align_items_stretch.html | 22 ++ .../gap_row_gap_column_child_margins.html | 19 ++ .../gap_row_gap_row_wrap_child_margins.html | 19 ++ .../generated/gap_column_gap_child_margins.rs | 83 +++++ tests/generated/gap_column_gap_flexible.rs | 72 +++++ ...ap_column_gap_flexible_undefined_parent.rs | 68 ++++ tests/generated/gap_column_gap_inflexible.rs | 62 ++++ ..._column_gap_inflexible_undefined_parent.rs | 58 ++++ .../gap_column_gap_justify_center.rs | 63 ++++ .../gap_column_gap_justify_flex_end.rs | 63 ++++ .../gap_column_gap_justify_flex_start.rs | 62 ++++ .../gap_column_gap_justify_space_around.rs | 63 ++++ .../gap_column_gap_justify_space_between.rs | 63 ++++ .../gap_column_gap_justify_space_evenly.rs | 63 ++++ .../gap_column_gap_mixed_flexible.rs | 64 ++++ ..._percentage_cyclic_partially_shrinkable.rs | 71 ++++ ...column_gap_percentage_cyclic_shrinkable.rs | 69 ++++ ...lumn_gap_percentage_cyclic_unshrinkable.rs | 72 +++++ .../gap_column_gap_percentage_flexible.rs | 72 +++++ .../gap_column_gap_percentage_inflexible.rs | 62 ++++ ...rs => gap_column_gap_wrap_align_center.rs} | 81 ++--- .../gap_column_gap_wrap_align_flex_end.rs | 131 ++++++++ .../gap_column_gap_wrap_align_flex_start.rs | 131 ++++++++ ...gap_column_gap_wrap_align_space_around.rs} | 79 ++--- ...ap_column_gap_wrap_align_space_between.rs} | 75 +++-- .../gap_column_gap_wrap_align_stretch.rs | 94 ++++++ .../generated/gap_column_row_gap_wrapping.rs | 177 ++++++++++ .../gap_percentage_row_gap_wrapping.rs | 177 ++++++++++ .../generated/gap_row_gap_align_items_end.rs | 107 ++++++ .../gap_row_gap_align_items_stretch.rs | 106 ++++++ .../gap_row_gap_column_child_margins.rs | 84 +++++ .../gap_row_gap_row_wrap_child_margins.rs | 78 +++++ tests/generated/mod.rs | 29 ++ 98 files changed, 5360 insertions(+), 335 deletions(-) create mode 100644 benches/generated/gap_column_gap_child_margins.rs create mode 100644 benches/generated/gap_column_gap_flexible.rs create mode 100644 benches/generated/gap_column_gap_flexible_undefined_parent.rs create mode 100644 benches/generated/gap_column_gap_inflexible.rs create mode 100644 benches/generated/gap_column_gap_inflexible_undefined_parent.rs create mode 100644 benches/generated/gap_column_gap_justify_center.rs create mode 100644 benches/generated/gap_column_gap_justify_flex_end.rs create mode 100644 benches/generated/gap_column_gap_justify_flex_start.rs create mode 100644 benches/generated/gap_column_gap_justify_space_around.rs create mode 100644 benches/generated/gap_column_gap_justify_space_between.rs create mode 100644 benches/generated/gap_column_gap_justify_space_evenly.rs create mode 100644 benches/generated/gap_column_gap_mixed_flexible.rs create mode 100644 benches/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs create mode 100644 benches/generated/gap_column_gap_percentage_cyclic_shrinkable.rs create mode 100644 benches/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs create mode 100644 benches/generated/gap_column_gap_percentage_flexible.rs create mode 100644 benches/generated/gap_column_gap_percentage_inflexible.rs rename benches/generated/{align_content_space_evenly.rs => gap_column_gap_wrap_align_center.rs} (67%) create mode 100644 benches/generated/gap_column_gap_wrap_align_flex_end.rs create mode 100644 benches/generated/gap_column_gap_wrap_align_flex_start.rs rename benches/generated/{align_content_space_around.rs => gap_column_gap_wrap_align_space_around.rs} (69%) rename benches/generated/{align_content_space_between.rs => gap_column_gap_wrap_align_space_between.rs} (69%) create mode 100644 benches/generated/gap_column_gap_wrap_align_stretch.rs create mode 100644 benches/generated/gap_column_row_gap_wrapping.rs create mode 100644 benches/generated/gap_percentage_row_gap_wrapping.rs create mode 100644 benches/generated/gap_row_gap_align_items_end.rs create mode 100644 benches/generated/gap_row_gap_align_items_stretch.rs create mode 100644 benches/generated/gap_row_gap_column_child_margins.rs create mode 100644 benches/generated/gap_row_gap_row_wrap_child_margins.rs create mode 100644 examples/flexbox-gap.rs create mode 100644 test_fixtures/gap_column_gap_child_margins.html create mode 100644 test_fixtures/gap_column_gap_flexible.html create mode 100644 test_fixtures/gap_column_gap_flexible_undefined_parent.html create mode 100644 test_fixtures/gap_column_gap_inflexible.html create mode 100644 test_fixtures/gap_column_gap_inflexible_undefined_parent.html create mode 100644 test_fixtures/gap_column_gap_justify_center.html create mode 100644 test_fixtures/gap_column_gap_justify_flex_end.html create mode 100644 test_fixtures/gap_column_gap_justify_flex_start.html create mode 100644 test_fixtures/gap_column_gap_justify_space_around.html create mode 100644 test_fixtures/gap_column_gap_justify_space_between.html create mode 100644 test_fixtures/gap_column_gap_justify_space_evenly.html create mode 100644 test_fixtures/gap_column_gap_mixed_flexible.html create mode 100644 test_fixtures/gap_column_gap_percentage_cyclic_partially_shrinkable.html create mode 100644 test_fixtures/gap_column_gap_percentage_cyclic_shrinkable.html create mode 100644 test_fixtures/gap_column_gap_percentage_cyclic_unshrinkable.html create mode 100644 test_fixtures/gap_column_gap_percentage_flexible.html create mode 100644 test_fixtures/gap_column_gap_percentage_inflexible.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_center.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_flex_end.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_flex_start.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_space_around.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_space_between.html create mode 100644 test_fixtures/gap_column_gap_wrap_align_stretch.html create mode 100644 test_fixtures/gap_column_row_gap_wrapping.html create mode 100644 test_fixtures/gap_percentage_row_gap_wrapping.html create mode 100644 test_fixtures/gap_row_gap_align_items_end.html create mode 100644 test_fixtures/gap_row_gap_align_items_stretch.html create mode 100644 test_fixtures/gap_row_gap_column_child_margins.html create mode 100644 test_fixtures/gap_row_gap_row_wrap_child_margins.html create mode 100644 tests/generated/gap_column_gap_child_margins.rs create mode 100644 tests/generated/gap_column_gap_flexible.rs create mode 100644 tests/generated/gap_column_gap_flexible_undefined_parent.rs create mode 100644 tests/generated/gap_column_gap_inflexible.rs create mode 100644 tests/generated/gap_column_gap_inflexible_undefined_parent.rs create mode 100644 tests/generated/gap_column_gap_justify_center.rs create mode 100644 tests/generated/gap_column_gap_justify_flex_end.rs create mode 100644 tests/generated/gap_column_gap_justify_flex_start.rs create mode 100644 tests/generated/gap_column_gap_justify_space_around.rs create mode 100644 tests/generated/gap_column_gap_justify_space_between.rs create mode 100644 tests/generated/gap_column_gap_justify_space_evenly.rs create mode 100644 tests/generated/gap_column_gap_mixed_flexible.rs create mode 100644 tests/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs create mode 100644 tests/generated/gap_column_gap_percentage_cyclic_shrinkable.rs create mode 100644 tests/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs create mode 100644 tests/generated/gap_column_gap_percentage_flexible.rs create mode 100644 tests/generated/gap_column_gap_percentage_inflexible.rs rename tests/generated/{align_content_space_evenly.rs => gap_column_gap_wrap_align_center.rs} (50%) create mode 100644 tests/generated/gap_column_gap_wrap_align_flex_end.rs create mode 100644 tests/generated/gap_column_gap_wrap_align_flex_start.rs rename tests/generated/{align_content_space_around.rs => gap_column_gap_wrap_align_space_around.rs} (51%) rename tests/generated/{align_content_space_between.rs => gap_column_gap_wrap_align_space_between.rs} (54%) create mode 100644 tests/generated/gap_column_gap_wrap_align_stretch.rs create mode 100644 tests/generated/gap_column_row_gap_wrapping.rs create mode 100644 tests/generated/gap_percentage_row_gap_wrapping.rs create mode 100644 tests/generated/gap_row_gap_align_items_end.rs create mode 100644 tests/generated/gap_row_gap_align_items_stretch.rs create mode 100644 tests/generated/gap_row_gap_column_child_margins.rs create mode 100644 tests/generated/gap_row_gap_row_wrap_child_margins.rs diff --git a/RELEASES.md b/RELEASES.md index 28dadd256..3cfa44e8a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -12,6 +12,7 @@ - Added support for `AlignContent::SpaceEvenly` - Added `AvailableSpace` enum - Added `debug` modules with a `print_tree` function, which prints a debug representation of the computed layout for a tree of nodes. +- Added support for `gap` property (shorthand form of `row-gap`/`column-gap`) ### 0.2.0 Changed diff --git a/benches/big_tree.rs b/benches/big_tree.rs index e298127b4..97aea4183 100644 --- a/benches/big_tree.rs +++ b/benches/big_tree.rs @@ -126,9 +126,30 @@ fn taffy_benchmarks(c: &mut Criterion) { drop(group); // Decrease sample size, because the tasks take longer - let mut group = c.benchmark_group("big trees"); + let mut group = c.benchmark_group("big trees (wide)"); group.sample_size(10); + group.bench_function("10 nodes (2-level hierarchy)", |b| { + let mut taffy = Taffy::new(); + let root = build_flat_hierarchy(&mut taffy, 10); + + b.iter(|| taffy.compute_layout(root, Size::MAX_CONTENT).unwrap()) + }); + + group.bench_function("100 nodes (2-level hierarchy)", |b| { + let mut taffy = Taffy::new(); + let root = build_flat_hierarchy(&mut taffy, 100); + + b.iter(|| taffy.compute_layout(root, Size::MAX_CONTENT).unwrap()) + }); + + group.bench_function("1_000 nodes (2-level hierarchy)", |b| { + let mut taffy = Taffy::new(); + let root = build_flat_hierarchy(&mut taffy, 1_000); + + b.iter(|| taffy.compute_layout(root, Size::MAX_CONTENT).unwrap()) + }); + group.bench_function("10_000 nodes (2-level hierarchy)", |b| { let mut taffy = Taffy::new(); let root = build_flat_hierarchy(&mut taffy, 10_000); @@ -150,6 +171,12 @@ fn taffy_benchmarks(c: &mut Criterion) { b.iter(|| taffy.compute_layout(root, Size::MAX_CONTENT).unwrap()) }); + drop(group); + + // Decrease sample size, because the tasks take longer + let mut group = c.benchmark_group("big trees (deep)"); + group.sample_size(10); + group.bench_function("4000 nodes (12-level hierarchy)", |b| { let mut taffy = Taffy::new(); let root = build_deep_hierarchy(&mut taffy, 4000, 2); diff --git a/benches/generated/gap_column_gap_child_margins.rs b/benches/generated/gap_column_gap_child_margins.rs new file mode 100644 index 000000000..2a95d12f3 --- /dev/null +++ b/benches/generated/gap_column_gap_child_margins.rs @@ -0,0 +1,66 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(2f32), + end: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(10f32), + end: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(15f32), + end: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_flexible.rs b/benches/generated/gap_column_gap_flexible.rs new file mode 100644 index 000000000..0c95be0fc --- /dev/null +++ b/benches/generated/gap_column_gap_flexible.rs @@ -0,0 +1,55 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_flexible_undefined_parent.rs b/benches/generated/gap_column_gap_flexible_undefined_parent.rs new file mode 100644 index 000000000..c83163671 --- /dev/null +++ b/benches/generated/gap_column_gap_flexible_undefined_parent.rs @@ -0,0 +1,51 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { height: taffy::style::Dimension::Points(100f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_inflexible.rs b/benches/generated/gap_column_gap_inflexible.rs new file mode 100644 index 000000000..eaae60b5e --- /dev/null +++ b/benches/generated/gap_column_gap_inflexible.rs @@ -0,0 +1,45 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_inflexible_undefined_parent.rs b/benches/generated/gap_column_gap_inflexible_undefined_parent.rs new file mode 100644 index 000000000..8a7d66ced --- /dev/null +++ b/benches/generated/gap_column_gap_inflexible_undefined_parent.rs @@ -0,0 +1,41 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { height: taffy::style::Dimension::Points(100f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_center.rs b/benches/generated/gap_column_gap_justify_center.rs new file mode 100644 index 000000000..6536fbdbe --- /dev/null +++ b/benches/generated/gap_column_gap_justify_center.rs @@ -0,0 +1,46 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::Center, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_flex_end.rs b/benches/generated/gap_column_gap_justify_flex_end.rs new file mode 100644 index 000000000..c79af24e5 --- /dev/null +++ b/benches/generated/gap_column_gap_justify_flex_end.rs @@ -0,0 +1,46 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::FlexEnd, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_flex_start.rs b/benches/generated/gap_column_gap_justify_flex_start.rs new file mode 100644 index 000000000..ef1b65759 --- /dev/null +++ b/benches/generated/gap_column_gap_justify_flex_start.rs @@ -0,0 +1,45 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_space_around.rs b/benches/generated/gap_column_gap_justify_space_around.rs new file mode 100644 index 000000000..cd9b55104 --- /dev/null +++ b/benches/generated/gap_column_gap_justify_space_around.rs @@ -0,0 +1,46 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceAround, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_space_between.rs b/benches/generated/gap_column_gap_justify_space_between.rs new file mode 100644 index 000000000..5850447f3 --- /dev/null +++ b/benches/generated/gap_column_gap_justify_space_between.rs @@ -0,0 +1,46 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceBetween, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_justify_space_evenly.rs b/benches/generated/gap_column_gap_justify_space_evenly.rs new file mode 100644 index 000000000..c4fea81c6 --- /dev/null +++ b/benches/generated/gap_column_gap_justify_space_evenly.rs @@ -0,0 +1,46 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceEvenly, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_mixed_flexible.rs b/benches/generated/gap_column_gap_mixed_flexible.rs new file mode 100644 index 000000000..7c9523d9a --- /dev/null +++ b/benches/generated/gap_column_gap_mixed_flexible.rs @@ -0,0 +1,47 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs b/benches/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs new file mode 100644 index 000000000..9645e298a --- /dev/null +++ b/benches/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs @@ -0,0 +1,54 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_percentage_cyclic_shrinkable.rs b/benches/generated/gap_column_gap_percentage_cyclic_shrinkable.rs new file mode 100644 index 000000000..e066e9dd1 --- /dev/null +++ b/benches/generated/gap_column_gap_percentage_cyclic_shrinkable.rs @@ -0,0 +1,52 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs b/benches/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs new file mode 100644 index 000000000..888bf4262 --- /dev/null +++ b/benches/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs @@ -0,0 +1,55 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_percentage_flexible.rs b/benches/generated/gap_column_gap_percentage_flexible.rs new file mode 100644 index 000000000..c6ff863f9 --- /dev/null +++ b/benches/generated/gap_column_gap_percentage_flexible.rs @@ -0,0 +1,55 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Percent(0.1f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_percentage_inflexible.rs b/benches/generated/gap_column_gap_percentage_inflexible.rs new file mode 100644 index 000000000..ac84f8e89 --- /dev/null +++ b/benches/generated/gap_column_gap_percentage_inflexible.rs @@ -0,0 +1,45 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/align_content_space_evenly.rs b/benches/generated/gap_column_gap_wrap_align_center.rs similarity index 67% rename from benches/generated/align_content_space_evenly.rs rename to benches/generated/gap_column_gap_wrap_align_center.rs index 812842224..82fdd3698 100644 --- a/benches/generated/align_content_space_evenly.rs +++ b/benches/generated/gap_column_gap_wrap_align_center.rs @@ -4,8 +4,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -17,8 +17,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -30,8 +30,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -43,8 +43,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -56,8 +56,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -69,8 +69,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -82,7 +82,12 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, - align_content: taffy::style::AlignContent::SpaceEvenly, + align_content: taffy::style::AlignContent::Center, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -93,5 +98,5 @@ pub fn compute() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); } diff --git a/benches/generated/gap_column_gap_wrap_align_flex_end.rs b/benches/generated/gap_column_gap_wrap_align_flex_end.rs new file mode 100644 index 000000000..358f815c8 --- /dev/null +++ b/benches/generated/gap_column_gap_wrap_align_flex_end.rs @@ -0,0 +1,102 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_content: taffy::style::AlignContent::FlexEnd, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_gap_wrap_align_flex_start.rs b/benches/generated/gap_column_gap_wrap_align_flex_start.rs new file mode 100644 index 000000000..a418fb3c2 --- /dev/null +++ b/benches/generated/gap_column_gap_wrap_align_flex_start.rs @@ -0,0 +1,102 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_content: taffy::style::AlignContent::FlexStart, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/align_content_space_around.rs b/benches/generated/gap_column_gap_wrap_align_space_around.rs similarity index 69% rename from benches/generated/align_content_space_around.rs rename to benches/generated/gap_column_gap_wrap_align_space_around.rs index 667024a5a..a85afb217 100644 --- a/benches/generated/align_content_space_around.rs +++ b/benches/generated/gap_column_gap_wrap_align_space_around.rs @@ -4,8 +4,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -17,8 +17,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -30,8 +30,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -43,8 +43,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -56,8 +56,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -69,8 +69,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -83,6 +83,11 @@ pub fn compute() { taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, align_content: taffy::style::AlignContent::SpaceAround, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -93,5 +98,5 @@ pub fn compute() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); } diff --git a/benches/generated/align_content_space_between.rs b/benches/generated/gap_column_gap_wrap_align_space_between.rs similarity index 69% rename from benches/generated/align_content_space_between.rs rename to benches/generated/gap_column_gap_wrap_align_space_between.rs index 27df4fe08..fb9e468af 100644 --- a/benches/generated/align_content_space_between.rs +++ b/benches/generated/gap_column_gap_wrap_align_space_between.rs @@ -4,8 +4,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -17,8 +17,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -30,8 +30,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -43,8 +43,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -56,8 +56,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -69,8 +69,8 @@ pub fn compute() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -83,6 +83,11 @@ pub fn compute() { taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, align_content: taffy::style::AlignContent::SpaceBetween, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -93,5 +98,5 @@ pub fn compute() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); } diff --git a/benches/generated/gap_column_gap_wrap_align_stretch.rs b/benches/generated/gap_column_gap_wrap_align_stretch.rs new file mode 100644 index 000000000..2bcfbfb16 --- /dev/null +++ b/benches/generated/gap_column_gap_wrap_align_stretch.rs @@ -0,0 +1,69 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(5f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(300f32), + height: taffy::style::Dimension::Points(300f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_column_row_gap_wrapping.rs b/benches/generated/gap_column_row_gap_wrapping.rs new file mode 100644 index 000000000..8ebec0c5b --- /dev/null +++ b/benches/generated/gap_column_row_gap_wrapping.rs @@ -0,0 +1,136 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node6 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node7 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node8 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5, node6, node7, node8], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_percentage_row_gap_wrapping.rs b/benches/generated/gap_percentage_row_gap_wrapping.rs new file mode 100644 index 000000000..3b43f9b56 --- /dev/null +++ b/benches/generated/gap_percentage_row_gap_wrapping.rs @@ -0,0 +1,136 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node6 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node7 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node8 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Percent(0.1f32), + ..Default::default() + }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5, node6, node7, node8], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_row_gap_align_items_end.rs b/benches/generated/gap_row_gap_align_items_end.rs new file mode 100644 index 000000000..3cfb0840f --- /dev/null +++ b/benches/generated/gap_row_gap_align_items_end.rs @@ -0,0 +1,78 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_items: taffy::style::AlignItems::FlexEnd, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_row_gap_align_items_stretch.rs b/benches/generated/gap_row_gap_align_items_stretch.rs new file mode 100644 index 000000000..208bbc903 --- /dev/null +++ b/benches/generated/gap_row_gap_align_items_stretch.rs @@ -0,0 +1,77 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_row_gap_column_child_margins.rs b/benches/generated/gap_row_gap_column_child_margins.rs new file mode 100644 index 000000000..e61d54292 --- /dev/null +++ b/benches/generated/gap_row_gap_column_child_margins.rs @@ -0,0 +1,67 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(2f32), + bottom: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(10f32), + bottom: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(15f32), + bottom: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_direction: taffy::style::FlexDirection::Column, + gap: taffy::geometry::Size { height: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/gap_row_gap_row_wrap_child_margins.rs b/benches/generated/gap_row_gap_row_wrap_child_margins.rs new file mode 100644 index 000000000..9d2aa1a58 --- /dev/null +++ b/benches/generated/gap_row_gap_row_wrap_child_margins.rs @@ -0,0 +1,61 @@ +pub fn compute() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(2f32), + bottom: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(10f32), + bottom: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(15f32), + bottom: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { height: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index d9de95bdd..3db294a42 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -109,6 +109,35 @@ mod flex_shrink_to_zero; mod flex_wrap_align_stretch_fits_one_row; mod flex_wrap_children_with_min_main_overriding_flex_basis; mod flex_wrap_wrap_to_child_height; +mod gap_column_gap_child_margins; +mod gap_column_gap_flexible; +mod gap_column_gap_flexible_undefined_parent; +mod gap_column_gap_inflexible; +mod gap_column_gap_inflexible_undefined_parent; +mod gap_column_gap_justify_center; +mod gap_column_gap_justify_flex_end; +mod gap_column_gap_justify_flex_start; +mod gap_column_gap_justify_space_around; +mod gap_column_gap_justify_space_between; +mod gap_column_gap_justify_space_evenly; +mod gap_column_gap_mixed_flexible; +mod gap_column_gap_percentage_cyclic_partially_shrinkable; +mod gap_column_gap_percentage_cyclic_shrinkable; +mod gap_column_gap_percentage_cyclic_unshrinkable; +mod gap_column_gap_percentage_flexible; +mod gap_column_gap_percentage_inflexible; +mod gap_column_gap_wrap_align_center; +mod gap_column_gap_wrap_align_flex_end; +mod gap_column_gap_wrap_align_flex_start; +mod gap_column_gap_wrap_align_space_around; +mod gap_column_gap_wrap_align_space_between; +mod gap_column_gap_wrap_align_stretch; +mod gap_column_row_gap_wrapping; +mod gap_percentage_row_gap_wrapping; +mod gap_row_gap_align_items_end; +mod gap_row_gap_align_items_stretch; +mod gap_row_gap_column_child_margins; +mod gap_row_gap_row_wrap_child_margins; mod justify_content_column_center; mod justify_content_column_flex_end; mod justify_content_column_flex_start; @@ -356,6 +385,35 @@ fn benchmark(c: &mut Criterion) { flex_wrap_align_stretch_fits_one_row::compute(); flex_wrap_children_with_min_main_overriding_flex_basis::compute(); flex_wrap_wrap_to_child_height::compute(); + gap_column_gap_child_margins::compute(); + gap_column_gap_flexible::compute(); + gap_column_gap_flexible_undefined_parent::compute(); + gap_column_gap_inflexible::compute(); + gap_column_gap_inflexible_undefined_parent::compute(); + gap_column_gap_justify_center::compute(); + gap_column_gap_justify_flex_end::compute(); + gap_column_gap_justify_flex_start::compute(); + gap_column_gap_justify_space_around::compute(); + gap_column_gap_justify_space_between::compute(); + gap_column_gap_justify_space_evenly::compute(); + gap_column_gap_mixed_flexible::compute(); + gap_column_gap_percentage_cyclic_partially_shrinkable::compute(); + gap_column_gap_percentage_cyclic_shrinkable::compute(); + gap_column_gap_percentage_cyclic_unshrinkable::compute(); + gap_column_gap_percentage_flexible::compute(); + gap_column_gap_percentage_inflexible::compute(); + gap_column_gap_wrap_align_center::compute(); + gap_column_gap_wrap_align_flex_end::compute(); + gap_column_gap_wrap_align_flex_start::compute(); + gap_column_gap_wrap_align_space_around::compute(); + gap_column_gap_wrap_align_space_between::compute(); + gap_column_gap_wrap_align_stretch::compute(); + gap_column_row_gap_wrapping::compute(); + gap_percentage_row_gap_wrapping::compute(); + gap_row_gap_align_items_end::compute(); + gap_row_gap_align_items_stretch::compute(); + gap_row_gap_column_child_margins::compute(); + gap_row_gap_row_wrap_child_margins::compute(); justify_content_column_center::compute(); justify_content_column_flex_end::compute(); justify_content_column_flex_start::compute(); diff --git a/examples/flexbox-gap.rs b/examples/flexbox-gap.rs new file mode 100644 index 000000000..26de3db3c --- /dev/null +++ b/examples/flexbox-gap.rs @@ -0,0 +1,30 @@ +use taffy::prelude::*; + +// Creates three 20px x 20px children, evenly spaced 10px apart from each other +// Thus the container is 80px x 20px. + +fn main() -> Result<(), taffy::error::TaffyError> { + let mut taffy = Taffy::new(); + + let child_style = FlexboxLayout { + size: Size { width: Dimension::Points(20.0), height: Dimension::Points(20.0) }, + ..Default::default() + }; + let child0 = taffy.new_leaf(child_style.clone())?; + let child1 = taffy.new_leaf(child_style.clone())?; + let child2 = taffy.new_leaf(child_style.clone())?; + + let root = taffy.new_with_children( + FlexboxLayout { + gap: Size { width: Dimension::Points(10.0), height: Dimension::Undefined }, + ..Default::default() + }, + &[child0, child1, child2], + )?; + + // Compute layout and print result + taffy.compute_layout(root, Size::MAX_CONTENT)?; + taffy::debug::print_tree(&taffy, root); + + Ok(()) +} diff --git a/scripts/gentest/Cargo.toml b/scripts/gentest/Cargo.toml index 64e086c10..6a87db178 100644 --- a/scripts/gentest/Cargo.toml +++ b/scripts/gentest/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Emil Sjölander "] edition = "2018" [dependencies] +convert_case = "0.5.0" env_logger = "0.9.0" fantoccini = "0.19.0" json = "0.12.0" diff --git a/scripts/gentest/src/main.rs b/scripts/gentest/src/main.rs index 8a1615c32..e46f9ea22 100644 --- a/scripts/gentest/src/main.rs +++ b/scripts/gentest/src/main.rs @@ -2,11 +2,12 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; +use convert_case::{Case, Casing}; use fantoccini::{Client, ClientBuilder}; use log::*; use proc_macro2::{Span, TokenStream}; -use quote::quote; +use quote::{format_ident, quote}; use syn::Ident; #[tokio::main] @@ -91,20 +92,6 @@ async fn main() { }) .fold(quote!(), |a, b| quote!(#a #b)); - for (name, bench_body) in bench_descs { - let mut bench_filename = repo_root.join("benches").join("generated").join(&name); - bench_filename.set_extension("rs"); - debug!("writing {} to disk...", &name); - fs::write(bench_filename, bench_body.to_string()).unwrap(); - } - - for (name, test_body) in test_descs { - let mut test_filename = repo_root.join("tests").join("generated").join(&name); - test_filename.set_extension("rs"); - debug!("writing {} to disk...", &name); - fs::write(test_filename, test_body.to_string()).unwrap(); - } - let bench_mods = quote!( use criterion::{criterion_group, criterion_main, Criterion}; @@ -120,9 +107,29 @@ async fn main() { criterion_main!(benches); ); + info!("writing generated benchmarks file to disk..."); + let benches_base_path = repo_root.join("benches").join("generated"); + fs::remove_dir_all(&benches_base_path).unwrap(); + fs::create_dir(&benches_base_path).unwrap(); + for (name, bench_body) in bench_descs { + let mut bench_filename = benches_base_path.join(&name); + bench_filename.set_extension("rs"); + debug!("writing {} to disk...", &name); + fs::write(bench_filename, bench_body.to_string()).unwrap(); + } + fs::write(benches_base_path.join("mod.rs"), bench_mods.to_string()).unwrap(); + info!("writing generated test file to disk..."); - fs::write(repo_root.join("benches").join("generated").join("mod.rs"), bench_mods.to_string()).unwrap(); - fs::write(repo_root.join("tests").join("generated").join("mod.rs"), test_mods.to_string()).unwrap(); + let tests_base_path = repo_root.join("tests").join("generated"); + fs::remove_dir_all(&tests_base_path).unwrap(); + fs::create_dir(&tests_base_path).unwrap(); + for (name, test_body) in test_descs { + let mut test_filename = tests_base_path.join(&name); + test_filename.set_extension("rs"); + debug!("writing {} to disk...", &name); + fs::write(test_filename, test_body.to_string()).unwrap(); + } + fs::write(tests_base_path.join("mod.rs"), test_mods.to_string()).unwrap(); info!("formatting the source directory"); Command::new("cargo").arg("fmt").current_dir(repo_root).status().unwrap(); @@ -206,15 +213,90 @@ fn generate_assertions(ident: &str, node: &json::JsonValue) -> TokenStream { fn generate_node(ident: &str, node: &json::JsonValue) -> TokenStream { let style = &node["style"]; + fn quote_object_prop( + prop_name: &str, + style: &json::JsonValue, + quoter: impl Fn(&json::object::Object) -> TokenStream, + ) -> TokenStream { + let prop_name_snake_case = prop_name.to_case(Case::Snake); + let prop_name_camel_case = prop_name.to_case(Case::Camel); + let prop_name_ident = format_ident!("{}", prop_name_snake_case); + match style[prop_name_camel_case] { + json::JsonValue::Object(ref value) => { + let prop_value = quoter(value); + quote!(#prop_name_ident: #prop_value,) + } + _ => quote!(), + } + } + + fn quote_array_prop( + prop_name: &str, + style: &json::JsonValue, + quoter: impl Fn(&[json::JsonValue]) -> TokenStream, + ) -> TokenStream { + let prop_name_snake_case = prop_name.to_case(Case::Snake); + let prop_name_camel_case = prop_name.to_case(Case::Camel); + let prop_name_ident = format_ident!("{}", prop_name_snake_case); + match style[prop_name_camel_case] { + json::JsonValue::Array(ref value) => { + let prop_value = quoter(value); + quote!(#prop_name_ident: #prop_value,) + } + _ => quote!(), + } + } + + // This is currently unused, but leaving for future use. + #[allow(dead_code)] + fn quote_string_prop( + prop_name: &str, + style: &json::JsonValue, + quoter: impl Fn(&str) -> TokenStream, + ) -> TokenStream { + let prop_name_snake_case = prop_name.to_case(Case::Snake); + let prop_name_camel_case = prop_name.to_case(Case::Camel); + let prop_name_ident = format_ident!("{}", prop_name_snake_case); + match style[prop_name_camel_case] { + json::JsonValue::Short(ref value) => { + let prop_value = quoter(value.as_ref()); + quote!(#prop_name_ident: #prop_value,) + } + json::JsonValue::String(ref value) => { + let prop_value = quoter(value.as_ref()); + quote!(#prop_name_ident: #prop_value,) + } + _ => quote!(), + } + } + + fn quote_number_prop>( + prop_name: &str, + style: &json::JsonValue, + quoter: impl Fn(T) -> TokenStream, + ) -> TokenStream { + let prop_name_snake_case = prop_name.to_case(Case::Snake); + let prop_name_camel_case = prop_name.to_case(Case::Camel); + let prop_name_ident = format_ident!("{}", prop_name_snake_case); + match style[prop_name_camel_case] { + json::JsonValue::Number(ref value) => { + let prop_value = quoter((*value).into()); + quote!(#prop_name_ident: #prop_value,) + } + _ => quote!(), + } + } + let display = match style["display"] { json::JsonValue::Short(ref value) => match value.as_ref() { "none" => quote!(display: taffy::style::Display::None,), - _ => quote!(), + "grid" => quote!(display: taffy::style::Display::Grid,), + _ => quote!(display: taffy::style::Display::Flex,), }, _ => quote!(), }; - let position_type = match style["position_type"] { + let position_type = match style["positionType"] { json::JsonValue::Short(ref value) => match value.as_ref() { "absolute" => quote!(position_type: taffy::style::PositionType::Absolute,), _ => quote!(), @@ -307,53 +389,26 @@ fn generate_node(ident: &str, node: &json::JsonValue) -> TokenStream { _ => quote!(), }; - let flex_grow = match style["flexGrow"] { - json::JsonValue::Number(value) => { - let value: f32 = value.into(); - quote!(flex_grow: #value,) - } - _ => quote!(), - }; + let flex_grow = quote_number_prop("flex_grow", style, |value: f32| quote!(#value)); + let flex_shrink = quote_number_prop("flex_shrink", style, |value: f32| quote!(#value)); - let flex_shrink = match style["flexShrink"] { - json::JsonValue::Number(value) => { - let value: f32 = value.into(); - quote!(flex_shrink: #value,) - } - _ => quote!(), - }; - - let flex_basis = match style["flexBasis"] { - json::JsonValue::Object(ref value) => { - let value = generate_dimension(value); - quote!(flex_basis: #value,) - } - _ => quote!(), - }; + let flex_basis = quote_object_prop("flex_basis", style, generate_dimension); + let size = quote_object_prop("size", style, generate_size); + let min_size = quote_object_prop("min_size", style, generate_size); + let max_size = quote_object_prop("max_size", style, generate_size); - let size = match style["size"] { - json::JsonValue::Object(ref value) => { - let size = generate_size(value); - quote!(size: #size,) - } - _ => quote!(), - }; + let gap = quote_object_prop("gap", style, generate_gap); - let min_size = match style["min_size"] { - json::JsonValue::Object(ref value) => { - let min_size = generate_size(value); - quote!(min_size: #min_size,) - } - _ => quote!(), - }; + let grid_template_rows = quote_array_prop("grid_template_rows", style, generate_track_definition_list); + let grid_template_columns = quote_array_prop("grid_template_columns", style, generate_track_definition_list); + let grid_auto_rows = quote_array_prop("grid_auto_rows", style, generate_track_definition_list); + let grid_auto_columns = quote_array_prop("grid_auto_columns", style, generate_track_definition_list); + let grid_auto_flow = quote_object_prop("grid_auto_flow", style, generate_grid_auto_flow); - let max_size = match style["max_size"] { - json::JsonValue::Object(ref value) => { - let max_size = generate_size(value); - quote!(max_size: #max_size,) - } - _ => quote!(), - }; + let grid_row_start = quote_object_prop("grid_row_start", style, generate_grid_position); + let grid_row_end = quote_object_prop("grid_row_end", style, generate_grid_position); + let grid_column_start = quote_object_prop("grid_column_start", style, generate_grid_position); + let grid_column_end = quote_object_prop("grid_column_end", style, generate_grid_position); macro_rules! edges_quoted { ($style:ident, $val:ident) => { @@ -412,6 +467,16 @@ fn generate_node(ident: &str, node: &json::JsonValue) -> TokenStream { #flex_grow #flex_shrink #flex_basis + #gap + #grid_template_rows + #grid_template_columns + #grid_auto_rows + #grid_auto_columns + #grid_auto_flow + #grid_row_start + #grid_row_end + #grid_column_start + #grid_column_end #size #min_size #max_size @@ -426,18 +491,24 @@ fn generate_node(ident: &str, node: &json::JsonValue) -> TokenStream { ).unwrap();) } -macro_rules! dim_quoted { - ($obj:ident, $dim_name:ident) => { - let $dim_name = match $obj.get(stringify!($dim_name)) { +macro_rules! dim_quoted_renamed { + ($obj:ident, $in_name:ident, $out_name:ident) => { + let $out_name = match $obj.get(stringify!($in_name)) { Some(json::JsonValue::Object(ref value)) => { let dim = generate_dimension(value); - quote!($dim_name: #dim,) + quote!($out_name: #dim,) } _ => quote!(), }; }; } +macro_rules! dim_quoted { + ($obj:ident, $dim_name:ident) => { + dim_quoted_renamed!($obj, $dim_name, $dim_name) + }; +} + fn generate_size(size: &json::object::Object) -> TokenStream { dim_quoted!(size, width); dim_quoted!(size, height); @@ -449,6 +520,17 @@ fn generate_size(size: &json::object::Object) -> TokenStream { ) } +fn generate_gap(size: &json::object::Object) -> TokenStream { + dim_quoted_renamed!(size, column, width); + dim_quoted_renamed!(size, row, height); + quote!( + taffy::geometry::Size { + #width #height + ..Default::default() + } + ) +} + fn generate_dimension(dimen: &json::object::Object) -> TokenStream { let unit = dimen.get("unit").unwrap(); let value = || dimen.get("value").unwrap().as_f32().unwrap(); @@ -481,3 +563,95 @@ fn generate_edges(dimen: &json::object::Object) -> TokenStream { ..Default::default() }) } + +fn generate_grid_auto_flow(auto_flow: &json::object::Object) -> TokenStream { + let direction = auto_flow.get("direction").unwrap().as_str().unwrap(); + let algorithm = auto_flow.get("algorithm").unwrap().as_str().unwrap(); + + match (direction, algorithm) { + ("row", "sparse") => quote!(taffy::style::GridAutoFlow::Row), + ("column", "sparse") => quote!(taffy::style::GridAutoFlow::Column), + ("row", "dense") => quote!(taffy::style::GridAutoFlow::RowDense), + ("column", "dense") => quote!(taffy::style::GridAutoFlow::ColumnDense), + _ => unreachable!(), + } +} + +fn generate_grid_position(grid_position: &json::object::Object) -> TokenStream { + let kind = grid_position.get("kind").unwrap(); + let value = || grid_position.get("value").unwrap().as_f32().unwrap(); + + match kind { + json::JsonValue::Short(ref kind) => match kind.as_ref() { + "auto" => quote!(taffy::style::GridLine::Auto), + "span" => { + let value = value() as u16; + quote!(taffy::style::GridLine::Span(#value)) + } + "track" => { + let value = value() as i16; + quote!(taffy::style::GridLine::Track(#value)) + } + _ => unreachable!(), + }, + _ => unreachable!(), + } +} + +fn generate_track_definition_list(raw_list: &[json::JsonValue]) -> TokenStream { + let list = raw_list.iter().map(|obj| match obj { + json::JsonValue::Object(inner) => generate_track_definition(inner), + _ => unreachable!(), + }); + + quote!(vec![#(#list),*]) +} + +fn generate_track_definition(track_definition: &json::object::Object) -> TokenStream { + let kind = track_definition.get("kind").unwrap().as_str().unwrap(); + let name = || track_definition.get("name").unwrap().as_str().unwrap(); + let arguments = || track_definition.get("arguments").unwrap(); + + match kind { + "scalar" => generate_scalar_definition(track_definition), + "function" => match (name(), arguments()) { + ("minmax", json::JsonValue::Array(arguments)) => { + if arguments.len() != 2 { + panic!("minmax function with the wrong number of arguments"); + } + let min = match arguments[0] { + json::JsonValue::Object(ref arg) => generate_scalar_definition(arg), + _ => unreachable!(), + }; + let max = match arguments[1] { + json::JsonValue::Object(ref arg) => generate_scalar_definition(arg), + _ => unreachable!(), + }; + quote!(taffy::style::GridTrackSizingFunction::MinMax{ min: #min, max: #max }) + } + // TODO: Add support for fit-content + _ => unreachable!(), + }, + _ => unreachable!(), + } +} + +fn generate_scalar_definition(track_definition: &json::object::Object) -> TokenStream { + let unit = || track_definition.get("unit").unwrap().as_str().unwrap(); + let value = || track_definition.get("value").unwrap().as_f32().unwrap(); + + match unit() { + "auto" => quote!(taffy::style::GridTrackSizingFunction::Auto), + "min-content" => quote!(taffy::style::GridTrackSizingFunction::MinContent), + "max-content" => quote!(taffy::style::GridTrackSizingFunction::MaxContent), + "points" | "percent" => { + let value = generate_dimension(track_definition); + quote!(taffy::style::GridTrackSizingFunction::Fixed(#value)) + } + "fraction" => { + let value: f32 = value(); + quote!(taffy::style::GridTrackSizingFunction::Flex(#value)) + } + _ => unreachable!(), + } +} diff --git a/scripts/gentest/test_helper.js b/scripts/gentest/test_helper.js index 4baf07b1d..184cdf7e2 100644 --- a/scripts/gentest/test_helper.js +++ b/scripts/gentest/test_helper.js @@ -1,79 +1,153 @@ -function define_element_prop(property, getter) { - if (!(property in Element.prototype)) { - Object.defineProperty(Element.prototype, property, { - get: function() { - return getter(this); + +class TrackSizingParser { + static INITIAL_CHAR_REGEX = /[a-z-A-Z0-9]/; + static TOKEN_CHAR_REGEX = /[-\.a-z-A-Z0-9%]/; + + constructor(input, options = { allowFrUnits: true }) { + this.input = input; + this.index = 0; + this.options = options; + } + + parseList() { + return this._parseItemList(' ', null); + } + + parseSingleItem() { + return this.parseItem(); + } + + _parseItemList(separator, terminator = null) { + if (!separator) throw new Error('No terminator passed'); + let tokenList = []; + // console.debug('Parse List', this.index, this.input.slice(this.index)); + + while (this.index < this.input.length) { + const char = this.input[this.index]; + // console.debug(this.index, char); + + // Skip whitespace + if (char === ' ') { this.index++; continue;} + + if (TrackSizingParser.INITIAL_CHAR_REGEX.test(char)) { + const token = this._parseItem(); + tokenList.push(token); + + const nextChar = this.input[this.index]; + if ((terminator && nextChar === terminator) || !terminator && !nextChar) { + return tokenList; + } else { + this.index++; + continue; + } } - }); + + throw new Error (`Invalid start of token ${char}`); + } } -} -define_element_prop("__stretch_description__", (e) => { - return JSON.stringify(describeElement(e)); -}); - -function parseDimension(input) { - if (input.endsWith("px")) { - return { - unit: 'points', - value: Number(input.replace('px','')) - }; - } else if (input.endsWith("%")) { - return { - unit: 'percent', - value: Number(input.replace('%','')) / 100 - }; - } else { - return input == "auto" ? {unit: "auto"} : undefined; + _parseItem() { + let token = ''; + // console.debug('Parse Item', this.index, this.input.slice(this.index)); + + while (this.index < this.input.length) { + const char = this.input[this.index]; + // console.debug(this.index, char); + + if (TrackSizingParser.TOKEN_CHAR_REGEX.test(char)) { + token += char; + this.index++; + continue; + } + + if (char === '(') { + this.index++; + const args = this._parseItemList(',', ')'); + this.index++; + return { kind: 'function', name: token, arguments: args }; + } + + return { kind: 'scalar', ...this._parseScalarItem(token) }; + } + return { kind: 'scalar', ...this._parseScalarItem(token) }; + } + + _parseScalarItem(item) { + const res = parseDimension(item, { allowFrUnits: this.options.allowFrUnits }); + if (!res) throw new Error(`Invalid scalar grid track sizing function ${item}`); + return res; + } + +} + +function parseDimension(input, options = { allowFrUnits: false }) { + if (options.allowFrUnits && input.endsWith('fr')) return { unit: 'fraction', value: parseFloat(input.replace('fr','')) }; + if (input.endsWith('px')) return { unit: 'points', value: parseFloat(input.replace('px','')) }; + if (input.endsWith('%')) return { unit: 'percent', value: parseFloat(input.replace('%','')) / 100 }; + if (input === 'auto') return { unit: 'auto' }; + if (input === 'min-content') return { unit: 'min-content' }; + if (input === 'max-content') return { unit: 'max-content' }; + return undefined; } function parseNumber(input) { - if (input === "" || isNaN(input)) { - return undefined; - } else { - return Number(input); - } + if (input === '' || isNaN(input)) return undefined; + return Number(input); } function parseEnum(input) { - if (input) { - return input; - } else { - return undefined; - } + if (input) return input; + return undefined; } function parseEdges(edges) { - var start = parseDimension(edges.start); - var end = parseDimension(edges.end); - var top = parseDimension(edges.top); - var bottom = parseDimension(edges.bottom); + const start = parseDimension(edges.start); + const end = parseDimension(edges.end); + const top = parseDimension(edges.top); + const bottom = parseDimension(edges.bottom); - if (start === undefined && end === undefined && top === undefined && bottom === undefined) { - return undefined; - } - - return { - start: start, - end: end, - top: top, - bottom: bottom - }; + if (!start && !end && !top && !bottom) return undefined; + return { start, end, top, bottom }; } function parseSize(size) { - var width = parseDimension(size.width); - var height = parseDimension(size.height); + const width = parseDimension(size.width); + const height = parseDimension(size.height); - if (width === undefined && height === undefined) { - return undefined; + if (!width && !height) return undefined; + return { width, height }; +} + +function parseGaps(style) { + if (style.gap) { + const gaps = style.gap.trim().split(/\s+/).map(part => parseDimension(part)); + return { row: gaps[0], column: gaps[1] ?? gaps[0] }; + } + if (style.rowGap || style.columnGap) { + return { row: parseDimension(style.rowGap), column: parseDimension(style.columnGap) } } + return undefined; +} - return { - width: width, - height: height, - }; + +function parseGridTrackDefinitions(input) { + if (input === '') return undefined; + return new TrackSizingParser(input).parseList(); +} + +function parseGridAutoFlow(input) { + if (!/column/.test(input) && !/row/.test(input) && !/dense/.test(input)) return undefined; + const direction = /column/.test(input) ? 'column' : 'row'; + const algorithm = /dense/.test(input) ? 'dense' : 'sparse'; + return { direction, algorithm }; +} + +function parseGridPosition(input) { + if (input === 'auto') return { kind: 'auto' } + if (/^span +\d+$/.test(input)) return { kind: 'span', value: parseInt(input.replace(/[^\d]/g, ''), 10)} + if (/^-?\d+$/.test(input)) return { kind: 'track', value: parseInt(input, 10)} + return undefined; } function describeElement(e) { @@ -81,7 +155,7 @@ function describeElement(e) { style: { display: parseEnum(e.style.display), - position_type: parseEnum(e.style.position), + positionType: parseEnum(e.style.position), direction: parseEnum(e.style.direction), flexDirection: parseEnum(e.style.flexDirection), @@ -98,9 +172,22 @@ function describeElement(e) { flexShrink: parseNumber(e.style.flexShrink), flexBasis: parseDimension(e.style.flexBasis), + gridTemplateRows: parseGridTrackDefinitions(e.style.gridTemplateRows), + gridTemplateColumns: parseGridTrackDefinitions(e.style.gridTemplateColumns), + gridAutoRows: parseGridTrackDefinitions(e.style.gridAutoRows), + gridAutoColumns: parseGridTrackDefinitions(e.style.gridAutoColumns), + gridAutoFlow: parseGridAutoFlow(e.style.gridAutoFlow), + + gridRowStart: parseGridPosition(e.style.gridRowStart), + gridRowEnd: parseGridPosition(e.style.gridRowEnd), + gridColumnStart: parseGridPosition(e.style.gridColumnStart), + gridColumnEnd: parseGridPosition(e.style.gridColumnEnd), + + gap: parseGaps(e.style), + size: parseSize({width: e.style.width, height: e.style.height}), - min_size: parseSize({width: e.style.minWidth, height: e.style.minHeight}), - max_size: parseSize({width: e.style.maxWidth, height: e.style.maxHeight}), + minSize: parseSize({width: e.style.minWidth, height: e.style.minHeight}), + maxSize: parseSize({width: e.style.maxWidth, height: e.style.maxHeight}), margin: parseEdges({ start: e.style.marginLeft, @@ -141,3 +228,12 @@ function describeElement(e) { children: Array.from(e.children).map(c => describeElement(c)), } } + +// Useful when developing this script. Logs the parsed style to the console when any test fixture is opened in a browser. +window.onload = function () { + try { + console.log(describeElement(document.getElementById('test-root'))); + } catch (e) { + console.error(e); + } +} diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index f7a20ea37..47657a698 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -75,6 +75,9 @@ struct FlexItem { struct FlexLine<'a> { /// The slice of items to iterate over during computation of this line items: &'a mut [FlexItem], + /// The length in the main-axis that this line contributes to the overall main + /// main size of the container. + container_main_size_contribution: f32, /// The dimensions of the cross-axis cross_size: f32, /// The relative offset of the cross-axis @@ -98,6 +101,8 @@ struct AlgoConstants { border: Rect, /// The padding of this section padding_border: Rect, + /// The gap of this section + gap: Size, /// The size of the internal node node_inner_size: Size>, @@ -197,11 +202,24 @@ fn compute_preliminary( NODE_LOGGER.log("collect_flex_lines"); let mut flex_lines = collect_flex_lines(tree, node, &constants, available_space, &mut flex_items); + // If container size is undefined, re-resolve gap based on resolved base sizes + let original_gap = constants.gap; + if constants.node_inner_size.main(constants.dir).is_none() { + let longest_line_length = flex_lines.iter().fold(f32::MIN, |acc, line| { + let length: f32 = line.items.iter().map(|item| item.hypothetical_outer_size.main(constants.dir)).sum(); + acc.max(length) + }); + + let style = tree.style(node); + let new_gap = style.gap.width.maybe_resolve(longest_line_length).unwrap_or(0.0); + constants.gap.set_main(constants.dir, new_gap); + } + // 6. Resolve the flexible lengths of all the flex items to find their used main size. #[cfg(feature = "debug")] NODE_LOGGER.log("resolve_flexible_lengths"); for line in &mut flex_lines { - resolve_flexible_lengths(tree, line, &constants, available_space); + resolve_flexible_lengths(tree, line, &constants, original_gap, available_space); } // TODO: Cleanup and make according to spec @@ -209,11 +227,8 @@ fn compute_preliminary( constants.container_size.set_main( constants.dir, known_dimensions.main(constants.dir).unwrap_or({ - let longest_line = flex_lines.iter().fold(f32::MIN, |acc, line| { - let length: f32 = line.items.iter().map(|item| item.outer_target_size.main(constants.dir)).sum(); - acc.max(length) - }); - + let longest_line = + flex_lines.iter().fold(f32::MIN, |acc, line| acc.max(line.container_main_size_contribution)); let size = longest_line + constants.padding_border.main_axis_sum(constants.dir); match available_space.main(constants.dir) { AvailableSpace::Definite(val) if flex_lines.len() > 1 && size < val => val, @@ -291,7 +306,7 @@ fn compute_preliminary( // 15. Determine the flex container’s used cross size. #[cfg(feature = "debug")] NODE_LOGGER.log("determine_container_cross_size"); - let total_cross_size = determine_container_cross_size(&mut flex_lines, known_dimensions, &mut constants); + let total_line_cross_size = determine_container_cross_size(&mut flex_lines, known_dimensions, &mut constants); // We have the container size. // If our caller does not care about performing layout we are done now. @@ -303,7 +318,7 @@ fn compute_preliminary( // 16. Align all flex lines per align-content. #[cfg(feature = "debug")] NODE_LOGGER.log("align_flex_lines_per_align_content"); - align_flex_lines_per_align_content(tree, &mut flex_lines, node, &constants, total_cross_size); + align_flex_lines_per_align_content(tree, &mut flex_lines, node, &constants, total_line_cross_size); // Do a final layout pass and gather the resulting layouts #[cfg(feature = "debug")] @@ -356,6 +371,7 @@ fn compute_constants( width: node_size.width.maybe_sub(padding_border.horizontal_axis_sum()), height: node_size.height.maybe_sub(padding_border.vertical_axis_sum()), }; + let gap = style.gap.resolve_or_default(node_inner_size.or(Size { width: Some(0.0), height: Some(0.0) })); let container_size = Size::ZERO; let inner_container_size = Size::ZERO; @@ -367,6 +383,7 @@ fn compute_constants( is_wrap_reverse, margin, border, + gap, padding_border, node_inner_size, container_size, @@ -621,9 +638,15 @@ fn collect_flex_lines<'a>( let mut lines = crate::sys::new_vec_with_capacity(1); if tree.style(node).flex_wrap == FlexWrap::NoWrap { - lines.push(FlexLine { items: flex_items.as_mut_slice(), cross_size: 0.0, offset_cross: 0.0 }); + lines.push(FlexLine { + items: flex_items.as_mut_slice(), + container_main_size_contribution: 0.0, + cross_size: 0.0, + offset_cross: 0.0, + }); } else { let mut flex_items = &mut flex_items[..]; + let main_axis_gap = constants.gap.main(constants.dir); while !flex_items.is_empty() { let mut line_length = 0.0; @@ -631,7 +654,10 @@ fn collect_flex_lines<'a>( .iter() .enumerate() .find(|&(idx, child)| { - line_length += child.hypothetical_outer_size.main(constants.dir); + // Gaps only occur between items (not before the first one or after the last one) + // So first item in the line does not contribute a gap to the line length + let gap_contribution = if idx == 0 { 0.0 } else { main_axis_gap }; + line_length += child.hypothetical_outer_size.main(constants.dir) + gap_contribution; if let AvailableSpace::Definite(main) = available_space.main(constants.dir) { line_length > main && idx != 0 } else { @@ -642,7 +668,7 @@ fn collect_flex_lines<'a>( .unwrap_or(flex_items.len()); let (items, rest) = flex_items.split_at_mut(index); - lines.push(FlexLine { items, cross_size: 0.0, offset_cross: 0.0 }); + lines.push(FlexLine { items, container_main_size_contribution: 0.0, cross_size: 0.0, offset_cross: 0.0 }); flex_items = rest; } } @@ -658,14 +684,20 @@ fn resolve_flexible_lengths( tree: &mut impl LayoutTree, line: &mut FlexLine, constants: &AlgoConstants, + original_gap: Size, available_space: Size, ) { + let total_original_main_axis_gap = sum_axis_gaps(original_gap.main(constants.dir), line.items.len()); + let total_main_axis_gap = sum_axis_gaps(constants.gap.main(constants.dir), line.items.len()); + // 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all // items on the line. If the sum is less than the flex container’s inner main size, // use the flex grow factor for the rest of this algorithm; otherwise, use the // flex shrink factor. - let used_flex_factor: f32 = line.items.iter().map(|child| child.hypothetical_outer_size.main(constants.dir)).sum(); + let total_hypothetical_outer_main_size = + line.items.iter().map(|child| child.hypothetical_outer_size.main(constants.dir)).sum::(); + let used_flex_factor: f32 = total_original_main_axis_gap + total_hypothetical_outer_main_size; let growing = used_flex_factor < constants.node_inner_size.main(constants.dir).unwrap_or(0.0); let shrinking = !growing; @@ -713,18 +745,22 @@ fn resolve_flexible_lengths( } } + let total_target_size = line.items.iter().map(|child| child.outer_target_size.main(constants.dir)).sum::(); + line.container_main_size_contribution = total_target_size + total_original_main_axis_gap; + // 3. Calculate initial free space. Sum the outer sizes of all items on the line, // and subtract this from the flex container’s inner main size. For frozen items, // use their outer target main size; for other items, use their outer flex base size. - let used_space: f32 = line - .items - .iter() - .map(|child| { - child.margin.main_axis_sum(constants.dir) - + if child.frozen { child.target_size.main(constants.dir) } else { child.flex_basis } - }) - .sum(); + let used_space: f32 = total_main_axis_gap + + line + .items + .iter() + .map(|child| { + child.margin.main_axis_sum(constants.dir) + + if child.frozen { child.target_size.main(constants.dir) } else { child.flex_basis } + }) + .sum::(); let initial_free_space = constants.node_inner_size.main(constants.dir).maybe_sub(used_space).unwrap_or(0.0); @@ -744,14 +780,15 @@ fn resolve_flexible_lengths( // value is less than the magnitude of the remaining free space, use this // as the remaining free space. - let used_space: f32 = line - .items - .iter() - .map(|child| { - child.margin.main_axis_sum(constants.dir) - + if child.frozen { child.target_size.main(constants.dir) } else { child.flex_basis } - }) - .sum(); + let used_space: f32 = total_main_axis_gap + + line + .items + .iter() + .map(|child| { + child.margin.main_axis_sum(constants.dir) + + if child.frozen { child.target_size.main(constants.dir) } else { child.flex_basis } + }) + .sum::(); let mut unfrozen: Vec<&mut FlexItem> = line.items.iter_mut().filter(|child| !child.frozen).collect(); @@ -762,13 +799,14 @@ fn resolve_flexible_lengths( }); let free_space = if growing && sum_flex_grow < 1.0 { - (initial_free_space * sum_flex_grow) + (initial_free_space * sum_flex_grow - total_main_axis_gap) .maybe_min(constants.node_inner_size.main(constants.dir).maybe_sub(used_space)) } else if shrinking && sum_flex_shrink < 1.0 { - (initial_free_space * sum_flex_shrink) + (initial_free_space * sum_flex_shrink - total_main_axis_gap) .maybe_max(constants.node_inner_size.main(constants.dir).maybe_sub(used_space)) } else { - (constants.node_inner_size.main(constants.dir).maybe_sub(used_space)).unwrap_or(0.0) + (constants.node_inner_size.main(constants.dir).maybe_sub(used_space)) + .unwrap_or(used_flex_factor - used_space) }; // c. Distribute free space proportional to the flex factors. @@ -1085,7 +1123,8 @@ fn handle_align_content_stretch( constants: &AlgoConstants, ) { if tree.style(node).align_content == AlignContent::Stretch && node_size.cross(constants.dir).is_some() { - let total_cross: f32 = flex_lines.iter().map(|line| line.cross_size).sum(); + let total_cross_axis_gap = sum_axis_gaps(constants.gap.cross(constants.dir), flex_lines.len()); + let total_cross: f32 = flex_lines.iter().map(|line| line.cross_size).sum::() + total_cross_axis_gap; let inner_cross = (node_size.cross(constants.dir).maybe_sub(constants.padding_border.cross_axis_sum(constants.dir))) .unwrap_or(0.0); @@ -1161,7 +1200,9 @@ fn distribute_remaining_free_space( constants: &AlgoConstants, ) { for line in flex_lines { - let used_space: f32 = line.items.iter().map(|child| child.outer_target_size.main(constants.dir)).sum(); + let total_main_axis_gap = sum_axis_gaps(constants.gap.main(constants.dir), line.items.len()); + let used_space: f32 = total_main_axis_gap + + line.items.iter().map(|child| child.outer_target_size.main(constants.dir)).sum::(); let free_space = constants.inner_container_size.main(constants.dir) - used_space; let mut num_auto_margins = 0; @@ -1198,47 +1239,62 @@ fn distribute_remaining_free_space( } else { let num_items = line.items.len(); let layout_reverse = constants.dir.is_reverse(); + let gap = constants.gap.main(constants.dir); let justify_item = |(i, child): (usize, &mut FlexItem)| { let is_first = i == 0; child.offset_main = match tree.style(node).justify_content { JustifyContent::FlexStart => { - if layout_reverse && is_first { - free_space + if is_first { + if layout_reverse { + free_space + } else { + 0.0 + } } else { - 0.0 + gap } } JustifyContent::Center => { if is_first { free_space / 2.0 } else { - 0.0 + gap } } JustifyContent::FlexEnd => { - if is_first && !layout_reverse { - free_space + if is_first { + if !layout_reverse { + free_space + } else { + 0.0 + } } else { - 0.0 + gap } } JustifyContent::SpaceBetween => { if is_first { 0.0 } else { - free_space / (num_items - 1) as f32 + gap + (free_space / (num_items - 1) as f32) } } JustifyContent::SpaceAround => { if is_first { (free_space / num_items as f32) / 2.0 } else { - free_space / num_items as f32 + gap + (free_space / num_items as f32) + } + } + JustifyContent::SpaceEvenly => { + if is_first { + free_space / (num_items + 1) as f32 + } else { + gap + (free_space / (num_items + 1) as f32) } } - JustifyContent::SpaceEvenly => free_space / (num_items + 1) as f32, }; }; @@ -1388,13 +1444,14 @@ fn determine_container_cross_size( node_size: Size>, constants: &mut AlgoConstants, ) -> f32 { - let total_cross_size: f32 = flex_lines.iter().map(|line| line.cross_size).sum(); + let total_cross_axis_gap = sum_axis_gaps(constants.gap.cross(constants.dir), flex_lines.len()); + let total_line_cross_size: f32 = flex_lines.iter().map(|line| line.cross_size).sum::(); constants.container_size.set_cross( constants.dir, - node_size - .cross(constants.dir) - .unwrap_or(total_cross_size + constants.padding_border.cross_axis_sum(constants.dir)), + node_size.cross(constants.dir).unwrap_or( + total_line_cross_size + total_cross_axis_gap + constants.padding_border.cross_axis_sum(constants.dir), + ), ); constants.inner_container_size.set_cross( @@ -1402,7 +1459,7 @@ fn determine_container_cross_size( constants.container_size.cross(constants.dir) - constants.padding_border.cross_axis_sum(constants.dir), ); - total_cross_size + total_line_cross_size } /// Align all flex lines per `align-content`. @@ -1418,48 +1475,70 @@ fn align_flex_lines_per_align_content( constants: &AlgoConstants, total_cross_size: f32, ) { - let free_space = constants.inner_container_size.cross(constants.dir) - total_cross_size; let num_lines = flex_lines.len(); + let gap = constants.gap.cross(constants.dir); + let total_cross_axis_gap = sum_axis_gaps(gap, num_lines); + let free_space = constants.inner_container_size.cross(constants.dir) - total_cross_size - total_cross_axis_gap; let align_line = |(i, line): (usize, &mut FlexLine)| { let is_first = i == 0; line.offset_cross = match tree.style(node).align_content { AlignContent::FlexStart => { - if is_first && constants.is_wrap_reverse { - free_space + if is_first { + if constants.is_wrap_reverse { + free_space + } else { + 0.0 + } } else { - 0.0 + gap } } AlignContent::FlexEnd => { - if is_first && !constants.is_wrap_reverse { - free_space + if is_first { + if !constants.is_wrap_reverse { + free_space + } else { + 0.0 + } } else { - 0.0 + gap } } AlignContent::Center => { if is_first { free_space / 2.0 } else { + gap + } + } + AlignContent::Stretch => { + if is_first { 0.0 + } else { + gap + } + } + AlignContent::SpaceEvenly => { + if is_first { + free_space / (num_lines + 1) as f32 + } else { + gap + (free_space / (num_lines + 1) as f32) } } - AlignContent::Stretch => 0.0, - AlignContent::SpaceEvenly => free_space / (num_lines + 1) as f32, AlignContent::SpaceBetween => { if is_first { 0.0 } else { - free_space / (num_lines - 1) as f32 + gap + (free_space / (num_lines - 1) as f32) } } AlignContent::SpaceAround => { if is_first { (free_space / num_lines as f32) / 2.0 } else { - free_space / num_lines as f32 + gap + (free_space / num_lines as f32) } } }; @@ -1760,6 +1839,21 @@ fn hidden_layout(tree: &mut impl LayoutTree, node: Node, order: u32) { } } +/// Computes the total space taken up by gaps in an axis given: +/// - The size of each gap +/// - The number of items (children or flex-lines) between which there are gaps +#[inline(always)] +fn sum_axis_gaps(gap: f32, num_items: usize) -> f32 { + // Gaps only exist between items, so... + if num_items <= 1 { + // ...if there are less than 2 items then there are no gaps + 0.0 + } else { + // ...otherwise there are (num_items - 1) gaps + gap * (num_items - 1) as f32 + } +} + #[cfg(test)] mod tests { use super::hidden_layout; diff --git a/src/resolve.rs b/src/resolve.rs index ac32b260d..e8895d213 100644 --- a/src/resolve.rs +++ b/src/resolve.rs @@ -65,6 +65,15 @@ impl ResolveOrDefault, f32> for Dimension { } } +impl ResolveOrDefault>, Size> for Size { + fn resolve_or_default(self, context: Size>) -> Size { + Size { + width: self.width.resolve_or_default(context.width), + height: self.height.resolve_or_default(context.height), + } + } +} + impl ResolveOrDefault>, Rect> for Rect { fn resolve_or_default(self, context: Size>) -> Rect { Rect { diff --git a/src/style.rs b/src/style.rs index d1f11dd86..5a9a99958 100644 --- a/src/style.rs +++ b/src/style.rs @@ -395,6 +395,9 @@ pub struct FlexboxLayout { pub padding: Rect, /// How large should the border be on each side? pub border: Rect, + // Gap + /// How large should the gaps between items in a grid or flex container be? + pub gap: Size, /// The relative rate at which this item grows when it is expanding to fill space /// /// 0.0 is the default value, and this value must not be negative. @@ -433,6 +436,7 @@ impl FlexboxLayout { margin: Rect::UNDEFINED, padding: Rect::UNDEFINED, border: Rect::UNDEFINED, + gap: Size::UNDEFINED, flex_grow: 0.0, flex_shrink: 1.0, flex_basis: Dimension::Auto, @@ -554,6 +558,7 @@ impl FlexboxLayout { #[cfg(test)] mod tests { use super::FlexboxLayout; + use crate::geometry::Size; #[test] fn defaults_match() { @@ -570,6 +575,7 @@ mod tests { margin: Default::default(), padding: Default::default(), border: Default::default(), + gap: Size::UNDEFINED, flex_grow: 0.0, flex_shrink: 1.0, flex_basis: super::Dimension::Auto, diff --git a/test_fixtures/gap_column_gap_child_margins.html b/test_fixtures/gap_column_gap_child_margins.html new file mode 100644 index 000000000..1f115a82c --- /dev/null +++ b/test_fixtures/gap_column_gap_child_margins.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_flexible.html b/test_fixtures/gap_column_gap_flexible.html new file mode 100644 index 000000000..14a6fc14c --- /dev/null +++ b/test_fixtures/gap_column_gap_flexible.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_flexible_undefined_parent.html b/test_fixtures/gap_column_gap_flexible_undefined_parent.html new file mode 100644 index 000000000..e029d0702 --- /dev/null +++ b/test_fixtures/gap_column_gap_flexible_undefined_parent.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_inflexible.html b/test_fixtures/gap_column_gap_inflexible.html new file mode 100644 index 000000000..eb7df4872 --- /dev/null +++ b/test_fixtures/gap_column_gap_inflexible.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_inflexible_undefined_parent.html b/test_fixtures/gap_column_gap_inflexible_undefined_parent.html new file mode 100644 index 000000000..08d0ab8c8 --- /dev/null +++ b/test_fixtures/gap_column_gap_inflexible_undefined_parent.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_center.html b/test_fixtures/gap_column_gap_justify_center.html new file mode 100644 index 000000000..e3334fe7e --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_center.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_flex_end.html b/test_fixtures/gap_column_gap_justify_flex_end.html new file mode 100644 index 000000000..80bed383d --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_flex_end.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_flex_start.html b/test_fixtures/gap_column_gap_justify_flex_start.html new file mode 100644 index 000000000..94f989fac --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_flex_start.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_space_around.html b/test_fixtures/gap_column_gap_justify_space_around.html new file mode 100644 index 000000000..97a5d28c8 --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_space_around.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_space_between.html b/test_fixtures/gap_column_gap_justify_space_between.html new file mode 100644 index 000000000..36267faa0 --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_space_between.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_justify_space_evenly.html b/test_fixtures/gap_column_gap_justify_space_evenly.html new file mode 100644 index 000000000..5128393e0 --- /dev/null +++ b/test_fixtures/gap_column_gap_justify_space_evenly.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_mixed_flexible.html b/test_fixtures/gap_column_gap_mixed_flexible.html new file mode 100644 index 000000000..c4008ee38 --- /dev/null +++ b/test_fixtures/gap_column_gap_mixed_flexible.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_percentage_cyclic_partially_shrinkable.html b/test_fixtures/gap_column_gap_percentage_cyclic_partially_shrinkable.html new file mode 100644 index 000000000..994f1370f --- /dev/null +++ b/test_fixtures/gap_column_gap_percentage_cyclic_partially_shrinkable.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_percentage_cyclic_shrinkable.html b/test_fixtures/gap_column_gap_percentage_cyclic_shrinkable.html new file mode 100644 index 000000000..88149a777 --- /dev/null +++ b/test_fixtures/gap_column_gap_percentage_cyclic_shrinkable.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_percentage_cyclic_unshrinkable.html b/test_fixtures/gap_column_gap_percentage_cyclic_unshrinkable.html new file mode 100644 index 000000000..c86a03d68 --- /dev/null +++ b/test_fixtures/gap_column_gap_percentage_cyclic_unshrinkable.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_percentage_flexible.html b/test_fixtures/gap_column_gap_percentage_flexible.html new file mode 100644 index 000000000..564929b6e --- /dev/null +++ b/test_fixtures/gap_column_gap_percentage_flexible.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_percentage_inflexible.html b/test_fixtures/gap_column_gap_percentage_inflexible.html new file mode 100644 index 000000000..697edb824 --- /dev/null +++ b/test_fixtures/gap_column_gap_percentage_inflexible.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_center.html b/test_fixtures/gap_column_gap_wrap_align_center.html new file mode 100644 index 000000000..4a68fbe91 --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_center.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_flex_end.html b/test_fixtures/gap_column_gap_wrap_align_flex_end.html new file mode 100644 index 000000000..8d31ad7d0 --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_flex_end.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_flex_start.html b/test_fixtures/gap_column_gap_wrap_align_flex_start.html new file mode 100644 index 000000000..58ea7fe89 --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_flex_start.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_space_around.html b/test_fixtures/gap_column_gap_wrap_align_space_around.html new file mode 100644 index 000000000..5169e02d3 --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_space_around.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_space_between.html b/test_fixtures/gap_column_gap_wrap_align_space_between.html new file mode 100644 index 000000000..03c59e551 --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_space_between.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_gap_wrap_align_stretch.html b/test_fixtures/gap_column_gap_wrap_align_stretch.html new file mode 100644 index 000000000..30796ed9d --- /dev/null +++ b/test_fixtures/gap_column_gap_wrap_align_stretch.html @@ -0,0 +1,21 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_column_row_gap_wrapping.html b/test_fixtures/gap_column_row_gap_wrapping.html new file mode 100644 index 000000000..db64565d3 --- /dev/null +++ b/test_fixtures/gap_column_row_gap_wrapping.html @@ -0,0 +1,25 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_percentage_row_gap_wrapping.html b/test_fixtures/gap_percentage_row_gap_wrapping.html new file mode 100644 index 000000000..997d9569f --- /dev/null +++ b/test_fixtures/gap_percentage_row_gap_wrapping.html @@ -0,0 +1,25 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_row_gap_align_items_end.html b/test_fixtures/gap_row_gap_align_items_end.html new file mode 100644 index 000000000..ff181aac0 --- /dev/null +++ b/test_fixtures/gap_row_gap_align_items_end.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_row_gap_align_items_stretch.html b/test_fixtures/gap_row_gap_align_items_stretch.html new file mode 100644 index 000000000..26d8aee90 --- /dev/null +++ b/test_fixtures/gap_row_gap_align_items_stretch.html @@ -0,0 +1,22 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_row_gap_column_child_margins.html b/test_fixtures/gap_row_gap_column_child_margins.html new file mode 100644 index 000000000..2fa48fba3 --- /dev/null +++ b/test_fixtures/gap_row_gap_column_child_margins.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/gap_row_gap_row_wrap_child_margins.html b/test_fixtures/gap_row_gap_row_wrap_child_margins.html new file mode 100644 index 000000000..2dd020369 --- /dev/null +++ b/test_fixtures/gap_row_gap_row_wrap_child_margins.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/gap_column_gap_child_margins.rs b/tests/generated/gap_column_gap_child_margins.rs new file mode 100644 index 000000000..dfa78096f --- /dev/null +++ b/tests/generated/gap_column_gap_child_margins.rs @@ -0,0 +1,83 @@ +#[test] +fn gap_column_gap_child_margins() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(2f32), + end: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(10f32), + end: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + start: taffy::style::Dimension::Points(15f32), + end: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 2f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 2f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 2f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 26f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 2f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 63f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_flexible.rs b/tests/generated/gap_column_gap_flexible.rs new file mode 100644 index 000000000..20c054ad5 --- /dev/null +++ b/tests/generated/gap_column_gap_flexible.rs @@ -0,0 +1,72 @@ +#[test] +fn gap_column_gap_flexible() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_flexible_undefined_parent.rs b/tests/generated/gap_column_gap_flexible_undefined_parent.rs new file mode 100644 index 000000000..cbb13a4ce --- /dev/null +++ b/tests/generated/gap_column_gap_flexible_undefined_parent.rs @@ -0,0 +1,68 @@ +#[test] +fn gap_column_gap_flexible_undefined_parent() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { height: taffy::style::Dimension::Points(100f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 10f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_inflexible.rs b/tests/generated/gap_column_gap_inflexible.rs new file mode 100644 index 000000000..6a563cc6a --- /dev/null +++ b/tests/generated/gap_column_gap_inflexible.rs @@ -0,0 +1,62 @@ +#[test] +fn gap_column_gap_inflexible() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_inflexible_undefined_parent.rs b/tests/generated/gap_column_gap_inflexible_undefined_parent.rs new file mode 100644 index 000000000..0cf432d1d --- /dev/null +++ b/tests/generated/gap_column_gap_inflexible_undefined_parent.rs @@ -0,0 +1,58 @@ +#[test] +fn gap_column_gap_inflexible_undefined_parent() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { height: taffy::style::Dimension::Points(100f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_center.rs b/tests/generated/gap_column_gap_justify_center.rs new file mode 100644 index 000000000..37ea4edf4 --- /dev/null +++ b/tests/generated/gap_column_gap_justify_center.rs @@ -0,0 +1,63 @@ +#[test] +fn gap_column_gap_justify_center() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::Center, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 10f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 70f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_flex_end.rs b/tests/generated/gap_column_gap_justify_flex_end.rs new file mode 100644 index 000000000..855bacc8a --- /dev/null +++ b/tests/generated/gap_column_gap_justify_flex_end.rs @@ -0,0 +1,63 @@ +#[test] +fn gap_column_gap_justify_flex_end() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::FlexEnd, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 20f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 80f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_flex_start.rs b/tests/generated/gap_column_gap_justify_flex_start.rs new file mode 100644 index 000000000..835ef17bb --- /dev/null +++ b/tests/generated/gap_column_gap_justify_flex_start.rs @@ -0,0 +1,62 @@ +#[test] +fn gap_column_gap_justify_flex_start() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_space_around.rs b/tests/generated/gap_column_gap_justify_space_around.rs new file mode 100644 index 000000000..ab22c4f9c --- /dev/null +++ b/tests/generated/gap_column_gap_justify_space_around.rs @@ -0,0 +1,63 @@ +#[test] +fn gap_column_gap_justify_space_around() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceAround, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 3f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 77f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_space_between.rs b/tests/generated/gap_column_gap_justify_space_between.rs new file mode 100644 index 000000000..e365c2cdf --- /dev/null +++ b/tests/generated/gap_column_gap_justify_space_between.rs @@ -0,0 +1,63 @@ +#[test] +fn gap_column_gap_justify_space_between() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceBetween, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 80f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_justify_space_evenly.rs b/tests/generated/gap_column_gap_justify_space_evenly.rs new file mode 100644 index 000000000..a937128c6 --- /dev/null +++ b/tests/generated/gap_column_gap_justify_space_evenly.rs @@ -0,0 +1,63 @@ +#[test] +fn gap_column_gap_justify_space_evenly() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + justify_content: taffy::style::JustifyContent::SpaceEvenly, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 5f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 75f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_mixed_flexible.rs b/tests/generated/gap_column_gap_mixed_flexible.rs new file mode 100644 index 000000000..b67fe9ed1 --- /dev/null +++ b/tests/generated/gap_column_gap_mixed_flexible.rs @@ -0,0 +1,64 @@ +#[test] +fn gap_column_gap_mixed_flexible() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(80f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs b/tests/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs new file mode 100644 index 000000000..70389ebbf --- /dev/null +++ b/tests/generated/gap_column_gap_percentage_cyclic_partially_shrinkable.rs @@ -0,0 +1,71 @@ +#[test] +fn gap_column_gap_percentage_cyclic_partially_shrinkable() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 80f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_percentage_cyclic_shrinkable.rs b/tests/generated/gap_column_gap_percentage_cyclic_shrinkable.rs new file mode 100644 index 000000000..cfc20adec --- /dev/null +++ b/tests/generated/gap_column_gap_percentage_cyclic_shrinkable.rs @@ -0,0 +1,69 @@ +#[test] +fn gap_column_gap_percentage_cyclic_shrinkable() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 12f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 12f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 24f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 12f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 48f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs b/tests/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs new file mode 100644 index 000000000..ff69fe5bb --- /dev/null +++ b/tests/generated/gap_column_gap_percentage_cyclic_unshrinkable.rs @@ -0,0 +1,72 @@ +#[test] +fn gap_column_gap_percentage_cyclic_unshrinkable() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_shrink: 0f32, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(40f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 32f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 40f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 64f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_percentage_flexible.rs b/tests/generated/gap_column_gap_percentage_flexible.rs new file mode 100644 index 000000000..d89d81c6f --- /dev/null +++ b/tests/generated/gap_column_gap_percentage_flexible.rs @@ -0,0 +1,72 @@ +#[test] +fn gap_column_gap_percentage_flexible() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Percent(0.1f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 27f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 27f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 37f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 27f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 73f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/gap_column_gap_percentage_inflexible.rs b/tests/generated/gap_column_gap_percentage_inflexible.rs new file mode 100644 index 000000000..3a3332688 --- /dev/null +++ b/tests/generated/gap_column_gap_percentage_inflexible.rs @@ -0,0 +1,62 @@ +#[test] +fn gap_column_gap_percentage_inflexible() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + gap: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 40f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 80f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); +} diff --git a/tests/generated/align_content_space_evenly.rs b/tests/generated/gap_column_gap_wrap_align_center.rs similarity index 50% rename from tests/generated/align_content_space_evenly.rs rename to tests/generated/gap_column_gap_wrap_align_center.rs index 060d12f50..48335cd16 100644 --- a/tests/generated/align_content_space_evenly.rs +++ b/tests/generated/gap_column_gap_wrap_align_center.rs @@ -1,12 +1,12 @@ #[test] -fn align_content_space_evenly() { +fn gap_column_gap_wrap_align_center() { let mut taffy = taffy::Taffy::new(); let node0 = taffy .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -18,8 +18,8 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -31,8 +31,8 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -44,8 +44,8 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -57,8 +57,8 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -70,8 +70,8 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -83,7 +83,12 @@ fn align_content_space_evenly() { .new_with_children( taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, - align_content: taffy::style::AlignContent::SpaceEvenly, + align_content: taffy::style::AlignContent::Center, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -94,33 +99,33 @@ fn align_content_space_evenly() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); - assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node0).unwrap().size.height, 10f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node0).unwrap().location.y, 18f32); - assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node1).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node1).unwrap().location.y, 18f32); - assert_eq!(taffy.layout(node2).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node2).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node2).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node2).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node3).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node3).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node3).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node3).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node4).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node4).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node4).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node4).unwrap().location.y, 73f32); - assert_eq!(taffy.layout(node5).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node5).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node5).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node5).unwrap().location.y, 73f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 60f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 60f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 60f32); } diff --git a/tests/generated/gap_column_gap_wrap_align_flex_end.rs b/tests/generated/gap_column_gap_wrap_align_flex_end.rs new file mode 100644 index 000000000..284eab40c --- /dev/null +++ b/tests/generated/gap_column_gap_wrap_align_flex_end.rs @@ -0,0 +1,131 @@ +#[test] +fn gap_column_gap_wrap_align_flex_end() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_content: taffy::style::AlignContent::FlexEnd, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 80f32); +} diff --git a/tests/generated/gap_column_gap_wrap_align_flex_start.rs b/tests/generated/gap_column_gap_wrap_align_flex_start.rs new file mode 100644 index 000000000..95e04e9ca --- /dev/null +++ b/tests/generated/gap_column_gap_wrap_align_flex_start.rs @@ -0,0 +1,131 @@ +#[test] +fn gap_column_gap_wrap_align_flex_start() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_content: taffy::style::AlignContent::FlexStart, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 40f32); +} diff --git a/tests/generated/align_content_space_around.rs b/tests/generated/gap_column_gap_wrap_align_space_around.rs similarity index 51% rename from tests/generated/align_content_space_around.rs rename to tests/generated/gap_column_gap_wrap_align_space_around.rs index 3ef9bf030..250ecfafc 100644 --- a/tests/generated/align_content_space_around.rs +++ b/tests/generated/gap_column_gap_wrap_align_space_around.rs @@ -1,12 +1,12 @@ #[test] -fn align_content_space_around() { +fn gap_column_gap_wrap_align_space_around() { let mut taffy = taffy::Taffy::new(); let node0 = taffy .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -18,8 +18,8 @@ fn align_content_space_around() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -31,8 +31,8 @@ fn align_content_space_around() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -44,8 +44,8 @@ fn align_content_space_around() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -57,8 +57,8 @@ fn align_content_space_around() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -70,8 +70,8 @@ fn align_content_space_around() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -84,6 +84,11 @@ fn align_content_space_around() { taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, align_content: taffy::style::AlignContent::SpaceAround, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -94,33 +99,33 @@ fn align_content_space_around() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); - assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node0).unwrap().size.height, 10f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node0).unwrap().location.y, 12f32); - assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node1).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node1).unwrap().location.y, 12f32); - assert_eq!(taffy.layout(node2).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node2).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node2).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node2).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node3).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node3).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node3).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node3).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node4).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node4).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node4).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node4).unwrap().location.y, 78f32); - assert_eq!(taffy.layout(node5).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node5).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node5).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node5).unwrap().location.y, 78f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 10f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 10f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 10f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 70f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 70f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 70f32); } diff --git a/tests/generated/align_content_space_between.rs b/tests/generated/gap_column_gap_wrap_align_space_between.rs similarity index 54% rename from tests/generated/align_content_space_between.rs rename to tests/generated/gap_column_gap_wrap_align_space_between.rs index 7ee166d46..5311320e2 100644 --- a/tests/generated/align_content_space_between.rs +++ b/tests/generated/gap_column_gap_wrap_align_space_between.rs @@ -1,12 +1,12 @@ #[test] -fn align_content_space_between() { +fn gap_column_gap_wrap_align_space_between() { let mut taffy = taffy::Taffy::new(); let node0 = taffy .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -18,8 +18,8 @@ fn align_content_space_between() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -31,8 +31,8 @@ fn align_content_space_between() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -44,8 +44,8 @@ fn align_content_space_between() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -57,8 +57,8 @@ fn align_content_space_between() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -70,8 +70,8 @@ fn align_content_space_between() { .new_with_children( taffy::style::FlexboxLayout { size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(50f32), - height: taffy::style::Dimension::Points(10f32), + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), ..Default::default() }, ..Default::default() @@ -84,6 +84,11 @@ fn align_content_space_between() { taffy::style::FlexboxLayout { flex_wrap: taffy::style::FlexWrap::Wrap, align_content: taffy::style::AlignContent::SpaceBetween, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), @@ -94,33 +99,33 @@ fn align_content_space_between() { &[node0, node1, node2, node3, node4, node5], ) .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::NONE).unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); - assert_eq!(taffy.layout(node0).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node0).unwrap().size.height, 10f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); - assert_eq!(taffy.layout(node1).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node1).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node1).unwrap().location.x, 50f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); - assert_eq!(taffy.layout(node2).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node2).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node2).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node2).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node3).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node3).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node3).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node3).unwrap().location.y, 45f32); - assert_eq!(taffy.layout(node4).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node4).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node4).unwrap().location.x, 0f32); - assert_eq!(taffy.layout(node4).unwrap().location.y, 90f32); - assert_eq!(taffy.layout(node5).unwrap().size.width, 50f32); - assert_eq!(taffy.layout(node5).unwrap().size.height, 10f32); - assert_eq!(taffy.layout(node5).unwrap().location.x, 50f32); - assert_eq!(taffy.layout(node5).unwrap().location.y, 90f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 80f32); } diff --git a/tests/generated/gap_column_gap_wrap_align_stretch.rs b/tests/generated/gap_column_gap_wrap_align_stretch.rs new file mode 100644 index 000000000..2db5d8769 --- /dev/null +++ b/tests/generated/gap_column_gap_wrap_align_stretch.rs @@ -0,0 +1,94 @@ +#[test] +fn gap_column_gap_wrap_align_stretch() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { width: taffy::style::Dimension::Points(5f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(300f32), + height: taffy::style::Dimension::Points(300f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 300f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 300f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 71f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 150f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 71f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 150f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 76f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 71f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 150f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 153f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 71f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 150f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 229f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 300f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 150f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 150f32); +} diff --git a/tests/generated/gap_column_row_gap_wrapping.rs b/tests/generated/gap_column_row_gap_wrapping.rs new file mode 100644 index 000000000..c5868f95e --- /dev/null +++ b/tests/generated/gap_column_row_gap_wrapping.rs @@ -0,0 +1,177 @@ +#[test] +fn gap_column_row_gap_wrapping() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node6 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node7 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node8 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5, node6, node7, node8], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 100f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node6).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node6).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node6).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node6).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node7).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node7).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node7).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node7).unwrap().location.y, 80f32); + assert_eq!(taffy.layout(node8).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node8).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node8).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node8).unwrap().location.y, 80f32); +} diff --git a/tests/generated/gap_percentage_row_gap_wrapping.rs b/tests/generated/gap_percentage_row_gap_wrapping.rs new file mode 100644 index 000000000..2ea1a9b3f --- /dev/null +++ b/tests/generated/gap_percentage_row_gap_wrapping.rs @@ -0,0 +1,177 @@ +#[test] +fn gap_percentage_row_gap_wrapping() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node6 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node7 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node8 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Percent(0.1f32), + ..Default::default() + }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(80f32), ..Default::default() }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5, node6, node7, node8], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 80f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 60f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 20f32); + assert_eq!(taffy.layout(node6).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node6).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node6).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node6).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node7).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node7).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node7).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node7).unwrap().location.y, 40f32); + assert_eq!(taffy.layout(node8).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node8).unwrap().size.height, 20f32); + assert_eq!(taffy.layout(node8).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node8).unwrap().location.y, 40f32); +} diff --git a/tests/generated/gap_row_gap_align_items_end.rs b/tests/generated/gap_row_gap_align_items_end.rs new file mode 100644 index 000000000..210f60ab7 --- /dev/null +++ b/tests/generated/gap_row_gap_align_items_end.rs @@ -0,0 +1,107 @@ +#[test] +fn gap_row_gap_align_items_end() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + align_items: taffy::style::AlignItems::FlexEnd, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 200f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 90f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 90f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 90f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 200f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 200f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 0f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 200f32); +} diff --git a/tests/generated/gap_row_gap_align_items_stretch.rs b/tests/generated/gap_row_gap_align_items_stretch.rs new file mode 100644 index 000000000..a0846571b --- /dev/null +++ b/tests/generated/gap_row_gap_align_items_stretch.rs @@ -0,0 +1,106 @@ +#[test] +fn gap_row_gap_align_items_stretch() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node3 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node4 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node5 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(20f32), ..Default::default() }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(20f32), + ..Default::default() + }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2, node3, node4, node5], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 200f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node3).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node3).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node3).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node3).unwrap().location.y, 110f32); + assert_eq!(taffy.layout(node4).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node4).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node4).unwrap().location.x, 30f32); + assert_eq!(taffy.layout(node4).unwrap().location.y, 110f32); + assert_eq!(taffy.layout(node5).unwrap().size.width, 20f32); + assert_eq!(taffy.layout(node5).unwrap().size.height, 90f32); + assert_eq!(taffy.layout(node5).unwrap().location.x, 60f32); + assert_eq!(taffy.layout(node5).unwrap().location.y, 110f32); +} diff --git a/tests/generated/gap_row_gap_column_child_margins.rs b/tests/generated/gap_row_gap_column_child_margins.rs new file mode 100644 index 000000000..1c32592e7 --- /dev/null +++ b/tests/generated/gap_row_gap_column_child_margins.rs @@ -0,0 +1,84 @@ +#[test] +fn gap_row_gap_column_child_margins() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(2f32), + bottom: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(10f32), + bottom: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_grow: 1f32, + flex_shrink: 1f32, + flex_basis: taffy::style::Dimension::Percent(0f32), + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(15f32), + bottom: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_direction: taffy::style::FlexDirection::Column, + gap: taffy::geometry::Size { height: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 200f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 2f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 66f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 143f32); +} diff --git a/tests/generated/gap_row_gap_row_wrap_child_margins.rs b/tests/generated/gap_row_gap_row_wrap_child_margins.rs new file mode 100644 index 000000000..3d796f606 --- /dev/null +++ b/tests/generated/gap_row_gap_row_wrap_child_margins.rs @@ -0,0 +1,78 @@ +#[test] +fn gap_row_gap_row_wrap_child_margins() { + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(2f32), + bottom: taffy::style::Dimension::Points(2f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node1 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(10f32), + bottom: taffy::style::Dimension::Points(10f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node2 = taffy + .new_with_children( + taffy::style::FlexboxLayout { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(60f32), ..Default::default() }, + margin: taffy::geometry::Rect { + top: taffy::style::Dimension::Points(15f32), + bottom: taffy::style::Dimension::Points(15f32), + ..Default::default() + }, + ..Default::default() + }, + &[], + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::FlexboxLayout { + flex_wrap: taffy::style::FlexWrap::Wrap, + gap: taffy::geometry::Size { height: taffy::style::Dimension::Points(10f32), ..Default::default() }, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(200f32), + ..Default::default() + }, + ..Default::default() + }, + &[node0, node1, node2], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + assert_eq!(taffy.layout(node).unwrap().size.width, 100f32); + assert_eq!(taffy.layout(node).unwrap().size.height, 200f32); + assert_eq!(taffy.layout(node).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node).unwrap().location.y, 0f32); + assert_eq!(taffy.layout(node0).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node0).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node0).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node0).unwrap().location.y, 2f32); + assert_eq!(taffy.layout(node1).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node1).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node1).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node1).unwrap().location.y, 66f32); + assert_eq!(taffy.layout(node2).unwrap().size.width, 60f32); + assert_eq!(taffy.layout(node2).unwrap().size.height, 42f32); + assert_eq!(taffy.layout(node2).unwrap().location.x, 0f32); + assert_eq!(taffy.layout(node2).unwrap().location.y, 143f32); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 1921c8704..cda3125d5 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -108,6 +108,35 @@ mod flex_shrink_to_zero; mod flex_wrap_align_stretch_fits_one_row; mod flex_wrap_children_with_min_main_overriding_flex_basis; mod flex_wrap_wrap_to_child_height; +mod gap_column_gap_child_margins; +mod gap_column_gap_flexible; +mod gap_column_gap_flexible_undefined_parent; +mod gap_column_gap_inflexible; +mod gap_column_gap_inflexible_undefined_parent; +mod gap_column_gap_justify_center; +mod gap_column_gap_justify_flex_end; +mod gap_column_gap_justify_flex_start; +mod gap_column_gap_justify_space_around; +mod gap_column_gap_justify_space_between; +mod gap_column_gap_justify_space_evenly; +mod gap_column_gap_mixed_flexible; +mod gap_column_gap_percentage_cyclic_partially_shrinkable; +mod gap_column_gap_percentage_cyclic_shrinkable; +mod gap_column_gap_percentage_cyclic_unshrinkable; +mod gap_column_gap_percentage_flexible; +mod gap_column_gap_percentage_inflexible; +mod gap_column_gap_wrap_align_center; +mod gap_column_gap_wrap_align_flex_end; +mod gap_column_gap_wrap_align_flex_start; +mod gap_column_gap_wrap_align_space_around; +mod gap_column_gap_wrap_align_space_between; +mod gap_column_gap_wrap_align_stretch; +mod gap_column_row_gap_wrapping; +mod gap_percentage_row_gap_wrapping; +mod gap_row_gap_align_items_end; +mod gap_row_gap_align_items_stretch; +mod gap_row_gap_column_child_margins; +mod gap_row_gap_row_wrap_child_margins; mod justify_content_column_center; mod justify_content_column_flex_end; mod justify_content_column_flex_start;