From 0bff4e2c1f44c407fad2c7d803bace181538fd3a Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 13:37:11 +0000 Subject: [PATCH 01/40] Add aspect ratio support to gentest script + add aspect ratio support to text node content sizing --- .../grid_fit_content_points_argument.rs | 8 +++- .../grid_fit_content_points_max_content.rs | 8 +++- .../grid_fit_content_points_min_content.rs | 8 +++- ...d_margins_auto_margins_override_stretch.rs | 8 +++- .../grid_max_content_maximum_single_item.rs | 8 +++- .../generated/grid_max_content_single_item.rs | 8 +++- ...rid_max_content_single_item_margin_auto.rs | 8 +++- ...id_max_content_single_item_margin_fixed.rs | 8 +++- ..._max_content_single_item_margin_percent.rs | 8 +++- .../generated/grid_min_content_flex_column.rs | 24 +++++++++-- .../generated/grid_min_content_flex_row.rs | 24 +++++++++-- .../grid_min_content_flex_single_item.rs | 8 +++- ...in_content_flex_single_item_margin_auto.rs | 8 +++- ...n_content_flex_single_item_margin_fixed.rs | 8 +++- ...content_flex_single_item_margin_percent.rs | 8 +++- .../grid_min_content_maximum_single_item.rs | 8 +++- .../generated/grid_min_content_single_item.rs | 8 +++- .../generated/grid_relayout_vertical_text.rs | 16 +++++++- .../generated/grid_size_child_fixed_tracks.rs | 40 ++++++++++++++++--- benches/generated/measure_child.rs | 8 +++- benches/generated/measure_child_absolute.rs | 8 +++- benches/generated/measure_child_constraint.rs | 2 +- ...measure_child_constraint_padding_parent.rs | 2 +- .../generated/measure_child_with_flex_grow.rs | 8 +++- .../measure_child_with_flex_shrink.rs | 8 +++- .../measure_flex_basis_overrides_measure.rs | 8 +++- .../measure_height_overrides_measure.rs | 8 +++- .../measure_remeasure_child_after_growing.rs | 8 +++- ...measure_remeasure_child_after_shrinking.rs | 8 +++- ...easure_remeasure_child_after_stretching.rs | 8 +++- benches/generated/measure_root.rs | 8 +++- .../measure_stretch_overrides_measure.rs | 8 +++- .../measure_width_overrides_measure.rs | 8 +++- benches/generated/mod.rs | 14 ++++++- scripts/gentest/src/main.rs | 38 +++++++++++++++--- scripts/gentest/test_helper.js | 15 +++++++ .../grid_fit_content_points_argument.rs | 8 +++- .../grid_fit_content_points_max_content.rs | 8 +++- .../grid_fit_content_points_min_content.rs | 8 +++- ...d_margins_auto_margins_override_stretch.rs | 8 +++- .../grid_max_content_maximum_single_item.rs | 8 +++- .../generated/grid_max_content_single_item.rs | 8 +++- ...rid_max_content_single_item_margin_auto.rs | 8 +++- ...id_max_content_single_item_margin_fixed.rs | 8 +++- ..._max_content_single_item_margin_percent.rs | 8 +++- .../generated/grid_min_content_flex_column.rs | 24 +++++++++-- tests/generated/grid_min_content_flex_row.rs | 24 +++++++++-- .../grid_min_content_flex_single_item.rs | 8 +++- ...in_content_flex_single_item_margin_auto.rs | 8 +++- ...n_content_flex_single_item_margin_fixed.rs | 8 +++- ...content_flex_single_item_margin_percent.rs | 8 +++- .../grid_min_content_maximum_single_item.rs | 8 +++- .../generated/grid_min_content_single_item.rs | 8 +++- .../generated/grid_relayout_vertical_text.rs | 16 +++++++- .../generated/grid_size_child_fixed_tracks.rs | 40 ++++++++++++++++--- tests/generated/measure_child.rs | 8 +++- tests/generated/measure_child_absolute.rs | 8 +++- tests/generated/measure_child_constraint.rs | 2 +- ...measure_child_constraint_padding_parent.rs | 2 +- .../generated/measure_child_with_flex_grow.rs | 8 +++- .../measure_child_with_flex_shrink.rs | 8 +++- .../measure_flex_basis_overrides_measure.rs | 8 +++- .../measure_height_overrides_measure.rs | 8 +++- .../measure_remeasure_child_after_growing.rs | 8 +++- ...measure_remeasure_child_after_shrinking.rs | 8 +++- ...easure_remeasure_child_after_stretching.rs | 8 +++- tests/generated/measure_root.rs | 8 +++- .../measure_stretch_overrides_measure.rs | 8 +++- .../measure_width_overrides_measure.rs | 8 +++- tests/generated/mod.rs | 14 ++++++- 70 files changed, 636 insertions(+), 93 deletions(-) diff --git a/benches/generated/grid_fit_content_points_argument.rs b/benches/generated/grid_fit_content_points_argument.rs index 1a08d5bdb..a831b56e0 100644 --- a/benches/generated/grid_fit_content_points_argument.rs +++ b/benches/generated/grid_fit_content_points_argument.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_fit_content_points_max_content.rs b/benches/generated/grid_fit_content_points_max_content.rs index c2c3829bb..9fff48fd5 100644 --- a/benches/generated/grid_fit_content_points_max_content.rs +++ b/benches/generated/grid_fit_content_points_max_content.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_fit_content_points_min_content.rs b/benches/generated/grid_fit_content_points_min_content.rs index 611fda99c..cb4f1b256 100644 --- a/benches/generated/grid_fit_content_points_min_content.rs +++ b/benches/generated/grid_fit_content_points_min_content.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_margins_auto_margins_override_stretch.rs b/benches/generated/grid_margins_auto_margins_override_stretch.rs index 8b51cc6a8..a12b36bd0 100644 --- a/benches/generated/grid_margins_auto_margins_override_stretch.rs +++ b/benches/generated/grid_margins_auto_margins_override_stretch.rs @@ -23,7 +23,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_max_content_maximum_single_item.rs b/benches/generated/grid_max_content_maximum_single_item.rs index 88fc970e8..3c72bef01 100644 --- a/benches/generated/grid_max_content_maximum_single_item.rs +++ b/benches/generated/grid_max_content_maximum_single_item.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_max_content_single_item.rs b/benches/generated/grid_max_content_single_item.rs index 956d5ff70..ad6f03f09 100644 --- a/benches/generated/grid_max_content_single_item.rs +++ b/benches/generated/grid_max_content_single_item.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_max_content_single_item_margin_auto.rs b/benches/generated/grid_max_content_single_item_margin_auto.rs index 70799c6da..480c0dc44 100644 --- a/benches/generated/grid_max_content_single_item_margin_auto.rs +++ b/benches/generated/grid_max_content_single_item_margin_auto.rs @@ -16,7 +16,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_max_content_single_item_margin_fixed.rs b/benches/generated/grid_max_content_single_item_margin_fixed.rs index 2a53d1ad8..086d3a4ca 100644 --- a/benches/generated/grid_max_content_single_item_margin_fixed.rs +++ b/benches/generated/grid_max_content_single_item_margin_fixed.rs @@ -16,7 +16,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_max_content_single_item_margin_percent.rs b/benches/generated/grid_max_content_single_item_margin_percent.rs index 3cd508ee7..2c5663eed 100644 --- a/benches/generated/grid_max_content_single_item_margin_percent.rs +++ b/benches/generated/grid_max_content_single_item_margin_percent.rs @@ -16,7 +16,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_column.rs b/benches/generated/grid_min_content_flex_column.rs index 1ec016dd8..63e1aebbc 100644 --- a/benches/generated/grid_min_content_flex_column.rs +++ b/benches/generated/grid_min_content_flex_column.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -16,7 +22,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -25,7 +37,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_row.rs b/benches/generated/grid_min_content_flex_row.rs index fce7e8674..9dbed47a7 100644 --- a/benches/generated/grid_min_content_flex_row.rs +++ b/benches/generated/grid_min_content_flex_row.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -16,7 +22,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -25,7 +37,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_single_item.rs b/benches/generated/grid_min_content_flex_single_item.rs index c4c05db81..5649fc722 100644 --- a/benches/generated/grid_min_content_flex_single_item.rs +++ b/benches/generated/grid_min_content_flex_single_item.rs @@ -22,7 +22,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_single_item_margin_auto.rs b/benches/generated/grid_min_content_flex_single_item_margin_auto.rs index ce42e39d4..9ad8ef86f 100644 --- a/benches/generated/grid_min_content_flex_single_item_margin_auto.rs +++ b/benches/generated/grid_min_content_flex_single_item_margin_auto.rs @@ -34,7 +34,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_single_item_margin_fixed.rs b/benches/generated/grid_min_content_flex_single_item_margin_fixed.rs index e30c932d5..d27ef5f6e 100644 --- a/benches/generated/grid_min_content_flex_single_item_margin_fixed.rs +++ b/benches/generated/grid_min_content_flex_single_item_margin_fixed.rs @@ -34,7 +34,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_flex_single_item_margin_percent.rs b/benches/generated/grid_min_content_flex_single_item_margin_percent.rs index ea3af0248..0e7ec42e0 100644 --- a/benches/generated/grid_min_content_flex_single_item_margin_percent.rs +++ b/benches/generated/grid_min_content_flex_single_item_margin_percent.rs @@ -34,7 +34,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_maximum_single_item.rs b/benches/generated/grid_min_content_maximum_single_item.rs index 15e6fff5c..4506d354c 100644 --- a/benches/generated/grid_min_content_maximum_single_item.rs +++ b/benches/generated/grid_min_content_maximum_single_item.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_min_content_single_item.rs b/benches/generated/grid_min_content_single_item.rs index d1e871849..d13263c15 100644 --- a/benches/generated/grid_min_content_single_item.rs +++ b/benches/generated/grid_min_content_single_item.rs @@ -8,7 +8,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_relayout_vertical_text.rs b/benches/generated/grid_relayout_vertical_text.rs index 93134c5cc..4b7b6c55b 100644 --- a/benches/generated/grid_relayout_vertical_text.rs +++ b/benches/generated/grid_relayout_vertical_text.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Vertical) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + None, + ) }), ) .unwrap(); @@ -16,7 +22,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/grid_size_child_fixed_tracks.rs b/benches/generated/grid_size_child_fixed_tracks.rs index a50d5e058..53e301a07 100644 --- a/benches/generated/grid_size_child_fixed_tracks.rs +++ b/benches/generated/grid_size_child_fixed_tracks.rs @@ -11,7 +11,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -24,7 +30,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHH\u{200b}HHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -37,7 +49,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -51,7 +69,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -65,7 +89,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_child.rs b/benches/generated/measure_child.rs index bc84bd19f..81570d5d2 100644 --- a/benches/generated/measure_child.rs +++ b/benches/generated/measure_child.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_child_absolute.rs b/benches/generated/measure_child_absolute.rs index 679593802..5c7d4433c 100644 --- a/benches/generated/measure_child_absolute.rs +++ b/benches/generated/measure_child_absolute.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { position: taffy::style::Position::Absolute, ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_child_constraint.rs b/benches/generated/measure_child_constraint.rs index e2fd457ad..3bc4c5150 100644 --- a/benches/generated/measure_child_constraint.rs +++ b/benches/generated/measure_child_constraint.rs @@ -2,7 +2,7 @@ pub fn compute() { #[allow(unused_imports)] use taffy::prelude::*; let mut taffy = taffy::Taffy::new(); - let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal) }) ,) . unwrap () ; + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , None) }) ,) . unwrap () ; let node = taffy .new_with_children( taffy::style::Style { diff --git a/benches/generated/measure_child_constraint_padding_parent.rs b/benches/generated/measure_child_constraint_padding_parent.rs index fe5b0749d..68c9a589f 100644 --- a/benches/generated/measure_child_constraint_padding_parent.rs +++ b/benches/generated/measure_child_constraint_padding_parent.rs @@ -2,7 +2,7 @@ pub fn compute() { #[allow(unused_imports)] use taffy::prelude::*; let mut taffy = taffy::Taffy::new(); - let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal) }) ,) . unwrap () ; + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , None) }) ,) . unwrap () ; let node = taffy .new_with_children( taffy::style::Style { diff --git a/benches/generated/measure_child_with_flex_grow.rs b/benches/generated/measure_child_with_flex_grow.rs index 09371b72b..f4b66a311 100644 --- a/benches/generated/measure_child_with_flex_grow.rs +++ b/benches/generated/measure_child_with_flex_grow.rs @@ -16,7 +16,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H\u{200b}H\u{200b}H\u{200b}H\u{200b}H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_child_with_flex_shrink.rs b/benches/generated/measure_child_with_flex_shrink.rs index 927888a5a..7955458a8 100644 --- a/benches/generated/measure_child_with_flex_shrink.rs +++ b/benches/generated/measure_child_with_flex_shrink.rs @@ -16,7 +16,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_flex_basis_overrides_measure.rs b/benches/generated/measure_flex_basis_overrides_measure.rs index d994ed75a..16bd75d1b 100644 --- a/benches/generated/measure_flex_basis_overrides_measure.rs +++ b/benches/generated/measure_flex_basis_overrides_measure.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_height_overrides_measure.rs b/benches/generated/measure_height_overrides_measure.rs index 7902a8cf2..7e20f3339 100644 --- a/benches/generated/measure_height_overrides_measure.rs +++ b/benches/generated/measure_height_overrides_measure.rs @@ -10,7 +10,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_remeasure_child_after_growing.rs b/benches/generated/measure_remeasure_child_after_growing.rs index 587f7778f..f3f03056a 100644 --- a/benches/generated/measure_remeasure_child_after_growing.rs +++ b/benches/generated/measure_remeasure_child_after_growing.rs @@ -16,7 +16,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_remeasure_child_after_shrinking.rs b/benches/generated/measure_remeasure_child_after_shrinking.rs index c7190de2e..c670c7603 100644 --- a/benches/generated/measure_remeasure_child_after_shrinking.rs +++ b/benches/generated/measure_remeasure_child_after_shrinking.rs @@ -17,7 +17,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_remeasure_child_after_stretching.rs b/benches/generated/measure_remeasure_child_after_stretching.rs index 938e14bb2..15f5ac9ca 100644 --- a/benches/generated/measure_remeasure_child_after_stretching.rs +++ b/benches/generated/measure_remeasure_child_after_stretching.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_root.rs b/benches/generated/measure_root.rs index eb3859e81..f1dc0ea5a 100644 --- a/benches/generated/measure_root.rs +++ b/benches/generated/measure_root.rs @@ -7,7 +7,13 @@ pub fn compute() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_stretch_overrides_measure.rs b/benches/generated/measure_stretch_overrides_measure.rs index 04d4832b4..2327aaef0 100644 --- a/benches/generated/measure_stretch_overrides_measure.rs +++ b/benches/generated/measure_stretch_overrides_measure.rs @@ -18,7 +18,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/measure_width_overrides_measure.rs b/benches/generated/measure_width_overrides_measure.rs index 302751bd3..418a858db 100644 --- a/benches/generated/measure_width_overrides_measure.rs +++ b/benches/generated/measure_width_overrides_measure.rs @@ -10,7 +10,13 @@ pub fn compute() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 30c35db8b..946885629 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -11,9 +11,13 @@ fn measure_standard_text( available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, + aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; + fn f32_max(a: f32, b: f32) -> f32 { + core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) + } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -56,8 +60,14 @@ fn measure_standard_text( (line_count as f32) * H_HEIGHT }); match writing_mode { - WritingMode::Horizontal => Size { width: inline_size, height: block_size }, - WritingMode::Vertical => Size { width: block_size, height: inline_size }, + WritingMode::Horizontal => Size { + width: inline_size, + height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), + }, + WritingMode::Vertical => Size { + width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), + height: inline_size, + }, } } mod absolute_layout_align_items_and_justify_content_center; diff --git a/scripts/gentest/src/main.rs b/scripts/gentest/src/main.rs index 7d43e7b06..36a1fcf46 100644 --- a/scripts/gentest/src/main.rs +++ b/scripts/gentest/src/main.rs @@ -334,6 +334,13 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream { } } + fn get_number_value<'a, 'b, 'c: 'b>(prop_name: &'a str, style: &'c Value) -> Option { + match style[prop_name.to_case(Case::Camel)] { + Value::Number(ref value) => Some(value.as_f64().unwrap() as f32), + _ => None, + } + } + fn quote_number_prop(prop_name: &str, style: &Value, quoter: impl Fn(f32) -> TokenStream) -> TokenStream { let prop_name_snake_case = prop_name.to_case(Case::Snake); let prop_name_camel_case = prop_name.to_case(Case::Camel); @@ -484,6 +491,7 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream { 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 aspect_ratio = quote_number_prop("aspect_ratio", style, |value: f32| quote!(Some(#value))); let gap = quote_object_prop("gap", style, generate_gap); @@ -525,7 +533,9 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream { let text_content = get_string_value("text_content", node); let writing_mode = get_string_value("writingMode", style); - let measure_func: Option<_> = text_content.map(|text| generate_measure_function(text, writing_mode)); + let raw_aspect_ratio = get_number_value("aspect_ratio", style); + let measure_func: Option<_> = + text_content.map(|text| generate_measure_function(text, writing_mode, raw_aspect_ratio)); edges_quoted!(style, margin, generate_length_percentage_auto, quote!(zero())); edges_quoted!(style, padding, generate_length_percentage, quote!(zero())); @@ -583,6 +593,7 @@ fn generate_node(ident: &str, node: &Value) -> TokenStream { #size #min_size #max_size + #aspect_ratio #margin #padding #inset @@ -834,9 +845,13 @@ fn generate_generic_measure_function() -> TokenStream { available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, + aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; + fn f32_max(a: f32, b: f32) -> f32 { + core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) + } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -884,23 +899,36 @@ fn generate_generic_measure_function() -> TokenStream { }); match writing_mode { - WritingMode::Horizontal => Size { width: inline_size, height: block_size }, - WritingMode::Vertical => Size { width: block_size, height: inline_size }, + WritingMode::Horizontal => Size { + width: inline_size, + // Apply aspect ratio + height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), + }, + WritingMode::Vertical => Size { + // Apply aspect ratio + width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), + height: inline_size, + }, } } ) } -fn generate_measure_function(text_content: &str, writing_mode: Option<&str>) -> TokenStream { +fn generate_measure_function(text_content: &str, writing_mode: Option<&str>, aspect_ratio: Option) -> TokenStream { let writing_mode_token = match writing_mode { Some("vertical-rl" | "vertical-lr") => quote!(super::WritingMode::Vertical), _ => quote!(super::WritingMode::Horizontal), }; + let aspect_ratio_token = match aspect_ratio { + Some(ratio) => quote!(Some(#ratio)), + None => quote!(None), + }; + quote!( taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT : &str = #text_content; - super::measure_standard_text(known_dimensions, available_space, TEXT, #writing_mode_token) + super::measure_standard_text(known_dimensions, available_space, TEXT, #writing_mode_token, #aspect_ratio_token) }) ) } diff --git a/scripts/gentest/test_helper.js b/scripts/gentest/test_helper.js index 8a75ea4f6..22d5894f0 100644 --- a/scripts/gentest/test_helper.js +++ b/scripts/gentest/test_helper.js @@ -103,6 +103,20 @@ function parseNumber(input) { return Number(input); } +function parseRatio(input) { + if (!input) return undefined + + if (input.includes('/')) { + let [width, height] = input.split("/").map(part => parseFloat(part.trim())); + if (!width || width < 0 || !height || height <= 0) return undefined; + return width / height; + } + + let ratio = parseFloat(input); + if (!ratio || ratio < 0) return undefined; + return ratio; +} + function parseEnum(input) { if (input) return input; return undefined; @@ -200,6 +214,7 @@ function describeElement(e) { size: parseSize({width: e.style.width, height: e.style.height}), minSize: parseSize({width: e.style.minWidth, height: e.style.minHeight}), maxSize: parseSize({width: e.style.maxWidth, height: e.style.maxHeight}), + aspectRatio: parseRatio(e.style.aspectRatio), margin: parseEdges({ left: e.style.marginLeft, diff --git a/tests/generated/grid_fit_content_points_argument.rs b/tests/generated/grid_fit_content_points_argument.rs index 70fb4e8a3..d2f2a80e4 100644 --- a/tests/generated/grid_fit_content_points_argument.rs +++ b/tests/generated/grid_fit_content_points_argument.rs @@ -10,7 +10,13 @@ fn grid_fit_content_points_argument() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_fit_content_points_max_content.rs b/tests/generated/grid_fit_content_points_max_content.rs index 45e84d4d0..dd4980fab 100644 --- a/tests/generated/grid_fit_content_points_max_content.rs +++ b/tests/generated/grid_fit_content_points_max_content.rs @@ -10,7 +10,13 @@ fn grid_fit_content_points_max_content() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_fit_content_points_min_content.rs b/tests/generated/grid_fit_content_points_min_content.rs index 5e9fceee4..437b8ba54 100644 --- a/tests/generated/grid_fit_content_points_min_content.rs +++ b/tests/generated/grid_fit_content_points_min_content.rs @@ -10,7 +10,13 @@ fn grid_fit_content_points_min_content() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_margins_auto_margins_override_stretch.rs b/tests/generated/grid_margins_auto_margins_override_stretch.rs index e9c129f1b..9b3484a9f 100644 --- a/tests/generated/grid_margins_auto_margins_override_stretch.rs +++ b/tests/generated/grid_margins_auto_margins_override_stretch.rs @@ -25,7 +25,13 @@ fn grid_margins_auto_margins_override_stretch() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_max_content_maximum_single_item.rs b/tests/generated/grid_max_content_maximum_single_item.rs index 016f92eb2..bfadfdd93 100644 --- a/tests/generated/grid_max_content_maximum_single_item.rs +++ b/tests/generated/grid_max_content_maximum_single_item.rs @@ -10,7 +10,13 @@ fn grid_max_content_maximum_single_item() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_max_content_single_item.rs b/tests/generated/grid_max_content_single_item.rs index b7926c016..1bcd397d7 100644 --- a/tests/generated/grid_max_content_single_item.rs +++ b/tests/generated/grid_max_content_single_item.rs @@ -10,7 +10,13 @@ fn grid_max_content_single_item() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_max_content_single_item_margin_auto.rs b/tests/generated/grid_max_content_single_item_margin_auto.rs index 854b507c2..d993eb4a8 100644 --- a/tests/generated/grid_max_content_single_item_margin_auto.rs +++ b/tests/generated/grid_max_content_single_item_margin_auto.rs @@ -18,7 +18,13 @@ fn grid_max_content_single_item_margin_auto() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_max_content_single_item_margin_fixed.rs b/tests/generated/grid_max_content_single_item_margin_fixed.rs index 51fe1346a..450c449a4 100644 --- a/tests/generated/grid_max_content_single_item_margin_fixed.rs +++ b/tests/generated/grid_max_content_single_item_margin_fixed.rs @@ -18,7 +18,13 @@ fn grid_max_content_single_item_margin_fixed() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_max_content_single_item_margin_percent.rs b/tests/generated/grid_max_content_single_item_margin_percent.rs index 7a42b8df3..8f6f57214 100644 --- a/tests/generated/grid_max_content_single_item_margin_percent.rs +++ b/tests/generated/grid_max_content_single_item_margin_percent.rs @@ -18,7 +18,13 @@ fn grid_max_content_single_item_margin_percent() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_column.rs b/tests/generated/grid_min_content_flex_column.rs index 9cd01654d..e19b39c0e 100644 --- a/tests/generated/grid_min_content_flex_column.rs +++ b/tests/generated/grid_min_content_flex_column.rs @@ -9,7 +9,13 @@ fn grid_min_content_flex_column() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -18,7 +24,13 @@ fn grid_min_content_flex_column() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -27,7 +39,13 @@ fn grid_min_content_flex_column() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_row.rs b/tests/generated/grid_min_content_flex_row.rs index 66a005699..68f65b7f0 100644 --- a/tests/generated/grid_min_content_flex_row.rs +++ b/tests/generated/grid_min_content_flex_row.rs @@ -9,7 +9,13 @@ fn grid_min_content_flex_row() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -18,7 +24,13 @@ fn grid_min_content_flex_row() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -27,7 +39,13 @@ fn grid_min_content_flex_row() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_single_item.rs b/tests/generated/grid_min_content_flex_single_item.rs index c942f782b..7401a84fa 100644 --- a/tests/generated/grid_min_content_flex_single_item.rs +++ b/tests/generated/grid_min_content_flex_single_item.rs @@ -24,7 +24,13 @@ fn grid_min_content_flex_single_item() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_single_item_margin_auto.rs b/tests/generated/grid_min_content_flex_single_item_margin_auto.rs index f77d88d4c..d7a7a3b7a 100644 --- a/tests/generated/grid_min_content_flex_single_item_margin_auto.rs +++ b/tests/generated/grid_min_content_flex_single_item_margin_auto.rs @@ -36,7 +36,13 @@ fn grid_min_content_flex_single_item_margin_auto() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_single_item_margin_fixed.rs b/tests/generated/grid_min_content_flex_single_item_margin_fixed.rs index 47d7cd1b3..b675dc335 100644 --- a/tests/generated/grid_min_content_flex_single_item_margin_fixed.rs +++ b/tests/generated/grid_min_content_flex_single_item_margin_fixed.rs @@ -36,7 +36,13 @@ fn grid_min_content_flex_single_item_margin_fixed() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_flex_single_item_margin_percent.rs b/tests/generated/grid_min_content_flex_single_item_margin_percent.rs index e353b5932..1328c61de 100644 --- a/tests/generated/grid_min_content_flex_single_item_margin_percent.rs +++ b/tests/generated/grid_min_content_flex_single_item_margin_percent.rs @@ -36,7 +36,13 @@ fn grid_min_content_flex_single_item_margin_percent() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_maximum_single_item.rs b/tests/generated/grid_min_content_maximum_single_item.rs index 9b4eb821f..c3bf75ff0 100644 --- a/tests/generated/grid_min_content_maximum_single_item.rs +++ b/tests/generated/grid_min_content_maximum_single_item.rs @@ -10,7 +10,13 @@ fn grid_min_content_maximum_single_item() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_min_content_single_item.rs b/tests/generated/grid_min_content_single_item.rs index 628462049..0bec76a5b 100644 --- a/tests/generated/grid_min_content_single_item.rs +++ b/tests/generated/grid_min_content_single_item.rs @@ -10,7 +10,13 @@ fn grid_min_content_single_item() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_relayout_vertical_text.rs b/tests/generated/grid_relayout_vertical_text.rs index 5e56b42ad..ce46aa687 100644 --- a/tests/generated/grid_relayout_vertical_text.rs +++ b/tests/generated/grid_relayout_vertical_text.rs @@ -9,7 +9,13 @@ fn grid_relayout_vertical_text() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Vertical) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + None, + ) }), ) .unwrap(); @@ -18,7 +24,13 @@ fn grid_relayout_vertical_text() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/grid_size_child_fixed_tracks.rs b/tests/generated/grid_size_child_fixed_tracks.rs index 4b9604d84..3f66a0767 100644 --- a/tests/generated/grid_size_child_fixed_tracks.rs +++ b/tests/generated/grid_size_child_fixed_tracks.rs @@ -13,7 +13,13 @@ fn grid_size_child_fixed_tracks() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -26,7 +32,13 @@ fn grid_size_child_fixed_tracks() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHH\u{200b}HHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -39,7 +51,13 @@ fn grid_size_child_fixed_tracks() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -53,7 +71,13 @@ fn grid_size_child_fixed_tracks() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); @@ -67,7 +91,13 @@ fn grid_size_child_fixed_tracks() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_child.rs b/tests/generated/measure_child.rs index 0e6214615..ac143afae 100644 --- a/tests/generated/measure_child.rs +++ b/tests/generated/measure_child.rs @@ -9,7 +9,13 @@ fn measure_child() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_child_absolute.rs b/tests/generated/measure_child_absolute.rs index 9f15cc4fc..c46619328 100644 --- a/tests/generated/measure_child_absolute.rs +++ b/tests/generated/measure_child_absolute.rs @@ -9,7 +9,13 @@ fn measure_child_absolute() { taffy::style::Style { position: taffy::style::Position::Absolute, ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_child_constraint.rs b/tests/generated/measure_child_constraint.rs index 6b445402a..87752dd90 100644 --- a/tests/generated/measure_child_constraint.rs +++ b/tests/generated/measure_child_constraint.rs @@ -4,7 +4,7 @@ fn measure_child_constraint() { #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; let mut taffy = taffy::Taffy::new(); - let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal) }) ,) . unwrap () ; + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , None) }) ,) . unwrap () ; let node = taffy .new_with_children( taffy::style::Style { diff --git a/tests/generated/measure_child_constraint_padding_parent.rs b/tests/generated/measure_child_constraint_padding_parent.rs index 5dc3c0d42..3980c91e0 100644 --- a/tests/generated/measure_child_constraint_padding_parent.rs +++ b/tests/generated/measure_child_constraint_padding_parent.rs @@ -4,7 +4,7 @@ fn measure_child_constraint_padding_parent() { #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; let mut taffy = taffy::Taffy::new(); - let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal) }) ,) . unwrap () ; + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , None) }) ,) . unwrap () ; let node = taffy .new_with_children( taffy::style::Style { diff --git a/tests/generated/measure_child_with_flex_grow.rs b/tests/generated/measure_child_with_flex_grow.rs index 90e186806..332611386 100644 --- a/tests/generated/measure_child_with_flex_grow.rs +++ b/tests/generated/measure_child_with_flex_grow.rs @@ -18,7 +18,13 @@ fn measure_child_with_flex_grow() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H\u{200b}H\u{200b}H\u{200b}H\u{200b}H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_child_with_flex_shrink.rs b/tests/generated/measure_child_with_flex_shrink.rs index a3787c73f..f14bc3ab7 100644 --- a/tests/generated/measure_child_with_flex_shrink.rs +++ b/tests/generated/measure_child_with_flex_shrink.rs @@ -18,7 +18,13 @@ fn measure_child_with_flex_shrink() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH\u{200b}HHHHHHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_flex_basis_overrides_measure.rs b/tests/generated/measure_flex_basis_overrides_measure.rs index 8b9f9461e..b5735ce07 100644 --- a/tests/generated/measure_flex_basis_overrides_measure.rs +++ b/tests/generated/measure_flex_basis_overrides_measure.rs @@ -9,7 +9,13 @@ fn measure_flex_basis_overrides_measure() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_height_overrides_measure.rs b/tests/generated/measure_height_overrides_measure.rs index fba584fab..5a2bae1ab 100644 --- a/tests/generated/measure_height_overrides_measure.rs +++ b/tests/generated/measure_height_overrides_measure.rs @@ -12,7 +12,13 @@ fn measure_height_overrides_measure() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_remeasure_child_after_growing.rs b/tests/generated/measure_remeasure_child_after_growing.rs index 75713f3b9..13e23cc33 100644 --- a/tests/generated/measure_remeasure_child_after_growing.rs +++ b/tests/generated/measure_remeasure_child_after_growing.rs @@ -18,7 +18,13 @@ fn measure_remeasure_child_after_growing() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_remeasure_child_after_shrinking.rs b/tests/generated/measure_remeasure_child_after_shrinking.rs index 24265d2c6..51a04defa 100644 --- a/tests/generated/measure_remeasure_child_after_shrinking.rs +++ b/tests/generated/measure_remeasure_child_after_shrinking.rs @@ -19,7 +19,13 @@ fn measure_remeasure_child_after_shrinking() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_remeasure_child_after_stretching.rs b/tests/generated/measure_remeasure_child_after_stretching.rs index f381f437a..8dc16c090 100644 --- a/tests/generated/measure_remeasure_child_after_stretching.rs +++ b/tests/generated/measure_remeasure_child_after_stretching.rs @@ -9,7 +9,13 @@ fn measure_remeasure_child_after_stretching() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_root.rs b/tests/generated/measure_root.rs index a7c72dd8d..011887af4 100644 --- a/tests/generated/measure_root.rs +++ b/tests/generated/measure_root.rs @@ -9,7 +9,13 @@ fn measure_root() { taffy::style::Style { ..Default::default() }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_stretch_overrides_measure.rs b/tests/generated/measure_stretch_overrides_measure.rs index b4a0ce571..05961e1cd 100644 --- a/tests/generated/measure_stretch_overrides_measure.rs +++ b/tests/generated/measure_stretch_overrides_measure.rs @@ -20,7 +20,13 @@ fn measure_stretch_overrides_measure() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "H"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/measure_width_overrides_measure.rs b/tests/generated/measure_width_overrides_measure.rs index ce224ec80..73cc15abe 100644 --- a/tests/generated/measure_width_overrides_measure.rs +++ b/tests/generated/measure_width_overrides_measure.rs @@ -12,7 +12,13 @@ fn measure_width_overrides_measure() { }, taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { const TEXT: &str = "HHHHHHHHHH"; - super::measure_standard_text(known_dimensions, available_space, TEXT, super::WritingMode::Horizontal) + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + None, + ) }), ) .unwrap(); diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 965ebe5e9..50ecc5235 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -10,9 +10,13 @@ fn measure_standard_text( available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, + aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; + fn f32_max(a: f32, b: f32) -> f32 { + core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) + } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -55,8 +59,14 @@ fn measure_standard_text( (line_count as f32) * H_HEIGHT }); match writing_mode { - WritingMode::Horizontal => Size { width: inline_size, height: block_size }, - WritingMode::Vertical => Size { width: block_size, height: inline_size }, + WritingMode::Horizontal => Size { + width: inline_size, + height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), + }, + WritingMode::Vertical => Size { + width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), + height: inline_size, + }, } } mod absolute_layout_align_items_and_justify_content_center; From 2801c19af7f9aec2e5ae049a3731683014f3cf20 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 14:08:07 +0000 Subject: [PATCH 02/40] Add maybe_apply_aspect_ratio helper to Size> --- src/geometry.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/geometry.rs b/src/geometry.rs index 0d1590b64..d0b187f7e 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -365,6 +365,22 @@ impl Size> { pub const fn new(width: f32, height: f32) -> Self { Size { width: Some(width), height: Some(height) } } + + /// Applies aspect_ratio (if one is supplied) to the Size: + /// - If width is `Some` but height is `None`, then height is computed from width and aspect_ratio + /// - If height is `Some` but width is `None`, then width is computed from width and aspect_ratio + /// + /// If aspect_ratio is `None` then this function simply returns self. + pub fn maybe_apply_aspect_ratio(self, aspect_ratio: Option) -> Size> { + match aspect_ratio { + Some(ratio) => match (self.width, self.height) { + (Some(width), None) => Size { width: Some(width), height: Some(width / ratio) }, + (None, Some(height)) => Size { width: Some(height * ratio), height: Some(height) }, + _ => self, + }, + None => self, + } + } } impl Size> { From 1dea4d02219b6c3943abb89603a6c7ad1cf418db Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 14:13:06 +0000 Subject: [PATCH 03/40] Apply aspect ratio to leaf node style resolution --- src/compute/leaf.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compute/leaf.rs b/src/compute/leaf.rs index 4b06360a0..78a0679d2 100644 --- a/src/compute/leaf.rs +++ b/src/compute/leaf.rs @@ -33,11 +33,13 @@ pub(crate) fn compute( (node_size, node_min_size, node_max_size) } SizingMode::InherentSize => { - let style_size = style.size.maybe_resolve(parent_size); + let aspect_ratio = style.aspect_ratio; + let style_size = style.size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let style_min_size = style.min_size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let style_max_size = style.max_size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let node_size = known_dimensions.or(style_size); - let node_min_size = style.min_size.maybe_resolve(parent_size); - let node_max_size = style.max_size.maybe_resolve(parent_size); - (node_size, node_min_size, node_max_size) + (node_size, style_min_size, style_max_size) } }; From fd88cf43c477f395648c9f30f5c52c2fce91c334 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 14:13:26 +0000 Subject: [PATCH 04/40] Apply aspect ratio when doing final placement of grid items --- src/compute/grid/alignment.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compute/grid/alignment.rs b/src/compute/grid/alignment.rs index 44e377c87..d645cf671 100644 --- a/src/compute/grid/alignment.rs +++ b/src/compute/grid/alignment.rs @@ -87,14 +87,17 @@ pub(super) fn align_and_position_item( let position = style.position; let inset_horizontal = style.inset.horizontal_components().map(|size| size.resolve_to_option(grid_area_size.width)); let inset_vertical = style.inset.vertical_components().map(|size| size.resolve_to_option(grid_area_size.height)); - let inherent_size = style.size.maybe_resolve(grid_area_size); - let min_size = style.min_size.maybe_resolve(grid_area_size); - let max_size = style.max_size.maybe_resolve(grid_area_size); + let inherent_size = style.size.maybe_resolve(grid_area_size).maybe_apply_aspect_ratio(aspect_ratio); + let min_size = style.min_size.maybe_resolve(grid_area_size).maybe_apply_aspect_ratio(aspect_ratio); + let max_size = style.max_size.maybe_resolve(grid_area_size).maybe_apply_aspect_ratio(aspect_ratio); // Resolve default alignment styles if they are set on neither the parent or the node itself + // Note: if the child has a preferred aspect ratio but neither width or height are set, then the width is stretched + // and the then height is calculated from the width according the aspect ratio + // See: https://www.w3.org/TR/css-grid-1/#grid-item-sizing let alignment_styles = InBothAbsAxis { horizontal: container_alignment_styles.horizontal.or(justify_self).unwrap_or_else(|| { - if inherent_size.width.is_some() || aspect_ratio.is_some() { + if inherent_size.width.is_some() { AlignSelf::Start } else { AlignSelf::Stretch @@ -166,6 +169,9 @@ pub(super) fn align_and_position_item( None }); + // Reapply aspect ratio after stretch and absolute position adjustments + let Size { width, height } = Size { width, height }.maybe_apply_aspect_ratio(aspect_ratio); + // Layout node let measured_size = compute_node_layout( tree, From da30c98d8f63aac2ec78f3069374fd4aacdcf72e Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 14:58:12 +0000 Subject: [PATCH 05/40] Make cargo gentest compile generator in release mode --- .cargo/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 7e669f119..52ecae305 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -gentest = "run --package gentest --" \ No newline at end of file +gentest = "run --release --package gentest --" \ No newline at end of file From cd7a5630cdebee14f8acf56bfd60b78702405461 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 13:50:21 +0000 Subject: [PATCH 06/40] Add tests for aspect ratio of leaf nodes in grid containers --- .../aspect_ratio_leaf_fill_height.rs | 26 +++++++++ .../aspect_ratio_leaf_fill_max_height.rs | 38 +++++++++++++ .../aspect_ratio_leaf_fill_max_width.rs | 38 +++++++++++++ .../aspect_ratio_leaf_fill_min_height.rs | 26 +++++++++ .../aspect_ratio_leaf_fill_min_width.rs | 38 +++++++++++++ .../generated/aspect_ratio_leaf_fill_width.rs | 26 +++++++++ ..._ratio_leaf_overriden_by_explicit_sizes.rs | 29 ++++++++++ benches/generated/mod.rs | 14 +++++ .../aspect_ratio_leaf_fill_height.html | 17 ++++++ .../aspect_ratio_leaf_fill_max_height.html | 17 ++++++ .../aspect_ratio_leaf_fill_max_width.html | 17 ++++++ .../aspect_ratio_leaf_fill_min_height.html | 17 ++++++ .../aspect_ratio_leaf_fill_min_width.html | 19 +++++++ .../aspect_ratio_leaf_fill_width.html | 17 ++++++ ...atio_leaf_overriden_by_explicit_sizes.html | 17 ++++++ ...ect_ratio_leaf_fill_min_width_percent.html | 19 +++++++ .../aspect_ratio_leaf_fill_height.rs | 41 ++++++++++++++ .../aspect_ratio_leaf_fill_max_height.rs | 53 +++++++++++++++++++ .../aspect_ratio_leaf_fill_max_width.rs | 53 +++++++++++++++++++ .../aspect_ratio_leaf_fill_min_height.rs | 41 ++++++++++++++ .../aspect_ratio_leaf_fill_min_width.rs | 53 +++++++++++++++++++ .../generated/aspect_ratio_leaf_fill_width.rs | 41 ++++++++++++++ ..._ratio_leaf_overriden_by_explicit_sizes.rs | 44 +++++++++++++++ tests/generated/mod.rs | 7 +++ 24 files changed, 708 insertions(+) create mode 100644 benches/generated/aspect_ratio_leaf_fill_height.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_max_height.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_max_width.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_min_height.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_min_width.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_width.rs create mode 100644 benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs create mode 100644 test_fixtures/aspect_ratio_leaf_fill_height.html create mode 100644 test_fixtures/aspect_ratio_leaf_fill_max_height.html create mode 100644 test_fixtures/aspect_ratio_leaf_fill_max_width.html create mode 100644 test_fixtures/aspect_ratio_leaf_fill_min_height.html create mode 100644 test_fixtures/aspect_ratio_leaf_fill_min_width.html create mode 100644 test_fixtures/aspect_ratio_leaf_fill_width.html create mode 100644 test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html create mode 100644 test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html create mode 100644 tests/generated/aspect_ratio_leaf_fill_height.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_max_height.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_max_width.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_min_height.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_min_width.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_width.rs create mode 100644 tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_height.rs b/benches/generated/aspect_ratio_leaf_fill_height.rs new file mode 100644 index 000000000..b90024157 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_height.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_max_height.rs b/benches/generated/aspect_ratio_leaf_fill_max_height.rs new file mode 100644 index 000000000..172dcb9ee --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_max_height.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_max_width.rs b/benches/generated/aspect_ratio_leaf_fill_max_width.rs new file mode 100644 index 000000000..830cc29f4 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_max_width.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_min_height.rs b/benches/generated/aspect_ratio_leaf_fill_min_height.rs new file mode 100644 index 000000000..819186737 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_min_height.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_min_width.rs b/benches/generated/aspect_ratio_leaf_fill_min_width.rs new file mode 100644 index 000000000..0df0c51d7 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_min_width.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_width.rs b/benches/generated/aspect_ratio_leaf_fill_width.rs new file mode 100644 index 000000000..4f801930b --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_width.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs b/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs new file mode 100644 index 000000000..39ed71ce2 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs @@ -0,0 +1,29 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 946885629..ac41d0067 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -121,6 +121,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_leaf_fill_height; +mod aspect_ratio_leaf_fill_max_height; +mod aspect_ratio_leaf_fill_max_width; +mod aspect_ratio_leaf_fill_min_height; +mod aspect_ratio_leaf_fill_min_width; +mod aspect_ratio_leaf_fill_width; +mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod border_center_child; mod border_flex_child; mod border_no_child; @@ -645,6 +652,13 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); + aspect_ratio_leaf_fill_height::compute(); + aspect_ratio_leaf_fill_max_height::compute(); + aspect_ratio_leaf_fill_max_width::compute(); + aspect_ratio_leaf_fill_min_height::compute(); + aspect_ratio_leaf_fill_min_width::compute(); + aspect_ratio_leaf_fill_width::compute(); + aspect_ratio_leaf_overriden_by_explicit_sizes::compute(); border_center_child::compute(); border_flex_child::compute(); border_no_child::compute(); diff --git a/test_fixtures/aspect_ratio_leaf_fill_height.html b/test_fixtures/aspect_ratio_leaf_fill_height.html new file mode 100644 index 000000000..c0e301774 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_fill_max_height.html b/test_fixtures/aspect_ratio_leaf_fill_max_height.html new file mode 100644 index 000000000..6abb462d4 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_fill_max_width.html b/test_fixtures/aspect_ratio_leaf_fill_max_width.html new file mode 100644 index 000000000..d6ebcf5d7 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_fill_min_height.html b/test_fixtures/aspect_ratio_leaf_fill_min_height.html new file mode 100644 index 000000000..908d5907f --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_fill_min_width.html b/test_fixtures/aspect_ratio_leaf_fill_min_width.html new file mode 100644 index 000000000..2a30c8f10 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_min_width.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_fill_width.html b/test_fixtures/aspect_ratio_leaf_fill_width.html new file mode 100644 index 000000000..37acb9990 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html b/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html new file mode 100644 index 000000000..f01c566e0 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html b/test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html new file mode 100644 index 000000000..152bd75b8 --- /dev/null +++ b/test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_leaf_fill_height.rs b/tests/generated/aspect_ratio_leaf_fill_height.rs new file mode 100644 index 000000000..b9659d606 --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_height.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_leaf_fill_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 25f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 25f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_max_height.rs b/tests/generated/aspect_ratio_leaf_fill_max_height.rs new file mode 100644 index 000000000..0a182eebe --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_max_height.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_leaf_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_max_width.rs b/tests/generated/aspect_ratio_leaf_fill_max_width.rs new file mode 100644 index 000000000..1ba057b6c --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_max_width.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_leaf_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_min_height.rs b/tests/generated/aspect_ratio_leaf_fill_min_height.rs new file mode 100644 index 000000000..0eefa4b52 --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_min_height.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_leaf_fill_min_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_min_width.rs b/tests/generated/aspect_ratio_leaf_fill_min_width.rs new file mode 100644 index 000000000..d005e4df0 --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_min_width.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_leaf_fill_min_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_width.rs b/tests/generated/aspect_ratio_leaf_fill_width.rs new file mode 100644 index 000000000..231de24fb --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_width.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_leaf_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs b/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs new file mode 100644 index 000000000..e42d61516 --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs @@ -0,0 +1,44 @@ +#[test] +fn aspect_ratio_leaf_overriden_by_explicit_sizes() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 50ecc5235..491e9934a 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -120,6 +120,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_leaf_fill_height; +mod aspect_ratio_leaf_fill_max_height; +mod aspect_ratio_leaf_fill_max_width; +mod aspect_ratio_leaf_fill_min_height; +mod aspect_ratio_leaf_fill_min_width; +mod aspect_ratio_leaf_fill_width; +mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod border_center_child; mod border_flex_child; mod border_no_child; From d74c903872bac36aad52e7fe55394922b76dcf4f Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 17:05:53 +0000 Subject: [PATCH 07/40] Apply aspect ratio to grid container styles --- src/compute/grid/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compute/grid/mod.rs b/src/compute/grid/mod.rs index 529dadaff..daa4cd6fc 100644 --- a/src/compute/grid/mod.rs +++ b/src/compute/grid/mod.rs @@ -105,9 +105,10 @@ pub fn compute( let padding = style.padding.resolve_or_zero(parent_size.width); let border = style.border.resolve_or_zero(parent_size.width); let margin = style.margin.resolve_or_zero(parent_size.width); - let min_size = style.min_size.maybe_resolve(parent_size); - let max_size = style.max_size.maybe_resolve(parent_size); - let size = style.size.maybe_resolve(parent_size); + let aspect_ratio = style.aspect_ratio; + let min_size = style.min_size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let max_size = style.max_size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let size = style.size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); let constrained_available_space = size .maybe_clamp(min_size, max_size) From 796cf13d80b508364d88464f7c9ae65490c54b03 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 17:13:40 +0000 Subject: [PATCH 08/40] Apply aspect ratio to automatic minimum size --- src/compute/grid/types/grid_item.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compute/grid/types/grid_item.rs b/src/compute/grid/types/grid_item.rs index b38d84b15..fcd76cd41 100644 --- a/src/compute/grid/types/grid_item.rs +++ b/src/compute/grid/types/grid_item.rs @@ -241,12 +241,18 @@ impl GridItem { ) -> f32 { self.minimum_contribution_cache.unwrap_or_else(|| { let style = tree.style(self.node); - let axis_available_space = available_space.get(axis).into_option(); style .size + .maybe_resolve(available_space.into_options()) + .maybe_apply_aspect_ratio(style.aspect_ratio) .get(axis) - .maybe_resolve(axis_available_space) - .or_else(|| style.min_size.get(axis).maybe_resolve(axis_available_space)) + .or_else(|| { + style + .min_size + .maybe_resolve(available_space.into_options()) + .maybe_apply_aspect_ratio(style.aspect_ratio) + .get(axis) + }) .unwrap_or_else(|| { // Automatic minimum size. See https://www.w3.org/TR/css-grid-1/#min-size-auto From fd57d843685e4910c4bfa4101f70510a96ec3523 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 17:15:37 +0000 Subject: [PATCH 09/40] Add tests for aspect ratio of content-sized leaf nodes --- ...ct_ratio_grid_child_fill_content_height.rs | 33 ++++++++++++ ...ect_ratio_grid_child_fill_content_width.rs | 33 ++++++++++++ benches/generated/mod.rs | 4 ++ ..._ratio_grid_child_fill_content_height.html | 18 +++++++ ...t_ratio_grid_child_fill_content_width.html | 18 +++++++ ...ct_ratio_grid_child_fill_content_height.rs | 53 +++++++++++++++++++ ...ect_ratio_grid_child_fill_content_width.rs | 53 +++++++++++++++++++ tests/generated/mod.rs | 2 + 8 files changed, 214 insertions(+) create mode 100644 benches/generated/aspect_ratio_grid_child_fill_content_height.rs create mode 100644 benches/generated/aspect_ratio_grid_child_fill_content_width.rs create mode 100644 test_fixtures/aspect_ratio_grid_child_fill_content_height.html create mode 100644 test_fixtures/aspect_ratio_grid_child_fill_content_width.html create mode 100644 tests/generated/aspect_ratio_grid_child_fill_content_height.rs create mode 100644 tests/generated/aspect_ratio_grid_child_fill_content_width.rs diff --git a/benches/generated/aspect_ratio_grid_child_fill_content_height.rs b/benches/generated/aspect_ratio_grid_child_fill_content_height.rs new file mode 100644 index 000000000..12523c8b9 --- /dev/null +++ b/benches/generated/aspect_ratio_grid_child_fill_content_height.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { aspect_ratio: Some(0.5f32), ..Default::default() }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HHHH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(0.5f32), + ) + }), + ) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Grid, ..Default::default() }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_grid_child_fill_content_width.rs b/benches/generated/aspect_ratio_grid_child_fill_content_width.rs new file mode 100644 index 000000000..d3dfc577c --- /dev/null +++ b/benches/generated/aspect_ratio_grid_child_fill_content_width.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { aspect_ratio: Some(2f32), ..Default::default() }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HHHH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + Some(2f32), + ) + }), + ) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Grid, ..Default::default() }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index ac41d0067..26428bc4e 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -121,6 +121,8 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_grid_child_fill_content_height; +mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; @@ -652,6 +654,8 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); + aspect_ratio_grid_child_fill_content_height::compute(); + aspect_ratio_grid_child_fill_content_width::compute(); aspect_ratio_leaf_fill_height::compute(); aspect_ratio_leaf_fill_max_height::compute(); aspect_ratio_leaf_fill_max_width::compute(); diff --git a/test_fixtures/aspect_ratio_grid_child_fill_content_height.html b/test_fixtures/aspect_ratio_grid_child_fill_content_height.html new file mode 100644 index 000000000..d914fd152 --- /dev/null +++ b/test_fixtures/aspect_ratio_grid_child_fill_content_height.html @@ -0,0 +1,18 @@ + + + + + + + Test description + + + + +
+
HHHH
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_grid_child_fill_content_width.html b/test_fixtures/aspect_ratio_grid_child_fill_content_width.html new file mode 100644 index 000000000..913574b4c --- /dev/null +++ b/test_fixtures/aspect_ratio_grid_child_fill_content_width.html @@ -0,0 +1,18 @@ + + + + + + + Test description + + + + +
+
HHHH
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_grid_child_fill_content_height.rs b/tests/generated/aspect_ratio_grid_child_fill_content_height.rs new file mode 100644 index 000000000..5f974ceb9 --- /dev/null +++ b/tests/generated/aspect_ratio_grid_child_fill_content_height.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_grid_child_fill_content_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { aspect_ratio: Some(0.5f32), ..Default::default() }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HHHH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(0.5f32), + ) + }), + ) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Grid, ..Default::default() }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 80f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x); + assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, location.y); +} diff --git a/tests/generated/aspect_ratio_grid_child_fill_content_width.rs b/tests/generated/aspect_ratio_grid_child_fill_content_width.rs new file mode 100644 index 000000000..27722c407 --- /dev/null +++ b/tests/generated/aspect_ratio_grid_child_fill_content_width.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_grid_child_fill_content_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { aspect_ratio: Some(2f32), ..Default::default() }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HHHH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Vertical, + Some(2f32), + ) + }), + ) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { display: taffy::style::Display::Grid, ..Default::default() }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x); + assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 491e9934a..9ea186bb0 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -120,6 +120,8 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_grid_child_fill_content_height; +mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; From fbc92dce6600ecd92951a0d0d7d199ee628ff420 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 17:41:39 +0000 Subject: [PATCH 10/40] Use main size for flex-basis if flex-basis is not set --- src/compute/flexbox.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 185deb233..9820da59c 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -553,8 +553,9 @@ fn determine_flex_base_size( // A. If the item has a definite used flex basis, that’s the flex base size. let flex_basis = child_style.flex_basis.maybe_resolve(constants.node_inner_size.main(constants.dir)); - if flex_basis.is_some() { - child.flex_basis = flex_basis.unwrap_or(0.0); + let main_size = child_style.size.maybe_resolve(constants.node_inner_size).main(constants.dir); + if let Some(flex_basis) = flex_basis.or(main_size) { + child.flex_basis = flex_basis; continue; }; From 807624efeb8d6d2ba82d2a218539796610bd3e3d Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 18:35:40 +0000 Subject: [PATCH 11/40] Resolve size, min_size, max_size against aspect ratio when generating flex items --- src/compute/flexbox.rs | 88 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 9820da59c..fc684cf09 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -208,7 +208,7 @@ fn compute_preliminary( // 3. Determine the flex base size and hypothetical main size of each item. #[cfg(feature = "debug")] NODE_LOGGER.log("determine_flex_base_size"); - determine_flex_base_size(tree, known_dimensions, &constants, available_space, &mut flex_items); + determine_flex_base_size(tree, &constants, available_space, &mut flex_items); #[cfg(feature = "debug")] for item in flex_items.iter() { @@ -446,32 +446,41 @@ fn generate_anonymous_flex_items(tree: &impl LayoutTree, node: Node, constants: .map(|child| (child, tree.style(*child))) .filter(|(_, style)| style.position != Position::Absolute) .filter(|(_, style)| style.display != Display::None) - .map(|(child, child_style)| FlexItem { - node: *child, - size: child_style.size.maybe_resolve(constants.node_inner_size), - min_size: child_style.min_size.maybe_resolve(constants.node_inner_size), - max_size: child_style.max_size.maybe_resolve(constants.node_inner_size), - - inset: child_style.inset.zip_size(constants.node_inner_size, |p, s| p.maybe_resolve(s)), - margin: child_style.margin.resolve_or_zero(constants.node_inner_size.width), - padding: child_style.padding.resolve_or_zero(constants.node_inner_size.width), - border: child_style.border.resolve_or_zero(constants.node_inner_size.width), - align_self: child_style.align_self.unwrap_or(constants.align_items), - flex_basis: 0.0, - inner_flex_basis: 0.0, - violation: 0.0, - frozen: false, - - resolved_minimum_size: Size::zero(), - hypothetical_inner_size: Size::zero(), - hypothetical_outer_size: Size::zero(), - target_size: Size::zero(), - outer_target_size: Size::zero(), - - baseline: 0.0, - - offset_main: 0.0, - offset_cross: 0.0, + .map(|(child, child_style)| { + let aspect_ratio = child_style.aspect_ratio; + FlexItem { + node: *child, + size: child_style.size.maybe_resolve(constants.node_inner_size).maybe_apply_aspect_ratio(aspect_ratio), + min_size: child_style + .min_size + .maybe_resolve(constants.node_inner_size) + .maybe_apply_aspect_ratio(aspect_ratio), + max_size: child_style + .max_size + .maybe_resolve(constants.node_inner_size) + .maybe_apply_aspect_ratio(aspect_ratio), + + inset: child_style.inset.zip_size(constants.node_inner_size, |p, s| p.maybe_resolve(s)), + margin: child_style.margin.resolve_or_zero(constants.node_inner_size.width), + padding: child_style.padding.resolve_or_zero(constants.node_inner_size.width), + border: child_style.border.resolve_or_zero(constants.node_inner_size.width), + align_self: child_style.align_self.unwrap_or(constants.align_items), + flex_basis: 0.0, + inner_flex_basis: 0.0, + violation: 0.0, + frozen: false, + + resolved_minimum_size: Size::zero(), + hypothetical_inner_size: Size::zero(), + hypothetical_outer_size: Size::zero(), + target_size: Size::zero(), + outer_target_size: Size::zero(), + + baseline: 0.0, + + offset_main: 0.0, + offset_cross: 0.0, + } }) .collect() } @@ -541,7 +550,6 @@ fn determine_available_space( #[inline] fn determine_flex_base_size( tree: &mut impl LayoutTree, - node_size: Size>, constants: &AlgoConstants, available_space: Size, flex_items: &mut Vec, @@ -552,26 +560,20 @@ fn determine_flex_base_size( // A. If the item has a definite used flex basis, that’s the flex base size. - let flex_basis = child_style.flex_basis.maybe_resolve(constants.node_inner_size.main(constants.dir)); - let main_size = child_style.size.maybe_resolve(constants.node_inner_size).main(constants.dir); - if let Some(flex_basis) = flex_basis.or(main_size) { - child.flex_basis = flex_basis; - continue; - }; - // B. If the flex item has an intrinsic aspect ratio, // a used flex basis of content, and a definite cross size, // then the flex base size is calculated from its inner // cross size and the flex item’s intrinsic aspect ratio. - if let Some(ratio) = child_style.aspect_ratio { - if let Some(cross) = node_size.cross(constants.dir) { - if child_style.flex_basis == Dimension::Auto { - child.flex_basis = cross * ratio; - continue; - } - } - } + // Note: `child.size` has already been resolved against aspect_ratio in generate_anonymous_flex_items + // So B will just work here by using main_size without special handling for aspect_ratio + + let flex_basis = child_style.flex_basis.maybe_resolve(constants.node_inner_size.main(constants.dir)); + let main_size = child.size.main(constants.dir); + if let Some(flex_basis) = flex_basis.or(main_size) { + child.flex_basis = flex_basis; + continue; + }; // C. If the used flex basis is content or depends on its available space, // and the flex container is being sized under a min-content or max-content From b2f0905f884383e848de0a17c60bb377bd197f3c Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 18:37:34 +0000 Subject: [PATCH 12/40] Add gentests for aspect-ratio in flex-row (align-start) --- .../aspect_ratio_flex_leaf_fill_height.rs | 27 ++++++++++ .../aspect_ratio_flex_leaf_fill_max_height.rs | 21 ++++++++ .../aspect_ratio_flex_leaf_fill_max_width.rs | 39 ++++++++++++++ .../aspect_ratio_flex_leaf_fill_min_height.rs | 27 ++++++++++ .../aspect_ratio_flex_leaf_fill_min_width.rs | 39 ++++++++++++++ .../aspect_ratio_flex_leaf_fill_width.rs | 27 ++++++++++ .../aspect_ratio_flex_leaf_fill_width_flex.rs | 26 +++++++++ ...o_leaf_overriden_by_explicit_sizes_flex.rs | 29 ++++++++++ benches/generated/mod.rs | 16 ++++++ .../aspect_ratio_flex_leaf_fill_height.html | 17 ++++++ ...spect_ratio_flex_leaf_fill_max_height.html | 17 ++++++ ...aspect_ratio_flex_leaf_fill_max_width.html | 17 ++++++ ...spect_ratio_flex_leaf_fill_min_height.html | 17 ++++++ ...aspect_ratio_flex_leaf_fill_min_width.html | 19 +++++++ .../aspect_ratio_flex_leaf_fill_width.html | 17 ++++++ ...spect_ratio_flex_leaf_fill_width_flex.html | 17 ++++++ ...leaf_overriden_by_explicit_sizes_flex.html | 17 ++++++ .../aspect_ratio_flex_leaf_fill_height.rs | 42 +++++++++++++++ .../aspect_ratio_flex_leaf_fill_max_height.rs | 36 +++++++++++++ .../aspect_ratio_flex_leaf_fill_max_width.rs | 54 +++++++++++++++++++ .../aspect_ratio_flex_leaf_fill_min_height.rs | 42 +++++++++++++++ .../aspect_ratio_flex_leaf_fill_min_width.rs | 54 +++++++++++++++++++ .../aspect_ratio_flex_leaf_fill_width.rs | 42 +++++++++++++++ .../aspect_ratio_flex_leaf_fill_width_flex.rs | 41 ++++++++++++++ ...o_leaf_overriden_by_explicit_sizes_flex.rs | 44 +++++++++++++++ tests/generated/mod.rs | 8 +++ 26 files changed, 752 insertions(+) create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_height.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_width.rs create mode 100644 benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs create mode 100644 benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_height.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_width.html create mode 100644 test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html create mode 100644 test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_height.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_width.rs create mode 100644 tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs create mode 100644 tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_height.rs b/benches/generated/aspect_ratio_flex_leaf_fill_height.rs new file mode 100644 index 000000000..fa97a2080 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_height.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs b/benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs new file mode 100644 index 000000000..809e0e909 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs @@ -0,0 +1,21 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs b/benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs new file mode 100644 index 000000000..8a9ef2899 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs @@ -0,0 +1,39 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs b/benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs new file mode 100644 index 000000000..5f71ff244 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs b/benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs new file mode 100644 index 000000000..877da1c41 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs @@ -0,0 +1,39 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_width.rs b/benches/generated/aspect_ratio_flex_leaf_fill_width.rs new file mode 100644 index 000000000..5859b0756 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_width.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs b/benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs new file mode 100644 index 000000000..4f801930b --- /dev/null +++ b/benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs b/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs new file mode 100644 index 000000000..39ed71ce2 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs @@ -0,0 +1,29 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 26428bc4e..78fa94c45 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -121,6 +121,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_flex_leaf_fill_height; +mod aspect_ratio_flex_leaf_fill_max_height; +mod aspect_ratio_flex_leaf_fill_max_width; +mod aspect_ratio_flex_leaf_fill_min_height; +mod aspect_ratio_flex_leaf_fill_min_width; +mod aspect_ratio_flex_leaf_fill_width; +mod aspect_ratio_flex_leaf_fill_width_flex; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; @@ -130,6 +137,7 @@ mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; +mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; mod border_center_child; mod border_flex_child; mod border_no_child; @@ -654,6 +662,13 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); + aspect_ratio_flex_leaf_fill_height::compute(); + aspect_ratio_flex_leaf_fill_max_height::compute(); + aspect_ratio_flex_leaf_fill_max_width::compute(); + aspect_ratio_flex_leaf_fill_min_height::compute(); + aspect_ratio_flex_leaf_fill_min_width::compute(); + aspect_ratio_flex_leaf_fill_width::compute(); + aspect_ratio_flex_leaf_fill_width_flex::compute(); aspect_ratio_grid_child_fill_content_height::compute(); aspect_ratio_grid_child_fill_content_width::compute(); aspect_ratio_leaf_fill_height::compute(); @@ -663,6 +678,7 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_leaf_fill_min_width::compute(); aspect_ratio_leaf_fill_width::compute(); aspect_ratio_leaf_overriden_by_explicit_sizes::compute(); + aspect_ratio_leaf_overriden_by_explicit_sizes_flex::compute(); border_center_child::compute(); border_flex_child::compute(); border_no_child::compute(); diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_height.html b/test_fixtures/aspect_ratio_flex_leaf_fill_height.html new file mode 100644 index 000000000..d4b52a8d2 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html b/test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html new file mode 100644 index 000000000..7d50d7826 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH​HH​HH​HH​HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html b/test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html new file mode 100644 index 000000000..12a94733c --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html b/test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html new file mode 100644 index 000000000..fb8aef515 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html b/test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html new file mode 100644 index 000000000..b92f16218 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_width.html b/test_fixtures/aspect_ratio_flex_leaf_fill_width.html new file mode 100644 index 000000000..dfe5c09e9 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html b/test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html new file mode 100644 index 000000000..37acb9990 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html b/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html new file mode 100644 index 000000000..f01c566e0 --- /dev/null +++ b/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_height.rs b/tests/generated/aspect_ratio_flex_leaf_fill_height.rs new file mode 100644 index 000000000..6eb03db77 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_height.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs b/tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs new file mode 100644 index 000000000..69558c66d --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs @@ -0,0 +1,36 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs b/tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs new file mode 100644 index 000000000..81dd45653 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs @@ -0,0 +1,54 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs b/tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs new file mode 100644 index 000000000..9231b77e5 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_min_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs b/tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs new file mode 100644 index 000000000..439a1b264 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs @@ -0,0 +1,54 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_min_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_width.rs b/tests/generated/aspect_ratio_flex_leaf_fill_width.rs new file mode 100644 index 000000000..72faade42 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_width.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs b/tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs new file mode 100644 index 000000000..cbabf9a4e --- /dev/null +++ b/tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_flex_leaf_fill_width_flex() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs b/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs new file mode 100644 index 000000000..193005b05 --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs @@ -0,0 +1,44 @@ +#[test] +fn aspect_ratio_leaf_overriden_by_explicit_sizes_flex() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 9ea186bb0..a7fef728d 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -120,6 +120,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_flex_leaf_fill_height; +mod aspect_ratio_flex_leaf_fill_max_height; +mod aspect_ratio_flex_leaf_fill_max_width; +mod aspect_ratio_flex_leaf_fill_min_height; +mod aspect_ratio_flex_leaf_fill_min_width; +mod aspect_ratio_flex_leaf_fill_width; +mod aspect_ratio_flex_leaf_fill_width_flex; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; @@ -129,6 +136,7 @@ mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; +mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; mod border_center_child; mod border_flex_child; mod border_no_child; From 8efe05c9b05197486a9fb8bf674bf2944762048e Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 19:07:25 +0000 Subject: [PATCH 13/40] Move aspect ratio handling from text measure func to leaf.rs --- ...spect_ratio_grid_child_fill_content_width.rs | 2 +- benches/generated/mod.rs | 15 +++------------ scripts/gentest/src/main.rs | 17 +++-------------- src/compute/leaf.rs | 12 +++++++++--- ...spect_ratio_grid_child_fill_content_width.rs | 14 +++++++------- tests/generated/mod.rs | 15 +++------------ 6 files changed, 26 insertions(+), 49 deletions(-) diff --git a/benches/generated/aspect_ratio_grid_child_fill_content_width.rs b/benches/generated/aspect_ratio_grid_child_fill_content_width.rs index d3dfc577c..6b9c8dc00 100644 --- a/benches/generated/aspect_ratio_grid_child_fill_content_width.rs +++ b/benches/generated/aspect_ratio_grid_child_fill_content_width.rs @@ -11,7 +11,7 @@ pub fn compute() { known_dimensions, available_space, TEXT, - super::WritingMode::Vertical, + super::WritingMode::Horizontal, Some(2f32), ) }), diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 78fa94c45..a7598f058 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -11,13 +11,10 @@ fn measure_standard_text( available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, - aspect_ratio: Option, + _aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; - fn f32_max(a: f32, b: f32) -> f32 { - core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) - } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -60,14 +57,8 @@ fn measure_standard_text( (line_count as f32) * H_HEIGHT }); match writing_mode { - WritingMode::Horizontal => Size { - width: inline_size, - height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), - }, - WritingMode::Vertical => Size { - width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), - height: inline_size, - }, + WritingMode::Horizontal => Size { width: inline_size, height: block_size }, + WritingMode::Vertical => Size { width: block_size, height: inline_size }, } } mod absolute_layout_align_items_and_justify_content_center; diff --git a/scripts/gentest/src/main.rs b/scripts/gentest/src/main.rs index 36a1fcf46..06eb5e165 100644 --- a/scripts/gentest/src/main.rs +++ b/scripts/gentest/src/main.rs @@ -845,13 +845,10 @@ fn generate_generic_measure_function() -> TokenStream { available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, - aspect_ratio: Option, + _aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; - fn f32_max(a: f32, b: f32) -> f32 { - core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) - } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -899,16 +896,8 @@ fn generate_generic_measure_function() -> TokenStream { }); match writing_mode { - WritingMode::Horizontal => Size { - width: inline_size, - // Apply aspect ratio - height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), - }, - WritingMode::Vertical => Size { - // Apply aspect ratio - width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), - height: inline_size, - }, + WritingMode::Horizontal => Size { width: inline_size, height: block_size }, + WritingMode::Vertical => Size { width: block_size, height: inline_size }, } } ) diff --git a/src/compute/leaf.rs b/src/compute/leaf.rs index 78a0679d2..9257c10d1 100644 --- a/src/compute/leaf.rs +++ b/src/compute/leaf.rs @@ -6,6 +6,7 @@ use crate::math::MaybeMath; use crate::node::Node; use crate::resolve::{MaybeResolve, ResolveOrZero}; use crate::style::AvailableSpace; +use crate::sys::f32_max; use crate::tree::LayoutTree; #[cfg(feature = "debug")] @@ -25,12 +26,12 @@ pub(crate) fn compute( // Resolve node's preferred/min/max sizes (width/heights) against the available space (percentages resolve to pixel values) // For ContentSize mode, we pretend that the node has no size styles as these should be ignored. - let (node_size, node_min_size, node_max_size) = match sizing_mode { + let (node_size, node_min_size, node_max_size, aspect_ratio) = match sizing_mode { SizingMode::ContentSize => { let node_size = known_dimensions; let node_min_size = Size::NONE; let node_max_size = Size::NONE; - (node_size, node_min_size, node_max_size) + (node_size, node_min_size, node_max_size, None) } SizingMode::InherentSize => { let aspect_ratio = style.aspect_ratio; @@ -39,7 +40,7 @@ pub(crate) fn compute( let style_max_size = style.max_size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); let node_size = known_dimensions.or(style_size); - (node_size, style_min_size, style_max_size) + (node_size, style_min_size, style_max_size, aspect_ratio) } }; @@ -75,6 +76,11 @@ pub(crate) fn compute( // Measure node let measured_size = tree.measure_node(node, known_dimensions, available_space); + let measured_size = Size { + width: measured_size.width, + height: f32_max(measured_size.height, aspect_ratio.map(|ratio| measured_size.width / ratio).unwrap_or(0.0)), + }; + return node_size.unwrap_or(measured_size).maybe_clamp(node_min_size, node_max_size); } diff --git a/tests/generated/aspect_ratio_grid_child_fill_content_width.rs b/tests/generated/aspect_ratio_grid_child_fill_content_width.rs index 27722c407..f859ada0d 100644 --- a/tests/generated/aspect_ratio_grid_child_fill_content_width.rs +++ b/tests/generated/aspect_ratio_grid_child_fill_content_width.rs @@ -13,7 +13,7 @@ fn aspect_ratio_grid_child_fill_content_width() { known_dimensions, available_space, TEXT, - super::WritingMode::Vertical, + super::WritingMode::Horizontal, Some(2f32), ) }), @@ -36,18 +36,18 @@ fn aspect_ratio_grid_child_fill_content_width() { taffy::debug::print_tree(&taffy, node); println!(); let Layout { size, location, .. } = taffy.layout(node).unwrap(); - assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 80f32, size.width); - assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 60f32, size.height); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 40f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node0).unwrap(); - assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); - assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node1).unwrap(); - assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 80f32, size.width); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, size.width); assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x); - assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y); + assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 20f32, location.y); } diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index a7fef728d..14b5766d1 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -10,13 +10,10 @@ fn measure_standard_text( available_space: taffy::geometry::Size, text_content: &str, writing_mode: WritingMode, - aspect_ratio: Option, + _aspect_ratio: Option, ) -> taffy::geometry::Size { use taffy::axis::AbsoluteAxis; use taffy::prelude::*; - fn f32_max(a: f32, b: f32) -> f32 { - core::cmp::max_by(a, b, |a, b| a.total_cmp(b)) - } const ZWS: char = '\u{200B}'; const H_WIDTH: f32 = 10.0; const H_HEIGHT: f32 = 10.0; @@ -59,14 +56,8 @@ fn measure_standard_text( (line_count as f32) * H_HEIGHT }); match writing_mode { - WritingMode::Horizontal => Size { - width: inline_size, - height: f32_max(block_size, aspect_ratio.map(|ratio| inline_size / ratio).unwrap_or(0.0)), - }, - WritingMode::Vertical => Size { - width: f32_max(block_size, aspect_ratio.map(|ratio| inline_size * ratio).unwrap_or(0.0)), - height: inline_size, - }, + WritingMode::Horizontal => Size { width: inline_size, height: block_size }, + WritingMode::Vertical => Size { width: block_size, height: inline_size }, } } mod absolute_layout_align_items_and_justify_content_center; From 81ac76897cb3868440c6b57f966b5dfc7eaeec25 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 19:30:17 +0000 Subject: [PATCH 14/40] Tweak clamping of flex item minimum sizes --- src/compute/flexbox.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index fc684cf09..d4fee4179 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -643,13 +643,10 @@ fn determine_flex_base_size( // 4.5. Automatic Minimum Size of Flex Items // https://www.w3.org/TR/css-flexbox-1/#min-size-auto - let specified = child.size.maybe_min(child.max_size); - child.resolved_minimum_size = child.min_size.unwrap_or(min_content_size.maybe_min(specified)); + child.resolved_minimum_size = + child.min_size.unwrap_or(min_content_size.maybe_min(child.size).maybe_min(child.max_size)); - let hypothetical_inner_min_main = min_content_size - .main(constants.dir) - .maybe_clamp(child.resolved_minimum_size.main(constants.dir).into(), child.size.main(constants.dir)) - .into(); + let hypothetical_inner_min_main = child.resolved_minimum_size.main(constants.dir).into(); child.hypothetical_inner_size.set_main( constants.dir, child.flex_basis.maybe_clamp(hypothetical_inner_min_main, child.max_size.main(constants.dir)), From 214b4e68f835eb30489f89ab9de03d59aee14d71 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 19:30:52 +0000 Subject: [PATCH 15/40] Add aspect ratio tests for flex-columns with align-items: start --- .../aspect_ratio_flex_column_fill_height.rs | 28 ++++++++++ ...spect_ratio_flex_column_fill_max_height.rs | 22 ++++++++ ...aspect_ratio_flex_column_fill_max_width.rs | 40 ++++++++++++++ ...spect_ratio_flex_column_fill_min_height.rs | 28 ++++++++++ ...aspect_ratio_flex_column_fill_min_width.rs | 40 ++++++++++++++ .../aspect_ratio_flex_column_fill_width.rs | 28 ++++++++++ ...spect_ratio_flex_column_fill_width_flex.rs | 27 +++++++++ ...s => aspect_ratio_flex_row_fill_height.rs} | 0 ... aspect_ratio_flex_row_fill_max_height.rs} | 0 ...> aspect_ratio_flex_row_fill_max_width.rs} | 0 ... aspect_ratio_flex_row_fill_min_height.rs} | 0 ...> aspect_ratio_flex_row_fill_min_width.rs} | 0 ...rs => aspect_ratio_flex_row_fill_width.rs} | 0 ... aspect_ratio_flex_row_fill_width_flex.rs} | 0 benches/generated/mod.rs | 42 +++++++++----- .../aspect_ratio_flex_column_fill_height.html | 17 ++++++ ...ect_ratio_flex_column_fill_max_height.html | 17 ++++++ ...pect_ratio_flex_column_fill_max_width.html | 17 ++++++ ...ect_ratio_flex_column_fill_min_height.html | 17 ++++++ ...pect_ratio_flex_column_fill_min_width.html | 19 +++++++ .../aspect_ratio_flex_column_fill_width.html | 17 ++++++ ...ect_ratio_flex_column_fill_width_flex.html | 17 ++++++ ...=> aspect_ratio_flex_row_fill_height.html} | 0 ...spect_ratio_flex_row_fill_max_height.html} | 0 ...aspect_ratio_flex_row_fill_max_width.html} | 0 ...spect_ratio_flex_row_fill_min_height.html} | 0 ...aspect_ratio_flex_row_fill_min_width.html} | 0 ... => aspect_ratio_flex_row_fill_width.html} | 0 ...spect_ratio_flex_row_fill_width_flex.html} | 0 ...t_ratio_grid_child_fill_content_width.html | 2 +- .../aspect_ratio_flex_column_fill_height.rs | 43 +++++++++++++++ ...spect_ratio_flex_column_fill_max_height.rs | 37 +++++++++++++ ...aspect_ratio_flex_column_fill_max_width.rs | 55 +++++++++++++++++++ ...spect_ratio_flex_column_fill_min_height.rs | 43 +++++++++++++++ ...aspect_ratio_flex_column_fill_min_width.rs | 55 +++++++++++++++++++ .../aspect_ratio_flex_column_fill_width.rs | 43 +++++++++++++++ ...spect_ratio_flex_column_fill_width_flex.rs | 42 ++++++++++++++ ...s => aspect_ratio_flex_row_fill_height.rs} | 2 +- ... aspect_ratio_flex_row_fill_max_height.rs} | 2 +- ...> aspect_ratio_flex_row_fill_max_width.rs} | 2 +- ... aspect_ratio_flex_row_fill_min_height.rs} | 2 +- ...> aspect_ratio_flex_row_fill_min_width.rs} | 2 +- ...rs => aspect_ratio_flex_row_fill_width.rs} | 2 +- ... aspect_ratio_flex_row_fill_width_flex.rs} | 2 +- tests/generated/mod.rs | 21 ++++--- 45 files changed, 702 insertions(+), 29 deletions(-) create mode 100644 benches/generated/aspect_ratio_flex_column_fill_height.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_max_height.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_max_width.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_min_height.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_min_width.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_width.rs create mode 100644 benches/generated/aspect_ratio_flex_column_fill_width_flex.rs rename benches/generated/{aspect_ratio_flex_leaf_fill_height.rs => aspect_ratio_flex_row_fill_height.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_max_height.rs => aspect_ratio_flex_row_fill_max_height.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_max_width.rs => aspect_ratio_flex_row_fill_max_width.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_min_height.rs => aspect_ratio_flex_row_fill_min_height.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_min_width.rs => aspect_ratio_flex_row_fill_min_width.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_width.rs => aspect_ratio_flex_row_fill_width.rs} (100%) rename benches/generated/{aspect_ratio_flex_leaf_fill_width_flex.rs => aspect_ratio_flex_row_fill_width_flex.rs} (100%) create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_height.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_max_height.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_max_width.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_min_height.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_min_width.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_width.html create mode 100644 test_fixtures/aspect_ratio_flex_column_fill_width_flex.html rename test_fixtures/{aspect_ratio_flex_leaf_fill_height.html => aspect_ratio_flex_row_fill_height.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_max_height.html => aspect_ratio_flex_row_fill_max_height.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_max_width.html => aspect_ratio_flex_row_fill_max_width.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_min_height.html => aspect_ratio_flex_row_fill_min_height.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_min_width.html => aspect_ratio_flex_row_fill_min_width.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_width.html => aspect_ratio_flex_row_fill_width.html} (100%) rename test_fixtures/{aspect_ratio_flex_leaf_fill_width_flex.html => aspect_ratio_flex_row_fill_width_flex.html} (100%) create mode 100644 tests/generated/aspect_ratio_flex_column_fill_height.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_max_height.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_max_width.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_min_height.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_min_width.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_width.rs create mode 100644 tests/generated/aspect_ratio_flex_column_fill_width_flex.rs rename tests/generated/{aspect_ratio_flex_leaf_fill_height.rs => aspect_ratio_flex_row_fill_height.rs} (98%) rename tests/generated/{aspect_ratio_flex_leaf_fill_max_height.rs => aspect_ratio_flex_row_fill_max_height.rs} (98%) rename tests/generated/{aspect_ratio_flex_leaf_fill_max_width.rs => aspect_ratio_flex_row_fill_max_width.rs} (98%) rename tests/generated/{aspect_ratio_flex_leaf_fill_min_height.rs => aspect_ratio_flex_row_fill_min_height.rs} (97%) rename tests/generated/{aspect_ratio_flex_leaf_fill_min_width.rs => aspect_ratio_flex_row_fill_min_width.rs} (98%) rename tests/generated/{aspect_ratio_flex_leaf_fill_width.rs => aspect_ratio_flex_row_fill_width.rs} (98%) rename tests/generated/{aspect_ratio_flex_leaf_fill_width_flex.rs => aspect_ratio_flex_row_fill_width_flex.rs} (97%) diff --git a/benches/generated/aspect_ratio_flex_column_fill_height.rs b/benches/generated/aspect_ratio_flex_column_fill_height.rs new file mode 100644 index 000000000..5f450c137 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_height.rs @@ -0,0 +1,28 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_max_height.rs b/benches/generated/aspect_ratio_flex_column_fill_max_height.rs new file mode 100644 index 000000000..545a90bb7 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_max_height.rs @@ -0,0 +1,22 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_max_width.rs b/benches/generated/aspect_ratio_flex_column_fill_max_width.rs new file mode 100644 index 000000000..aee7e7180 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_max_width.rs @@ -0,0 +1,40 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_min_height.rs b/benches/generated/aspect_ratio_flex_column_fill_min_height.rs new file mode 100644 index 000000000..b52b9b698 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_min_height.rs @@ -0,0 +1,28 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_min_width.rs b/benches/generated/aspect_ratio_flex_column_fill_min_width.rs new file mode 100644 index 000000000..adbe8fd7e --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_min_width.rs @@ -0,0 +1,40 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_width.rs b/benches/generated/aspect_ratio_flex_column_fill_width.rs new file mode 100644 index 000000000..a05061cf6 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_width.rs @@ -0,0 +1,28 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_fill_width_flex.rs b/benches/generated/aspect_ratio_flex_column_fill_width_flex.rs new file mode 100644 index 000000000..4cd3383d3 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_fill_width_flex.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_height.rs b/benches/generated/aspect_ratio_flex_row_fill_height.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_height.rs rename to benches/generated/aspect_ratio_flex_row_fill_height.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs b/benches/generated/aspect_ratio_flex_row_fill_max_height.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_max_height.rs rename to benches/generated/aspect_ratio_flex_row_fill_max_height.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs b/benches/generated/aspect_ratio_flex_row_fill_max_width.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_max_width.rs rename to benches/generated/aspect_ratio_flex_row_fill_max_width.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs b/benches/generated/aspect_ratio_flex_row_fill_min_height.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_min_height.rs rename to benches/generated/aspect_ratio_flex_row_fill_min_height.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs b/benches/generated/aspect_ratio_flex_row_fill_min_width.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_min_width.rs rename to benches/generated/aspect_ratio_flex_row_fill_min_width.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_width.rs b/benches/generated/aspect_ratio_flex_row_fill_width.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_width.rs rename to benches/generated/aspect_ratio_flex_row_fill_width.rs diff --git a/benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs b/benches/generated/aspect_ratio_flex_row_fill_width_flex.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_leaf_fill_width_flex.rs rename to benches/generated/aspect_ratio_flex_row_fill_width_flex.rs diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index a7598f058..803950807 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -112,13 +112,20 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_leaf_fill_height; -mod aspect_ratio_flex_leaf_fill_max_height; -mod aspect_ratio_flex_leaf_fill_max_width; -mod aspect_ratio_flex_leaf_fill_min_height; -mod aspect_ratio_flex_leaf_fill_min_width; -mod aspect_ratio_flex_leaf_fill_width; -mod aspect_ratio_flex_leaf_fill_width_flex; +mod aspect_ratio_flex_column_fill_height; +mod aspect_ratio_flex_column_fill_max_height; +mod aspect_ratio_flex_column_fill_max_width; +mod aspect_ratio_flex_column_fill_min_height; +mod aspect_ratio_flex_column_fill_min_width; +mod aspect_ratio_flex_column_fill_width; +mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_row_fill_height; +mod aspect_ratio_flex_row_fill_max_height; +mod aspect_ratio_flex_row_fill_max_width; +mod aspect_ratio_flex_row_fill_min_height; +mod aspect_ratio_flex_row_fill_min_width; +mod aspect_ratio_flex_row_fill_width; +mod aspect_ratio_flex_row_fill_width_flex; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; @@ -653,13 +660,20 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); - aspect_ratio_flex_leaf_fill_height::compute(); - aspect_ratio_flex_leaf_fill_max_height::compute(); - aspect_ratio_flex_leaf_fill_max_width::compute(); - aspect_ratio_flex_leaf_fill_min_height::compute(); - aspect_ratio_flex_leaf_fill_min_width::compute(); - aspect_ratio_flex_leaf_fill_width::compute(); - aspect_ratio_flex_leaf_fill_width_flex::compute(); + aspect_ratio_flex_column_fill_height::compute(); + aspect_ratio_flex_column_fill_max_height::compute(); + aspect_ratio_flex_column_fill_max_width::compute(); + aspect_ratio_flex_column_fill_min_height::compute(); + aspect_ratio_flex_column_fill_min_width::compute(); + aspect_ratio_flex_column_fill_width::compute(); + aspect_ratio_flex_column_fill_width_flex::compute(); + aspect_ratio_flex_row_fill_height::compute(); + aspect_ratio_flex_row_fill_max_height::compute(); + aspect_ratio_flex_row_fill_max_width::compute(); + aspect_ratio_flex_row_fill_min_height::compute(); + aspect_ratio_flex_row_fill_min_width::compute(); + aspect_ratio_flex_row_fill_width::compute(); + aspect_ratio_flex_row_fill_width_flex::compute(); aspect_ratio_grid_child_fill_content_height::compute(); aspect_ratio_grid_child_fill_content_width::compute(); aspect_ratio_leaf_fill_height::compute(); diff --git a/test_fixtures/aspect_ratio_flex_column_fill_height.html b/test_fixtures/aspect_ratio_flex_column_fill_height.html new file mode 100644 index 000000000..9b3e62690 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_max_height.html b/test_fixtures/aspect_ratio_flex_column_fill_max_height.html new file mode 100644 index 000000000..c3c08ae72 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH​HH​HH​HH​HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_max_width.html b/test_fixtures/aspect_ratio_flex_column_fill_max_width.html new file mode 100644 index 000000000..8b5996b8d --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_min_height.html b/test_fixtures/aspect_ratio_flex_column_fill_min_height.html new file mode 100644 index 000000000..dfc6580b3 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_min_width.html b/test_fixtures/aspect_ratio_flex_column_fill_min_width.html new file mode 100644 index 000000000..78434d38a --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_min_width.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_width.html b/test_fixtures/aspect_ratio_flex_column_fill_width.html new file mode 100644 index 000000000..2a401a098 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_fill_width_flex.html b/test_fixtures/aspect_ratio_flex_column_fill_width_flex.html new file mode 100644 index 000000000..2714b744d --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_fill_width_flex.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_height.html b/test_fixtures/aspect_ratio_flex_row_fill_height.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_height.html rename to test_fixtures/aspect_ratio_flex_row_fill_height.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html b/test_fixtures/aspect_ratio_flex_row_fill_max_height.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_max_height.html rename to test_fixtures/aspect_ratio_flex_row_fill_max_height.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html b/test_fixtures/aspect_ratio_flex_row_fill_max_width.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_max_width.html rename to test_fixtures/aspect_ratio_flex_row_fill_max_width.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html b/test_fixtures/aspect_ratio_flex_row_fill_min_height.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_min_height.html rename to test_fixtures/aspect_ratio_flex_row_fill_min_height.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html b/test_fixtures/aspect_ratio_flex_row_fill_min_width.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_min_width.html rename to test_fixtures/aspect_ratio_flex_row_fill_min_width.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_width.html b/test_fixtures/aspect_ratio_flex_row_fill_width.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_width.html rename to test_fixtures/aspect_ratio_flex_row_fill_width.html diff --git a/test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html b/test_fixtures/aspect_ratio_flex_row_fill_width_flex.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_leaf_fill_width_flex.html rename to test_fixtures/aspect_ratio_flex_row_fill_width_flex.html diff --git a/test_fixtures/aspect_ratio_grid_child_fill_content_width.html b/test_fixtures/aspect_ratio_grid_child_fill_content_width.html index 913574b4c..db240459c 100644 --- a/test_fixtures/aspect_ratio_grid_child_fill_content_width.html +++ b/test_fixtures/aspect_ratio_grid_child_fill_content_width.html @@ -10,7 +10,7 @@
-
HHHH
+
HHHH
diff --git a/tests/generated/aspect_ratio_flex_column_fill_height.rs b/tests/generated/aspect_ratio_flex_column_fill_height.rs new file mode 100644 index 000000000..b72209a28 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_height.rs @@ -0,0 +1,43 @@ +#[test] +fn aspect_ratio_flex_column_fill_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_max_height.rs b/tests/generated/aspect_ratio_flex_column_fill_max_height.rs new file mode 100644 index 000000000..f9c5ca4ab --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_max_height.rs @@ -0,0 +1,37 @@ +#[test] +fn aspect_ratio_flex_column_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_max_width.rs b/tests/generated/aspect_ratio_flex_column_fill_max_width.rs new file mode 100644 index 000000000..3017455ab --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_max_width.rs @@ -0,0 +1,55 @@ +#[test] +fn aspect_ratio_flex_column_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_min_height.rs b/tests/generated/aspect_ratio_flex_column_fill_min_height.rs new file mode 100644 index 000000000..9c59accd9 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_min_height.rs @@ -0,0 +1,43 @@ +#[test] +fn aspect_ratio_flex_column_fill_min_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_min_width.rs b/tests/generated/aspect_ratio_flex_column_fill_min_width.rs new file mode 100644 index 000000000..c1ccf2a4f --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_min_width.rs @@ -0,0 +1,55 @@ +#[test] +fn aspect_ratio_flex_column_fill_min_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "\n \n "; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_width.rs b/tests/generated/aspect_ratio_flex_column_fill_width.rs new file mode 100644 index 000000000..2dd2d380e --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_width.rs @@ -0,0 +1,43 @@ +#[test] +fn aspect_ratio_flex_column_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_fill_width_flex.rs b/tests/generated/aspect_ratio_flex_column_fill_width_flex.rs new file mode 100644 index 000000000..298755699 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_fill_width_flex.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_column_fill_width_flex() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_height.rs b/tests/generated/aspect_ratio_flex_row_fill_height.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_leaf_fill_height.rs rename to tests/generated/aspect_ratio_flex_row_fill_height.rs index 6eb03db77..516b0256f 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_height.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_height() { +fn aspect_ratio_flex_row_fill_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs b/tests/generated/aspect_ratio_flex_row_fill_max_height.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs rename to tests/generated/aspect_ratio_flex_row_fill_max_height.rs index 69558c66d..b4a5ad5c5 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_max_height.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_max_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_max_height() { +fn aspect_ratio_flex_row_fill_max_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs b/tests/generated/aspect_ratio_flex_row_fill_max_width.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs rename to tests/generated/aspect_ratio_flex_row_fill_max_width.rs index 81dd45653..e730fa0fc 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_max_width.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_max_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_max_width() { +fn aspect_ratio_flex_row_fill_max_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs b/tests/generated/aspect_ratio_flex_row_fill_min_height.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs rename to tests/generated/aspect_ratio_flex_row_fill_min_height.rs index 9231b77e5..977f5c589 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_min_height.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_min_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_min_height() { +fn aspect_ratio_flex_row_fill_min_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs b/tests/generated/aspect_ratio_flex_row_fill_min_width.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs rename to tests/generated/aspect_ratio_flex_row_fill_min_width.rs index 439a1b264..de53e47a1 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_min_width.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_min_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_min_width() { +fn aspect_ratio_flex_row_fill_min_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_width.rs b/tests/generated/aspect_ratio_flex_row_fill_width.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_leaf_fill_width.rs rename to tests/generated/aspect_ratio_flex_row_fill_width.rs index 72faade42..4a26d970d 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_width.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_width() { +fn aspect_ratio_flex_row_fill_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs b/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs rename to tests/generated/aspect_ratio_flex_row_fill_width_flex.rs index cbabf9a4e..e014f637d 100644 --- a/tests/generated/aspect_ratio_flex_leaf_fill_width_flex.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_leaf_fill_width_flex() { +fn aspect_ratio_flex_row_fill_width_flex() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 14b5766d1..d7d1bf716 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -111,13 +111,20 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_leaf_fill_height; -mod aspect_ratio_flex_leaf_fill_max_height; -mod aspect_ratio_flex_leaf_fill_max_width; -mod aspect_ratio_flex_leaf_fill_min_height; -mod aspect_ratio_flex_leaf_fill_min_width; -mod aspect_ratio_flex_leaf_fill_width; -mod aspect_ratio_flex_leaf_fill_width_flex; +mod aspect_ratio_flex_column_fill_height; +mod aspect_ratio_flex_column_fill_max_height; +mod aspect_ratio_flex_column_fill_max_width; +mod aspect_ratio_flex_column_fill_min_height; +mod aspect_ratio_flex_column_fill_min_width; +mod aspect_ratio_flex_column_fill_width; +mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_row_fill_height; +mod aspect_ratio_flex_row_fill_max_height; +mod aspect_ratio_flex_row_fill_max_width; +mod aspect_ratio_flex_row_fill_min_height; +mod aspect_ratio_flex_row_fill_min_width; +mod aspect_ratio_flex_row_fill_width; +mod aspect_ratio_flex_row_fill_width_flex; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; From e2af292c6f89b9a0b91d6ee8beba7b2efddf6397 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 20:22:01 +0000 Subject: [PATCH 16/40] FLexbox: don't apply aspect ratio to max_width when clamping stretched cross-sizes --- src/compute/flexbox.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index d4fee4179..85a80a909 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1187,8 +1187,15 @@ fn determine_used_cross_size(tree: &mut impl LayoutTree, flex_lines: &mut [FlexL && child_style.margin.cross_end(constants.dir) != LengthPercentageAuto::Auto && child_style.size.cross(constants.dir) == Dimension::Auto { - (line_cross_size - child.margin.cross_axis_sum(constants.dir)) - .maybe_clamp(child.min_size.cross(constants.dir), child.max_size.cross(constants.dir)) + // For some reason this particular usage of max_width is an exception to the rule that max_width's transfer + // using the aspect_ratio (if set). Both Chrome and Firefox agree on this. And reading the spec, it seems like + // a reasonable interpretation. Although it seems to me that the spec *should* apply aspect_ratio here. + let max_size_ignoring_aspect_ratio = child_style.max_size.maybe_resolve(constants.node_inner_size); + + (line_cross_size - child.margin.cross_axis_sum(constants.dir)).maybe_clamp( + child.min_size.cross(constants.dir), + max_size_ignoring_aspect_ratio.cross(constants.dir), + ) } else { child.hypothetical_inner_size.cross(constants.dir) }, From 03c91672e6e2ffa5e7fbcbfee8b99f162cf26ea7 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 4 Jan 2023 20:23:03 +0000 Subject: [PATCH 17/40] Add tests for aspect ratio with align-items:stretch (flexbox) --- ...t_ratio_flex_column_stretch_fill_height.rs | 27 ++++++++++ ...tio_flex_column_stretch_fill_max_height.rs | 21 ++++++++ ...atio_flex_column_stretch_fill_max_width.rs | 39 ++++++++++++++ ...ct_ratio_flex_column_stretch_fill_width.rs | 27 ++++++++++ .../aspect_ratio_flex_row_fill_width_flex.rs | 1 + ...pect_ratio_flex_row_stretch_fill_height.rs | 26 +++++++++ ..._ratio_flex_row_stretch_fill_max_height.rs | 20 +++++++ ...t_ratio_flex_row_stretch_fill_max_width.rs | 38 +++++++++++++ ...spect_ratio_flex_row_stretch_fill_width.rs | 26 +++++++++ ...spect_ratio_leaf_fill_min_width_percent.rs | 27 ++++++++++ benches/generated/mod.rs | 18 +++++++ ...ratio_flex_column_stretch_fill_height.html | 17 ++++++ ...o_flex_column_stretch_fill_max_height.html | 17 ++++++ ...io_flex_column_stretch_fill_max_width.html | 17 ++++++ ..._ratio_flex_column_stretch_fill_width.html | 17 ++++++ ...aspect_ratio_flex_row_fill_width_flex.html | 2 +- ...t_ratio_flex_row_stretch_fill_height.html} | 6 +-- ...atio_flex_row_stretch_fill_max_height.html | 17 ++++++ ...ratio_flex_row_stretch_fill_max_width.html | 17 ++++++ ...ect_ratio_flex_row_stretch_fill_width.html | 17 ++++++ ...o_flex_column_stretch_fill_min_height.html | 17 ++++++ ...io_flex_column_stretch_fill_min_width.html | 19 +++++++ ...atio_flex_row_stretch_fill_min_height.html | 17 ++++++ ...ratio_flex_row_stretch_fill_min_width.html | 19 +++++++ ...t_ratio_flex_column_stretch_fill_height.rs | 42 +++++++++++++++ ...tio_flex_column_stretch_fill_max_height.rs | 36 +++++++++++++ ...atio_flex_column_stretch_fill_max_width.rs | 54 +++++++++++++++++++ ...ct_ratio_flex_column_stretch_fill_width.rs | 42 +++++++++++++++ .../aspect_ratio_flex_row_fill_width_flex.rs | 1 + ...pect_ratio_flex_row_stretch_fill_height.rs | 41 ++++++++++++++ ..._ratio_flex_row_stretch_fill_max_height.rs | 35 ++++++++++++ ...t_ratio_flex_row_stretch_fill_max_width.rs | 53 ++++++++++++++++++ ...spect_ratio_flex_row_stretch_fill_width.rs | 41 ++++++++++++++ ...spect_ratio_leaf_fill_min_width_percent.rs | 42 +++++++++++++++ tests/generated/mod.rs | 9 ++++ 35 files changed, 860 insertions(+), 5 deletions(-) create mode 100644 benches/generated/aspect_ratio_flex_column_stretch_fill_height.rs create mode 100644 benches/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs create mode 100644 benches/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs create mode 100644 benches/generated/aspect_ratio_flex_column_stretch_fill_width.rs create mode 100644 benches/generated/aspect_ratio_flex_row_stretch_fill_height.rs create mode 100644 benches/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs create mode 100644 benches/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs create mode 100644 benches/generated/aspect_ratio_flex_row_stretch_fill_width.rs create mode 100644 benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs create mode 100644 test_fixtures/aspect_ratio_flex_column_stretch_fill_height.html create mode 100644 test_fixtures/aspect_ratio_flex_column_stretch_fill_max_height.html create mode 100644 test_fixtures/aspect_ratio_flex_column_stretch_fill_max_width.html create mode 100644 test_fixtures/aspect_ratio_flex_column_stretch_fill_width.html rename test_fixtures/{xaspect_ratio_leaf_fill_min_width_percent.html => aspect_ratio_flex_row_stretch_fill_height.html} (58%) create mode 100644 test_fixtures/aspect_ratio_flex_row_stretch_fill_max_height.html create mode 100644 test_fixtures/aspect_ratio_flex_row_stretch_fill_max_width.html create mode 100644 test_fixtures/aspect_ratio_flex_row_stretch_fill_width.html create mode 100644 test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_height.html create mode 100644 test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_width.html create mode 100644 test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_height.html create mode 100644 test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_width.html create mode 100644 tests/generated/aspect_ratio_flex_column_stretch_fill_height.rs create mode 100644 tests/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs create mode 100644 tests/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs create mode 100644 tests/generated/aspect_ratio_flex_column_stretch_fill_width.rs create mode 100644 tests/generated/aspect_ratio_flex_row_stretch_fill_height.rs create mode 100644 tests/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs create mode 100644 tests/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs create mode 100644 tests/generated/aspect_ratio_flex_row_stretch_fill_width.rs create mode 100644 tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs diff --git a/benches/generated/aspect_ratio_flex_column_stretch_fill_height.rs b/benches/generated/aspect_ratio_flex_column_stretch_fill_height.rs new file mode 100644 index 000000000..b2703bde7 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_stretch_fill_height.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs b/benches/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs new file mode 100644 index 000000000..225527030 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs @@ -0,0 +1,21 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs b/benches/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs new file mode 100644 index 000000000..dd8c40f0e --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs @@ -0,0 +1,39 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_stretch_fill_width.rs b/benches/generated/aspect_ratio_flex_column_stretch_fill_width.rs new file mode 100644 index 000000000..c00d49d30 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_stretch_fill_width.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_row_fill_width_flex.rs b/benches/generated/aspect_ratio_flex_row_fill_width_flex.rs index 4f801930b..02b13b129 100644 --- a/benches/generated/aspect_ratio_flex_row_fill_width_flex.rs +++ b/benches/generated/aspect_ratio_flex_row_fill_width_flex.rs @@ -13,6 +13,7 @@ pub fn compute() { .new_with_children( taffy::style::Style { display: taffy::style::Display::Grid, + align_items: Some(taffy::style::AlignItems::Start), size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), diff --git a/benches/generated/aspect_ratio_flex_row_stretch_fill_height.rs b/benches/generated/aspect_ratio_flex_row_stretch_fill_height.rs new file mode 100644 index 000000000..0a3c7e687 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_row_stretch_fill_height.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs b/benches/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs new file mode 100644 index 000000000..b78d778b0 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs @@ -0,0 +1,20 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs b/benches/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs new file mode 100644 index 000000000..f8d66c06d --- /dev/null +++ b/benches/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_row_stretch_fill_width.rs b/benches/generated/aspect_ratio_flex_row_stretch_fill_width.rs new file mode 100644 index 000000000..4bd68cfc6 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_row_stretch_fill_width.rs @@ -0,0 +1,26 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs b/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs new file mode 100644 index 000000000..651028550 --- /dev/null +++ b/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 803950807..85acf9dc0 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -119,6 +119,10 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_column_stretch_fill_height; +mod aspect_ratio_flex_column_stretch_fill_max_height; +mod aspect_ratio_flex_column_stretch_fill_max_width; +mod aspect_ratio_flex_column_stretch_fill_width; mod aspect_ratio_flex_row_fill_height; mod aspect_ratio_flex_row_fill_max_height; mod aspect_ratio_flex_row_fill_max_width; @@ -126,6 +130,10 @@ mod aspect_ratio_flex_row_fill_min_height; mod aspect_ratio_flex_row_fill_min_width; mod aspect_ratio_flex_row_fill_width; mod aspect_ratio_flex_row_fill_width_flex; +mod aspect_ratio_flex_row_stretch_fill_height; +mod aspect_ratio_flex_row_stretch_fill_max_height; +mod aspect_ratio_flex_row_stretch_fill_max_width; +mod aspect_ratio_flex_row_stretch_fill_width; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; @@ -133,6 +141,7 @@ mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; +mod aspect_ratio_leaf_fill_min_width_percent; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; @@ -667,6 +676,10 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_flex_column_fill_min_width::compute(); aspect_ratio_flex_column_fill_width::compute(); aspect_ratio_flex_column_fill_width_flex::compute(); + aspect_ratio_flex_column_stretch_fill_height::compute(); + aspect_ratio_flex_column_stretch_fill_max_height::compute(); + aspect_ratio_flex_column_stretch_fill_max_width::compute(); + aspect_ratio_flex_column_stretch_fill_width::compute(); aspect_ratio_flex_row_fill_height::compute(); aspect_ratio_flex_row_fill_max_height::compute(); aspect_ratio_flex_row_fill_max_width::compute(); @@ -674,6 +687,10 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_flex_row_fill_min_width::compute(); aspect_ratio_flex_row_fill_width::compute(); aspect_ratio_flex_row_fill_width_flex::compute(); + aspect_ratio_flex_row_stretch_fill_height::compute(); + aspect_ratio_flex_row_stretch_fill_max_height::compute(); + aspect_ratio_flex_row_stretch_fill_max_width::compute(); + aspect_ratio_flex_row_stretch_fill_width::compute(); aspect_ratio_grid_child_fill_content_height::compute(); aspect_ratio_grid_child_fill_content_width::compute(); aspect_ratio_leaf_fill_height::compute(); @@ -681,6 +698,7 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_leaf_fill_max_width::compute(); aspect_ratio_leaf_fill_min_height::compute(); aspect_ratio_leaf_fill_min_width::compute(); + aspect_ratio_leaf_fill_min_width_percent::compute(); aspect_ratio_leaf_fill_width::compute(); aspect_ratio_leaf_overriden_by_explicit_sizes::compute(); aspect_ratio_leaf_overriden_by_explicit_sizes_flex::compute(); diff --git a/test_fixtures/aspect_ratio_flex_column_stretch_fill_height.html b/test_fixtures/aspect_ratio_flex_column_stretch_fill_height.html new file mode 100644 index 000000000..cd2d48b10 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_stretch_fill_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_height.html b/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_height.html new file mode 100644 index 000000000..c57582db0 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH​HH​HH​HH​HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_width.html b/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_width.html new file mode 100644 index 000000000..2343fe878 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_stretch_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_stretch_fill_width.html b/test_fixtures/aspect_ratio_flex_column_stretch_fill_width.html new file mode 100644 index 000000000..b1c3100d6 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_stretch_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_row_fill_width_flex.html b/test_fixtures/aspect_ratio_flex_row_fill_width_flex.html index 37acb9990..84c3b5e6b 100644 --- a/test_fixtures/aspect_ratio_flex_row_fill_width_flex.html +++ b/test_fixtures/aspect_ratio_flex_row_fill_width_flex.html @@ -9,7 +9,7 @@ -
+
diff --git a/test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html b/test_fixtures/aspect_ratio_flex_row_stretch_fill_height.html similarity index 58% rename from test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html rename to test_fixtures/aspect_ratio_flex_row_stretch_fill_height.html index 152bd75b8..b1785946f 100644 --- a/test_fixtures/xaspect_ratio_leaf_fill_min_width_percent.html +++ b/test_fixtures/aspect_ratio_flex_row_stretch_fill_height.html @@ -9,10 +9,8 @@ - - -
-
+
+
diff --git a/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_height.html b/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_height.html new file mode 100644 index 000000000..e5302432e --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH​HH​HH​HH​HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_width.html b/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_width.html new file mode 100644 index 000000000..08c6727b8 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_row_stretch_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HH​HH​HH​HH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_row_stretch_fill_width.html b/test_fixtures/aspect_ratio_flex_row_stretch_fill_width.html new file mode 100644 index 000000000..1afa1ffc2 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_row_stretch_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_height.html b/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_height.html new file mode 100644 index 000000000..f4c783987 --- /dev/null +++ b/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_width.html b/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_width.html new file mode 100644 index 000000000..9def9017d --- /dev/null +++ b/test_fixtures/xaspect_ratio_flex_column_stretch_fill_min_width.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_height.html b/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_height.html new file mode 100644 index 000000000..051d88c56 --- /dev/null +++ b/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_width.html b/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_width.html new file mode 100644 index 000000000..d86f6aa42 --- /dev/null +++ b/test_fixtures/xaspect_ratio_flex_row_stretch_fill_min_width.html @@ -0,0 +1,19 @@ + + + + + + + Test description + + + + +
+
+ +
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_flex_column_stretch_fill_height.rs b/tests/generated/aspect_ratio_flex_column_stretch_fill_height.rs new file mode 100644 index 000000000..1602cfda4 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_stretch_fill_height.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_column_stretch_fill_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs b/tests/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs new file mode 100644 index 000000000..4d00231b0 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_stretch_fill_max_height.rs @@ -0,0 +1,36 @@ +#[test] +fn aspect_ratio_flex_column_stretch_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs b/tests/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs new file mode 100644 index 000000000..79c7b78b4 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_stretch_fill_max_width.rs @@ -0,0 +1,54 @@ +#[test] +fn aspect_ratio_flex_column_stretch_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_stretch_fill_width.rs b/tests/generated/aspect_ratio_flex_column_stretch_fill_width.rs new file mode 100644 index 000000000..89beefa0c --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_stretch_fill_width.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_flex_column_stretch_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + flex_direction: taffy::style::FlexDirection::Column, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs b/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs index e014f637d..8db4152dd 100644 --- a/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs +++ b/tests/generated/aspect_ratio_flex_row_fill_width_flex.rs @@ -15,6 +15,7 @@ fn aspect_ratio_flex_row_fill_width_flex() { .new_with_children( taffy::style::Style { display: taffy::style::Display::Grid, + align_items: Some(taffy::style::AlignItems::Start), size: taffy::geometry::Size { width: taffy::style::Dimension::Points(100f32), height: taffy::style::Dimension::Points(100f32), diff --git a/tests/generated/aspect_ratio_flex_row_stretch_fill_height.rs b/tests/generated/aspect_ratio_flex_row_stretch_fill_height.rs new file mode 100644 index 000000000..0e28c50e4 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_row_stretch_fill_height.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_flex_row_stretch_fill_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: taffy::style::Dimension::Points(40f32), height: auto() }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs b/tests/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs new file mode 100644 index 000000000..4935d24e0 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_row_stretch_fill_max_height.rs @@ -0,0 +1,35 @@ +#[test] +fn aspect_ratio_flex_row_stretch_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (40f32) , height : auto () , } , aspect_ratio : Some (2f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH\u{200b}HH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (2f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs b/tests/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs new file mode 100644 index 000000000..c2a14a370 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_row_stretch_fill_max_width.rs @@ -0,0 +1,53 @@ +#[test] +fn aspect_ratio_flex_row_stretch_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf_with_measure( + taffy::style::Style { + max_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(20f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }, + taffy::node::MeasureFunc::Raw(|known_dimensions, available_space| { + const TEXT: &str = "HH\u{200b}HH\u{200b}HH\u{200b}HH"; + super::measure_standard_text( + known_dimensions, + available_space, + TEXT, + super::WritingMode::Horizontal, + Some(2f32), + ) + }), + ) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 20f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_row_stretch_fill_width.rs b/tests/generated/aspect_ratio_flex_row_stretch_fill_width.rs new file mode 100644 index 000000000..809b4d9e8 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_row_stretch_fill_width.rs @@ -0,0 +1,41 @@ +#[test] +fn aspect_ratio_flex_row_stretch_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(40f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 80f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, size.width); + assert_eq!(size.height, 40f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs b/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs new file mode 100644 index 000000000..ddddeee6f --- /dev/null +++ b/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs @@ -0,0 +1,42 @@ +#[test] +fn aspect_ratio_leaf_fill_min_width_percent() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) }, + aspect_ratio: Some(2f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + align_items: Some(taffy::style::AlignItems::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index d7d1bf716..07b2f9d95 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -118,6 +118,10 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_column_stretch_fill_height; +mod aspect_ratio_flex_column_stretch_fill_max_height; +mod aspect_ratio_flex_column_stretch_fill_max_width; +mod aspect_ratio_flex_column_stretch_fill_width; mod aspect_ratio_flex_row_fill_height; mod aspect_ratio_flex_row_fill_max_height; mod aspect_ratio_flex_row_fill_max_width; @@ -125,6 +129,10 @@ mod aspect_ratio_flex_row_fill_min_height; mod aspect_ratio_flex_row_fill_min_width; mod aspect_ratio_flex_row_fill_width; mod aspect_ratio_flex_row_fill_width_flex; +mod aspect_ratio_flex_row_stretch_fill_height; +mod aspect_ratio_flex_row_stretch_fill_max_height; +mod aspect_ratio_flex_row_stretch_fill_max_width; +mod aspect_ratio_flex_row_stretch_fill_width; mod aspect_ratio_grid_child_fill_content_height; mod aspect_ratio_grid_child_fill_content_width; mod aspect_ratio_leaf_fill_height; @@ -132,6 +140,7 @@ mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; +mod aspect_ratio_leaf_fill_min_width_percent; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; From a3895d5e6744ad76b0209427757db3905e9de300 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 5 Jan 2023 01:10:25 +0000 Subject: [PATCH 18/40] Apply aspect ratio to absolute children of flex container --- ...ct_ratio_flex_column_percent_fill_width.rs | 33 +++++++++++++ ...spect_ratio_leaf_fill_min_width_percent.rs | 27 ----------- benches/generated/mod.rs | 4 +- src/compute/flexbox.rs | 13 +++-- ...ratio_flex_column_absolute_fill_width.html | 17 +++++++ ..._ratio_flex_column_percent_fill_width.html | 17 +++++++ ...ct_ratio_flex_column_percent_fill_width.rs | 48 +++++++++++++++++++ ...spect_ratio_leaf_fill_min_width_percent.rs | 42 ---------------- tests/generated/mod.rs | 2 +- 9 files changed, 128 insertions(+), 75 deletions(-) create mode 100644 benches/generated/aspect_ratio_flex_column_percent_fill_width.rs delete mode 100644 benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs create mode 100644 test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html create mode 100644 test_fixtures/aspect_ratio_flex_column_percent_fill_width.html create mode 100644 tests/generated/aspect_ratio_flex_column_percent_fill_width.rs delete mode 100644 tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs diff --git a/benches/generated/aspect_ratio_flex_column_percent_fill_width.rs b/benches/generated/aspect_ratio_flex_column_percent_fill_width.rs new file mode 100644 index 000000000..3c2c0401b --- /dev/null +++ b/benches/generated/aspect_ratio_flex_column_percent_fill_width.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(1280f32), + height: taffy::style::Dimension::Points(720f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs b/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs deleted file mode 100644 index 651028550..000000000 --- a/benches/generated/aspect_ratio_leaf_fill_min_width_percent.rs +++ /dev/null @@ -1,27 +0,0 @@ -pub fn compute() { - #[allow(unused_imports)] - use taffy::prelude::*; - let mut taffy = taffy::Taffy::new(); - let node0 = taffy - .new_leaf(taffy::style::Style { - min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) }, - aspect_ratio: Some(2f32), - ..Default::default() - }) - .unwrap(); - let node = taffy - .new_with_children( - taffy::style::Style { - display: taffy::style::Display::Grid, - align_items: Some(taffy::style::AlignItems::Start), - size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(100f32), - height: taffy::style::Dimension::Points(100f32), - }, - ..Default::default() - }, - &[node0], - ) - .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); -} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 85acf9dc0..4194383f2 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -119,6 +119,7 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_column_percent_fill_width; mod aspect_ratio_flex_column_stretch_fill_height; mod aspect_ratio_flex_column_stretch_fill_max_height; mod aspect_ratio_flex_column_stretch_fill_max_width; @@ -141,7 +142,6 @@ mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; -mod aspect_ratio_leaf_fill_min_width_percent; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; @@ -676,6 +676,7 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_flex_column_fill_min_width::compute(); aspect_ratio_flex_column_fill_width::compute(); aspect_ratio_flex_column_fill_width_flex::compute(); + aspect_ratio_flex_column_percent_fill_width::compute(); aspect_ratio_flex_column_stretch_fill_height::compute(); aspect_ratio_flex_column_stretch_fill_max_height::compute(); aspect_ratio_flex_column_stretch_fill_max_width::compute(); @@ -698,7 +699,6 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_leaf_fill_max_width::compute(); aspect_ratio_leaf_fill_min_height::compute(); aspect_ratio_leaf_fill_min_width::compute(); - aspect_ratio_leaf_fill_min_width_percent::compute(); aspect_ratio_leaf_fill_width::compute(); aspect_ratio_leaf_overriden_by_explicit_sizes::compute(); aspect_ratio_leaf_overriden_by_explicit_sizes_flex::compute(); diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 85a80a909..65b2b55f5 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1622,9 +1622,13 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node let (start_cross, end_cross) = if constants.is_row { (top, bottom) } else { (start, end) }; // Compute known dimensions from min/max/inherent size styles - let style_size = child_style.size.maybe_resolve(constants.container_size); - let min_size = child_style.min_size.maybe_resolve(constants.container_size); - let max_size = child_style.max_size.maybe_resolve(constants.container_size); + let aspect_ratio = child_style.aspect_ratio; + let style_size = + child_style.size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); + let min_size = + child_style.min_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); + let max_size = + child_style.max_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); let mut known_dimensions = style_size.maybe_clamp(min_size, max_size); // Fill in width from left/right and height from top/bottom is appropriate @@ -1635,6 +1639,9 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node known_dimensions.height = Some(container_height.maybe_sub(top).maybe_sub(bottom)); } + // Re-apply aspect ratio + let known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); + let preliminary_size = compute_node_layout( tree, child, diff --git a/test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html b/test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html new file mode 100644 index 000000000..f65dfaad7 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html b/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html new file mode 100644 index 000000000..f65dfaad7 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_flex_column_percent_fill_width.rs b/tests/generated/aspect_ratio_flex_column_percent_fill_width.rs new file mode 100644 index 000000000..01c0515ea --- /dev/null +++ b/tests/generated/aspect_ratio_flex_column_percent_fill_width.rs @@ -0,0 +1,48 @@ +#[test] +fn aspect_ratio_flex_column_percent_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(1280f32), + height: taffy::style::Dimension::Points(720f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 1280f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 1280f32, size.width); + assert_eq!(size.height, 720f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 720f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 256f32, size.width); + assert_eq!(size.height, 85f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 85f32, size.height); + assert_eq!(location.x, 64f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 64f32, location.x); + assert_eq!(location.y, 36f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 36f32, location.y); +} diff --git a/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs b/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs deleted file mode 100644 index ddddeee6f..000000000 --- a/tests/generated/aspect_ratio_leaf_fill_min_width_percent.rs +++ /dev/null @@ -1,42 +0,0 @@ -#[test] -fn aspect_ratio_leaf_fill_min_width_percent() { - use slotmap::Key; - #[allow(unused_imports)] - use taffy::{layout::Layout, prelude::*}; - let mut taffy = taffy::Taffy::new(); - let node0 = taffy - .new_leaf(taffy::style::Style { - min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.5f32) }, - aspect_ratio: Some(2f32), - ..Default::default() - }) - .unwrap(); - let node = taffy - .new_with_children( - taffy::style::Style { - display: taffy::style::Display::Grid, - align_items: Some(taffy::style::AlignItems::Start), - size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(100f32), - height: taffy::style::Dimension::Points(100f32), - }, - ..Default::default() - }, - &[node0], - ) - .unwrap(); - taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); - println!("\nComputed tree:"); - taffy::debug::print_tree(&taffy, node); - println!(); - let Layout { size, location, .. } = taffy.layout(node).unwrap(); - assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); - assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); - assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); - assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); - let Layout { size, location, .. } = taffy.layout(node0).unwrap(); - assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); - assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); - assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); - assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); -} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 07b2f9d95..7f8f06338 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -118,6 +118,7 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; +mod aspect_ratio_flex_column_percent_fill_width; mod aspect_ratio_flex_column_stretch_fill_height; mod aspect_ratio_flex_column_stretch_fill_max_height; mod aspect_ratio_flex_column_stretch_fill_max_width; @@ -140,7 +141,6 @@ mod aspect_ratio_leaf_fill_max_height; mod aspect_ratio_leaf_fill_max_width; mod aspect_ratio_leaf_fill_min_height; mod aspect_ratio_leaf_fill_min_width; -mod aspect_ratio_leaf_fill_min_width_percent; mod aspect_ratio_leaf_fill_width; mod aspect_ratio_leaf_overriden_by_explicit_sizes; mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; From 63f12a2d88875bb304bd3b9542fd002ebc78ab28 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 5 Jan 2023 12:16:33 +0000 Subject: [PATCH 19/40] Remove duplicate test --- ...ct_ratio_flex_column_absolute_fill_width.rs} | 0 benches/generated/mod.rs | 4 ++-- ...ct_ratio_flex_column_percent_fill_width.html | 17 ----------------- ...ct_ratio_flex_column_absolute_fill_width.rs} | 2 +- tests/generated/mod.rs | 2 +- 5 files changed, 4 insertions(+), 21 deletions(-) rename benches/generated/{aspect_ratio_flex_column_percent_fill_width.rs => aspect_ratio_flex_column_absolute_fill_width.rs} (100%) delete mode 100644 test_fixtures/aspect_ratio_flex_column_percent_fill_width.html rename tests/generated/{aspect_ratio_flex_column_percent_fill_width.rs => aspect_ratio_flex_column_absolute_fill_width.rs} (97%) diff --git a/benches/generated/aspect_ratio_flex_column_percent_fill_width.rs b/benches/generated/aspect_ratio_flex_column_absolute_fill_width.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_column_percent_fill_width.rs rename to benches/generated/aspect_ratio_flex_column_absolute_fill_width.rs diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 4194383f2..e7da93473 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -112,6 +112,7 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_flex_column_absolute_fill_width; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; @@ -119,7 +120,6 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; -mod aspect_ratio_flex_column_percent_fill_width; mod aspect_ratio_flex_column_stretch_fill_height; mod aspect_ratio_flex_column_stretch_fill_max_height; mod aspect_ratio_flex_column_stretch_fill_max_width; @@ -669,6 +669,7 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); + aspect_ratio_flex_column_absolute_fill_width::compute(); aspect_ratio_flex_column_fill_height::compute(); aspect_ratio_flex_column_fill_max_height::compute(); aspect_ratio_flex_column_fill_max_width::compute(); @@ -676,7 +677,6 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_flex_column_fill_min_width::compute(); aspect_ratio_flex_column_fill_width::compute(); aspect_ratio_flex_column_fill_width_flex::compute(); - aspect_ratio_flex_column_percent_fill_width::compute(); aspect_ratio_flex_column_stretch_fill_height::compute(); aspect_ratio_flex_column_stretch_fill_max_height::compute(); aspect_ratio_flex_column_stretch_fill_max_width::compute(); diff --git a/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html b/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html deleted file mode 100644 index f65dfaad7..000000000 --- a/test_fixtures/aspect_ratio_flex_column_percent_fill_width.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - Test description - - - - -
-
-
- - - \ No newline at end of file diff --git a/tests/generated/aspect_ratio_flex_column_percent_fill_width.rs b/tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_column_percent_fill_width.rs rename to tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs index 01c0515ea..dde047ee5 100644 --- a/tests/generated/aspect_ratio_flex_column_percent_fill_width.rs +++ b/tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_column_percent_fill_width() { +fn aspect_ratio_flex_column_absolute_fill_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 7f8f06338..424d5a394 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -111,6 +111,7 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; +mod aspect_ratio_flex_column_absolute_fill_width; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; @@ -118,7 +119,6 @@ mod aspect_ratio_flex_column_fill_min_height; mod aspect_ratio_flex_column_fill_min_width; mod aspect_ratio_flex_column_fill_width; mod aspect_ratio_flex_column_fill_width_flex; -mod aspect_ratio_flex_column_percent_fill_width; mod aspect_ratio_flex_column_stretch_fill_height; mod aspect_ratio_flex_column_stretch_fill_max_height; mod aspect_ratio_flex_column_stretch_fill_max_width; From 9a81357364c6002addb22c1b06da08403e5fdaff Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Thu, 5 Jan 2023 12:26:54 +0000 Subject: [PATCH 20/40] Namespace grid aspect ratio tests under grid --- ...aspect_ratio_child_fill_content_height.rs} | 0 ..._aspect_ratio_child_fill_content_width.rs} | 0 ...=> grid_aspect_ratio_fill_child_height.rs} | 0 ...rid_aspect_ratio_fill_child_max_height.rs} | 0 ...grid_aspect_ratio_fill_child_max_width.rs} | 0 ...rid_aspect_ratio_fill_child_min_height.rs} | 0 ...grid_aspect_ratio_fill_child_min_width.rs} | 0 ... => grid_aspect_ratio_fill_child_width.rs} | 0 ...pect_ratio_overriden_by_explicit_sizes.rs} | 0 ...ratio_overriden_by_explicit_sizes_flex.rs} | 0 benches/generated/mod.rs | 60 ++++++++++++------- ...pect_ratio_child_fill_content_height.html} | 0 ...spect_ratio_child_fill_content_width.html} | 0 ... grid_aspect_ratio_fill_child_height.html} | 0 ...d_aspect_ratio_fill_child_max_height.html} | 0 ...id_aspect_ratio_fill_child_max_width.html} | 0 ...d_aspect_ratio_fill_child_min_height.html} | 0 ...id_aspect_ratio_fill_child_min_width.html} | 0 ...> grid_aspect_ratio_fill_child_width.html} | 0 ...ct_ratio_overriden_by_explicit_sizes.html} | 0 ...tio_overriden_by_explicit_sizes_flex.html} | 0 ...aspect_ratio_child_fill_content_height.rs} | 2 +- ..._aspect_ratio_child_fill_content_width.rs} | 2 +- ...=> grid_aspect_ratio_fill_child_height.rs} | 2 +- ...rid_aspect_ratio_fill_child_max_height.rs} | 2 +- ...grid_aspect_ratio_fill_child_max_width.rs} | 2 +- ...rid_aspect_ratio_fill_child_min_height.rs} | 2 +- ...grid_aspect_ratio_fill_child_min_width.rs} | 2 +- ... => grid_aspect_ratio_fill_child_width.rs} | 2 +- ...pect_ratio_overriden_by_explicit_sizes.rs} | 2 +- ...ratio_overriden_by_explicit_sizes_flex.rs} | 2 +- tests/generated/mod.rs | 30 ++++++---- 32 files changed, 70 insertions(+), 40 deletions(-) rename benches/generated/{aspect_ratio_grid_child_fill_content_height.rs => grid_aspect_ratio_child_fill_content_height.rs} (100%) rename benches/generated/{aspect_ratio_grid_child_fill_content_width.rs => grid_aspect_ratio_child_fill_content_width.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_height.rs => grid_aspect_ratio_fill_child_height.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_max_height.rs => grid_aspect_ratio_fill_child_max_height.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_max_width.rs => grid_aspect_ratio_fill_child_max_width.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_min_height.rs => grid_aspect_ratio_fill_child_min_height.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_min_width.rs => grid_aspect_ratio_fill_child_min_width.rs} (100%) rename benches/generated/{aspect_ratio_leaf_fill_width.rs => grid_aspect_ratio_fill_child_width.rs} (100%) rename benches/generated/{aspect_ratio_leaf_overriden_by_explicit_sizes.rs => grid_aspect_ratio_overriden_by_explicit_sizes.rs} (100%) rename benches/generated/{aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs => grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs} (100%) rename test_fixtures/{aspect_ratio_grid_child_fill_content_height.html => grid_aspect_ratio_child_fill_content_height.html} (100%) rename test_fixtures/{aspect_ratio_grid_child_fill_content_width.html => grid_aspect_ratio_child_fill_content_width.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_height.html => grid_aspect_ratio_fill_child_height.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_max_height.html => grid_aspect_ratio_fill_child_max_height.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_max_width.html => grid_aspect_ratio_fill_child_max_width.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_min_height.html => grid_aspect_ratio_fill_child_min_height.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_min_width.html => grid_aspect_ratio_fill_child_min_width.html} (100%) rename test_fixtures/{aspect_ratio_leaf_fill_width.html => grid_aspect_ratio_fill_child_width.html} (100%) rename test_fixtures/{aspect_ratio_leaf_overriden_by_explicit_sizes.html => grid_aspect_ratio_overriden_by_explicit_sizes.html} (100%) rename test_fixtures/{aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html => grid_aspect_ratio_overriden_by_explicit_sizes_flex.html} (100%) rename tests/generated/{aspect_ratio_grid_child_fill_content_height.rs => grid_aspect_ratio_child_fill_content_height.rs} (98%) rename tests/generated/{aspect_ratio_grid_child_fill_content_width.rs => grid_aspect_ratio_child_fill_content_width.rs} (98%) rename tests/generated/{aspect_ratio_leaf_fill_height.rs => grid_aspect_ratio_fill_child_height.rs} (97%) rename tests/generated/{aspect_ratio_leaf_fill_max_height.rs => grid_aspect_ratio_fill_child_max_height.rs} (98%) rename tests/generated/{aspect_ratio_leaf_fill_max_width.rs => grid_aspect_ratio_fill_child_max_width.rs} (98%) rename tests/generated/{aspect_ratio_leaf_fill_min_height.rs => grid_aspect_ratio_fill_child_min_height.rs} (97%) rename tests/generated/{aspect_ratio_leaf_fill_min_width.rs => grid_aspect_ratio_fill_child_min_width.rs} (98%) rename tests/generated/{aspect_ratio_leaf_fill_width.rs => grid_aspect_ratio_fill_child_width.rs} (98%) rename tests/generated/{aspect_ratio_leaf_overriden_by_explicit_sizes.rs => grid_aspect_ratio_overriden_by_explicit_sizes.rs} (97%) rename tests/generated/{aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs => grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs} (97%) diff --git a/benches/generated/aspect_ratio_grid_child_fill_content_height.rs b/benches/generated/grid_aspect_ratio_child_fill_content_height.rs similarity index 100% rename from benches/generated/aspect_ratio_grid_child_fill_content_height.rs rename to benches/generated/grid_aspect_ratio_child_fill_content_height.rs diff --git a/benches/generated/aspect_ratio_grid_child_fill_content_width.rs b/benches/generated/grid_aspect_ratio_child_fill_content_width.rs similarity index 100% rename from benches/generated/aspect_ratio_grid_child_fill_content_width.rs rename to benches/generated/grid_aspect_ratio_child_fill_content_width.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_height.rs b/benches/generated/grid_aspect_ratio_fill_child_height.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_height.rs rename to benches/generated/grid_aspect_ratio_fill_child_height.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_max_height.rs b/benches/generated/grid_aspect_ratio_fill_child_max_height.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_max_height.rs rename to benches/generated/grid_aspect_ratio_fill_child_max_height.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_max_width.rs b/benches/generated/grid_aspect_ratio_fill_child_max_width.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_max_width.rs rename to benches/generated/grid_aspect_ratio_fill_child_max_width.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_min_height.rs b/benches/generated/grid_aspect_ratio_fill_child_min_height.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_min_height.rs rename to benches/generated/grid_aspect_ratio_fill_child_min_height.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_min_width.rs b/benches/generated/grid_aspect_ratio_fill_child_min_width.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_min_width.rs rename to benches/generated/grid_aspect_ratio_fill_child_min_width.rs diff --git a/benches/generated/aspect_ratio_leaf_fill_width.rs b/benches/generated/grid_aspect_ratio_fill_child_width.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_fill_width.rs rename to benches/generated/grid_aspect_ratio_fill_child_width.rs diff --git a/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs b/benches/generated/grid_aspect_ratio_overriden_by_explicit_sizes.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs rename to benches/generated/grid_aspect_ratio_overriden_by_explicit_sizes.rs diff --git a/benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs b/benches/generated/grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs similarity index 100% rename from benches/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs rename to benches/generated/grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index e7da93473..145c4d4bc 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -135,16 +135,6 @@ mod aspect_ratio_flex_row_stretch_fill_height; mod aspect_ratio_flex_row_stretch_fill_max_height; mod aspect_ratio_flex_row_stretch_fill_max_width; mod aspect_ratio_flex_row_stretch_fill_width; -mod aspect_ratio_grid_child_fill_content_height; -mod aspect_ratio_grid_child_fill_content_width; -mod aspect_ratio_leaf_fill_height; -mod aspect_ratio_leaf_fill_max_height; -mod aspect_ratio_leaf_fill_max_width; -mod aspect_ratio_leaf_fill_min_height; -mod aspect_ratio_leaf_fill_min_width; -mod aspect_ratio_leaf_fill_width; -mod aspect_ratio_leaf_overriden_by_explicit_sizes; -mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; mod border_center_child; mod border_flex_child; mod border_no_child; @@ -309,6 +299,26 @@ mod grid_align_items_sized_stretch; #[cfg(feature = "grid")] mod grid_align_self_sized_all; #[cfg(feature = "grid")] +mod grid_aspect_ratio_child_fill_content_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_child_fill_content_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_max_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_max_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_min_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_min_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_overriden_by_explicit_sizes; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_overriden_by_explicit_sizes_flex; +#[cfg(feature = "grid")] mod grid_auto_columns_fixed_width; #[cfg(feature = "grid")] mod grid_auto_fill_fixed_size; @@ -692,16 +702,6 @@ fn benchmark(c: &mut Criterion) { aspect_ratio_flex_row_stretch_fill_max_height::compute(); aspect_ratio_flex_row_stretch_fill_max_width::compute(); aspect_ratio_flex_row_stretch_fill_width::compute(); - aspect_ratio_grid_child_fill_content_height::compute(); - aspect_ratio_grid_child_fill_content_width::compute(); - aspect_ratio_leaf_fill_height::compute(); - aspect_ratio_leaf_fill_max_height::compute(); - aspect_ratio_leaf_fill_max_width::compute(); - aspect_ratio_leaf_fill_min_height::compute(); - aspect_ratio_leaf_fill_min_width::compute(); - aspect_ratio_leaf_fill_width::compute(); - aspect_ratio_leaf_overriden_by_explicit_sizes::compute(); - aspect_ratio_leaf_overriden_by_explicit_sizes_flex::compute(); border_center_child::compute(); border_flex_child::compute(); border_no_child::compute(); @@ -866,6 +866,26 @@ fn benchmark(c: &mut Criterion) { #[cfg(feature = "grid")] grid_align_self_sized_all::compute(); #[cfg(feature = "grid")] + grid_aspect_ratio_child_fill_content_height::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_child_fill_content_width::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_height::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_max_height::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_max_width::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_min_height::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_min_width::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_fill_child_width::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_overriden_by_explicit_sizes::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_overriden_by_explicit_sizes_flex::compute(); + #[cfg(feature = "grid")] grid_auto_columns_fixed_width::compute(); #[cfg(feature = "grid")] grid_auto_fill_fixed_size::compute(); diff --git a/test_fixtures/aspect_ratio_grid_child_fill_content_height.html b/test_fixtures/grid_aspect_ratio_child_fill_content_height.html similarity index 100% rename from test_fixtures/aspect_ratio_grid_child_fill_content_height.html rename to test_fixtures/grid_aspect_ratio_child_fill_content_height.html diff --git a/test_fixtures/aspect_ratio_grid_child_fill_content_width.html b/test_fixtures/grid_aspect_ratio_child_fill_content_width.html similarity index 100% rename from test_fixtures/aspect_ratio_grid_child_fill_content_width.html rename to test_fixtures/grid_aspect_ratio_child_fill_content_width.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_height.html b/test_fixtures/grid_aspect_ratio_fill_child_height.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_height.html rename to test_fixtures/grid_aspect_ratio_fill_child_height.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_max_height.html b/test_fixtures/grid_aspect_ratio_fill_child_max_height.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_max_height.html rename to test_fixtures/grid_aspect_ratio_fill_child_max_height.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_max_width.html b/test_fixtures/grid_aspect_ratio_fill_child_max_width.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_max_width.html rename to test_fixtures/grid_aspect_ratio_fill_child_max_width.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_min_height.html b/test_fixtures/grid_aspect_ratio_fill_child_min_height.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_min_height.html rename to test_fixtures/grid_aspect_ratio_fill_child_min_height.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_min_width.html b/test_fixtures/grid_aspect_ratio_fill_child_min_width.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_min_width.html rename to test_fixtures/grid_aspect_ratio_fill_child_min_width.html diff --git a/test_fixtures/aspect_ratio_leaf_fill_width.html b/test_fixtures/grid_aspect_ratio_fill_child_width.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_fill_width.html rename to test_fixtures/grid_aspect_ratio_fill_child_width.html diff --git a/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html b/test_fixtures/grid_aspect_ratio_overriden_by_explicit_sizes.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes.html rename to test_fixtures/grid_aspect_ratio_overriden_by_explicit_sizes.html diff --git a/test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html b/test_fixtures/grid_aspect_ratio_overriden_by_explicit_sizes_flex.html similarity index 100% rename from test_fixtures/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.html rename to test_fixtures/grid_aspect_ratio_overriden_by_explicit_sizes_flex.html diff --git a/tests/generated/aspect_ratio_grid_child_fill_content_height.rs b/tests/generated/grid_aspect_ratio_child_fill_content_height.rs similarity index 98% rename from tests/generated/aspect_ratio_grid_child_fill_content_height.rs rename to tests/generated/grid_aspect_ratio_child_fill_content_height.rs index 5f974ceb9..f62d70ffe 100644 --- a/tests/generated/aspect_ratio_grid_child_fill_content_height.rs +++ b/tests/generated/grid_aspect_ratio_child_fill_content_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_grid_child_fill_content_height() { +fn grid_aspect_ratio_child_fill_content_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_grid_child_fill_content_width.rs b/tests/generated/grid_aspect_ratio_child_fill_content_width.rs similarity index 98% rename from tests/generated/aspect_ratio_grid_child_fill_content_width.rs rename to tests/generated/grid_aspect_ratio_child_fill_content_width.rs index f859ada0d..acedf2436 100644 --- a/tests/generated/aspect_ratio_grid_child_fill_content_width.rs +++ b/tests/generated/grid_aspect_ratio_child_fill_content_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_grid_child_fill_content_width() { +fn grid_aspect_ratio_child_fill_content_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_height.rs b/tests/generated/grid_aspect_ratio_fill_child_height.rs similarity index 97% rename from tests/generated/aspect_ratio_leaf_fill_height.rs rename to tests/generated/grid_aspect_ratio_fill_child_height.rs index b9659d606..c97e77781 100644 --- a/tests/generated/aspect_ratio_leaf_fill_height.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_height() { +fn grid_aspect_ratio_fill_child_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_max_height.rs b/tests/generated/grid_aspect_ratio_fill_child_max_height.rs similarity index 98% rename from tests/generated/aspect_ratio_leaf_fill_max_height.rs rename to tests/generated/grid_aspect_ratio_fill_child_max_height.rs index 0a182eebe..d36031511 100644 --- a/tests/generated/aspect_ratio_leaf_fill_max_height.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_max_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_max_height() { +fn grid_aspect_ratio_fill_child_max_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_max_width.rs b/tests/generated/grid_aspect_ratio_fill_child_max_width.rs similarity index 98% rename from tests/generated/aspect_ratio_leaf_fill_max_width.rs rename to tests/generated/grid_aspect_ratio_fill_child_max_width.rs index 1ba057b6c..23d7c6bd6 100644 --- a/tests/generated/aspect_ratio_leaf_fill_max_width.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_max_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_max_width() { +fn grid_aspect_ratio_fill_child_max_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_min_height.rs b/tests/generated/grid_aspect_ratio_fill_child_min_height.rs similarity index 97% rename from tests/generated/aspect_ratio_leaf_fill_min_height.rs rename to tests/generated/grid_aspect_ratio_fill_child_min_height.rs index 0eefa4b52..d21f86188 100644 --- a/tests/generated/aspect_ratio_leaf_fill_min_height.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_min_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_min_height() { +fn grid_aspect_ratio_fill_child_min_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_min_width.rs b/tests/generated/grid_aspect_ratio_fill_child_min_width.rs similarity index 98% rename from tests/generated/aspect_ratio_leaf_fill_min_width.rs rename to tests/generated/grid_aspect_ratio_fill_child_min_width.rs index d005e4df0..75dfb6302 100644 --- a/tests/generated/aspect_ratio_leaf_fill_min_width.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_min_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_min_width() { +fn grid_aspect_ratio_fill_child_min_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_fill_width.rs b/tests/generated/grid_aspect_ratio_fill_child_width.rs similarity index 98% rename from tests/generated/aspect_ratio_leaf_fill_width.rs rename to tests/generated/grid_aspect_ratio_fill_child_width.rs index 231de24fb..45fabfdfe 100644 --- a/tests/generated/aspect_ratio_leaf_fill_width.rs +++ b/tests/generated/grid_aspect_ratio_fill_child_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_fill_width() { +fn grid_aspect_ratio_fill_child_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs b/tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes.rs similarity index 97% rename from tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs rename to tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes.rs index e42d61516..5778d3f89 100644 --- a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes.rs +++ b/tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_overriden_by_explicit_sizes() { +fn grid_aspect_ratio_overriden_by_explicit_sizes() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs b/tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs similarity index 97% rename from tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs rename to tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs index 193005b05..a6b546caf 100644 --- a/tests/generated/aspect_ratio_leaf_overriden_by_explicit_sizes_flex.rs +++ b/tests/generated/grid_aspect_ratio_overriden_by_explicit_sizes_flex.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_leaf_overriden_by_explicit_sizes_flex() { +fn grid_aspect_ratio_overriden_by_explicit_sizes_flex() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 424d5a394..fc6d8c775 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -134,16 +134,6 @@ mod aspect_ratio_flex_row_stretch_fill_height; mod aspect_ratio_flex_row_stretch_fill_max_height; mod aspect_ratio_flex_row_stretch_fill_max_width; mod aspect_ratio_flex_row_stretch_fill_width; -mod aspect_ratio_grid_child_fill_content_height; -mod aspect_ratio_grid_child_fill_content_width; -mod aspect_ratio_leaf_fill_height; -mod aspect_ratio_leaf_fill_max_height; -mod aspect_ratio_leaf_fill_max_width; -mod aspect_ratio_leaf_fill_min_height; -mod aspect_ratio_leaf_fill_min_width; -mod aspect_ratio_leaf_fill_width; -mod aspect_ratio_leaf_overriden_by_explicit_sizes; -mod aspect_ratio_leaf_overriden_by_explicit_sizes_flex; mod border_center_child; mod border_flex_child; mod border_no_child; @@ -308,6 +298,26 @@ mod grid_align_items_sized_stretch; #[cfg(feature = "grid")] mod grid_align_self_sized_all; #[cfg(feature = "grid")] +mod grid_aspect_ratio_child_fill_content_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_child_fill_content_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_max_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_max_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_min_height; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_min_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_fill_child_width; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_overriden_by_explicit_sizes; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_overriden_by_explicit_sizes_flex; +#[cfg(feature = "grid")] mod grid_auto_columns_fixed_width; #[cfg(feature = "grid")] mod grid_auto_fill_fixed_size; From 1dcf6dbdaecd2ce4479c99b639f87dbdf484921a Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 7 Jan 2023 14:40:46 +0000 Subject: [PATCH 21/40] Absolute positioning: Apply aspect ratio to inset-generated width before generating height from inset --- src/compute/flexbox.rs | 9 +++++---- src/compute/grid/alignment.rs | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 65b2b55f5..822336030 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1631,17 +1631,18 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node child_style.max_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); let mut known_dimensions = style_size.maybe_clamp(min_size, max_size); - // Fill in width from left/right and height from top/bottom is appropriate + // Fill in width from left/right and reapply aspect ratio if appropriate if known_dimensions.width.is_none() && start.is_some() && end.is_some() { known_dimensions.width = Some(container_width.maybe_sub(start).maybe_sub(end)); + known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); } + + // Fill in height from top/bottom and reapply aspect ratio if appropriate if known_dimensions.height.is_none() && top.is_some() && bottom.is_some() { known_dimensions.height = Some(container_height.maybe_sub(top).maybe_sub(bottom)); + known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); } - // Re-apply aspect ratio - let known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); - let preliminary_size = compute_node_layout( tree, child, diff --git a/src/compute/grid/alignment.rs b/src/compute/grid/alignment.rs index d645cf671..fd796c93e 100644 --- a/src/compute/grid/alignment.rs +++ b/src/compute/grid/alignment.rs @@ -145,7 +145,10 @@ pub(super) fn align_and_position_item( None }); - let height = inherent_size.height.or_else(|| { + // Reapply aspect ratio after stretch and absolute position width adjustments + let Size { width, height } = Size { width, height: inherent_size.height }.maybe_apply_aspect_ratio(aspect_ratio); + + let height = height.or_else(|| { if position == Position::Absolute { if let (Some(top), Some(bottom)) = (inset_vertical.start, inset_vertical.end) { return Some(f32_max(grid_area_size.height - top - bottom, 0.0)); @@ -168,8 +171,7 @@ pub(super) fn align_and_position_item( None }); - - // Reapply aspect ratio after stretch and absolute position adjustments + // Reapply aspect ratio after stretch and absolute position height adjustments let Size { width, height } = Size { width, height }.maybe_apply_aspect_ratio(aspect_ratio); // Layout node From 8b92331390764110199ecc564c56904a69cfaca6 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 7 Jan 2023 14:57:09 +0000 Subject: [PATCH 22/40] Add tests for aspect ratio height/width for absolutely positioned nodes --- ...ct_ratio_overrides_height_of_full_inset.rs | 32 +++++++++++++ ...aspect_ratio_flex_absolute_fill_height.rs} | 6 +-- ...io_flex_absolute_fill_height_from_inset.rs | 32 +++++++++++++ .../aspect_ratio_flex_absolute_fill_width.rs | 33 +++++++++++++ ...tio_flex_absolute_fill_width_from_inset.rs | 32 +++++++++++++ ...io_flex_absolute_height_overrides_inset.rs | 33 +++++++++++++ ...tio_flex_absolute_width_overrides_inset.rs | 33 +++++++++++++ ...ct_ratio_overrides_height_of_full_inset.rs | 32 +++++++++++++ benches/generated/mod.rs | 20 +++++++- ..._ratio_overrides_height_of_full_inset.html | 17 +++++++ ...pect_ratio_flex_absolute_fill_height.html} | 4 +- ..._flex_absolute_fill_height_from_inset.html | 17 +++++++ ...aspect_ratio_flex_absolute_fill_width.html | 17 +++++++ ...o_flex_absolute_fill_width_from_inset.html | 17 +++++++ ..._flex_absolute_height_overrides_inset.html | 17 +++++++ ...o_flex_absolute_width_overrides_inset.html | 17 +++++++ ..._ratio_overrides_height_of_full_inset.html | 17 +++++++ ...ct_ratio_overrides_height_of_full_inset.rs | 47 ++++++++++++++++++ ...aspect_ratio_flex_absolute_fill_height.rs} | 20 ++++---- ...io_flex_absolute_fill_height_from_inset.rs | 47 ++++++++++++++++++ .../aspect_ratio_flex_absolute_fill_width.rs | 48 +++++++++++++++++++ ...tio_flex_absolute_fill_width_from_inset.rs | 47 ++++++++++++++++++ ...io_flex_absolute_height_overrides_inset.rs | 48 +++++++++++++++++++ ...tio_flex_absolute_width_overrides_inset.rs | 48 +++++++++++++++++++ ...ct_ratio_overrides_height_of_full_inset.rs | 47 ++++++++++++++++++ tests/generated/mod.rs | 10 +++- 26 files changed, 720 insertions(+), 18 deletions(-) create mode 100644 benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs rename benches/generated/{aspect_ratio_flex_column_absolute_fill_width.rs => aspect_ratio_flex_absolute_fill_height.rs} (85%) create mode 100644 benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs create mode 100644 benches/generated/aspect_ratio_flex_absolute_fill_width.rs create mode 100644 benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs create mode 100644 benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs create mode 100644 benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs create mode 100644 benches/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs create mode 100644 test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html rename test_fixtures/{aspect_ratio_flex_column_absolute_fill_width.html => aspect_ratio_flex_absolute_fill_height.html} (68%) create mode 100644 test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html create mode 100644 test_fixtures/aspect_ratio_flex_absolute_fill_width.html create mode 100644 test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html create mode 100644 test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html create mode 100644 test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html create mode 100644 test_fixtures/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.html create mode 100644 tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs rename tests/generated/{aspect_ratio_flex_column_absolute_fill_width.rs => aspect_ratio_flex_absolute_fill_height.rs} (62%) create mode 100644 tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs create mode 100644 tests/generated/aspect_ratio_flex_absolute_fill_width.rs create mode 100644 tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs create mode 100644 tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs create mode 100644 tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs create mode 100644 tests/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs new file mode 100644 index 000000000..ca171c053 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: taffy::style::LengthPercentageAuto::Percent(0.05f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_column_absolute_fill_width.rs b/benches/generated/aspect_ratio_flex_absolute_fill_height.rs similarity index 85% rename from benches/generated/aspect_ratio_flex_column_absolute_fill_width.rs rename to benches/generated/aspect_ratio_flex_absolute_fill_height.rs index 3c2c0401b..bd566796a 100644 --- a/benches/generated/aspect_ratio_flex_column_absolute_fill_width.rs +++ b/benches/generated/aspect_ratio_flex_absolute_fill_height.rs @@ -5,7 +5,7 @@ pub fn compute() { let node0 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, - size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), height: auto() }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() }, aspect_ratio: Some(3f32), inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Percent(0.05f32), @@ -21,8 +21,8 @@ pub fn compute() { taffy::style::Style { display: taffy::style::Display::Flex, size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(1280f32), - height: taffy::style::Dimension::Points(720f32), + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), }, ..Default::default() }, diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs b/benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs new file mode 100644 index 000000000..cc8fef7e4 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_width.rs b/benches/generated/aspect_ratio_flex_absolute_fill_width.rs new file mode 100644 index 000000000..11070af81 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_fill_width.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.2f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs b/benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs new file mode 100644 index 000000000..44d0490b0 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs b/benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs new file mode 100644 index 000000000..694d0fcc4 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.1f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs b/benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs new file mode 100644 index 000000000..295697b68 --- /dev/null +++ b/benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.4f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/benches/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs new file mode 100644 index 000000000..bc264cd9e --- /dev/null +++ b/benches/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: taffy::style::LengthPercentageAuto::Percent(0.05f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 145c4d4bc..7a758af1e 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -112,7 +112,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_column_absolute_fill_width; +mod aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset; +mod aspect_ratio_flex_absolute_fill_height; +mod aspect_ratio_flex_absolute_fill_height_from_inset; +mod aspect_ratio_flex_absolute_fill_width; +mod aspect_ratio_flex_absolute_fill_width_from_inset; +mod aspect_ratio_flex_absolute_height_overrides_inset; +mod aspect_ratio_flex_absolute_width_overrides_inset; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; @@ -299,6 +305,8 @@ mod grid_align_items_sized_stretch; #[cfg(feature = "grid")] mod grid_align_self_sized_all; #[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset; +#[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_height; #[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_width; @@ -679,7 +687,13 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); - aspect_ratio_flex_column_absolute_fill_width::compute(); + aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset::compute(); + aspect_ratio_flex_absolute_fill_height::compute(); + aspect_ratio_flex_absolute_fill_height_from_inset::compute(); + aspect_ratio_flex_absolute_fill_width::compute(); + aspect_ratio_flex_absolute_fill_width_from_inset::compute(); + aspect_ratio_flex_absolute_height_overrides_inset::compute(); + aspect_ratio_flex_absolute_width_overrides_inset::compute(); aspect_ratio_flex_column_fill_height::compute(); aspect_ratio_flex_column_fill_max_height::compute(); aspect_ratio_flex_column_fill_max_width::compute(); @@ -866,6 +880,8 @@ fn benchmark(c: &mut Criterion) { #[cfg(feature = "grid")] grid_align_self_sized_all::compute(); #[cfg(feature = "grid")] + grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset::compute(); + #[cfg(feature = "grid")] grid_aspect_ratio_child_fill_content_height::compute(); #[cfg(feature = "grid")] grid_aspect_ratio_child_fill_content_width::compute(); diff --git a/test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html b/test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html new file mode 100644 index 000000000..b3510e54d --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html b/test_fixtures/aspect_ratio_flex_absolute_fill_height.html similarity index 68% rename from test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html rename to test_fixtures/aspect_ratio_flex_absolute_fill_height.html index f65dfaad7..8b681acf9 100644 --- a/test_fixtures/aspect_ratio_flex_column_absolute_fill_width.html +++ b/test_fixtures/aspect_ratio_flex_absolute_fill_height.html @@ -9,8 +9,8 @@ -
-
+
+
diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html b/test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html new file mode 100644 index 000000000..f38e94965 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_width.html b/test_fixtures/aspect_ratio_flex_absolute_fill_width.html new file mode 100644 index 000000000..f5e3d5e13 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_fill_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html b/test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html new file mode 100644 index 000000000..423325007 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html b/test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html new file mode 100644 index 000000000..75c82ed09 --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html b/test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html new file mode 100644 index 000000000..eb25a576b --- /dev/null +++ b/test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.html b/test_fixtures/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.html new file mode 100644 index 000000000..94b2c4a43 --- /dev/null +++ b/test_fixtures/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs new file mode 100644 index 000000000..204bafa12 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: taffy::style::LengthPercentageAuto::Percent(0.05f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 360f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 360f32, size.width); + assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 120f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs b/tests/generated/aspect_ratio_flex_absolute_fill_height.rs similarity index 62% rename from tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs rename to tests/generated/aspect_ratio_flex_absolute_fill_height.rs index dde047ee5..2b818698f 100644 --- a/tests/generated/aspect_ratio_flex_column_absolute_fill_width.rs +++ b/tests/generated/aspect_ratio_flex_absolute_fill_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_column_absolute_fill_width() { +fn aspect_ratio_flex_absolute_fill_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; @@ -7,7 +7,7 @@ fn aspect_ratio_flex_column_absolute_fill_width() { let node0 = taffy .new_leaf(taffy::style::Style { position: taffy::style::Position::Absolute, - size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.2f32), height: auto() }, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.5f32), height: auto() }, aspect_ratio: Some(3f32), inset: taffy::geometry::Rect { left: taffy::style::LengthPercentageAuto::Percent(0.05f32), @@ -23,8 +23,8 @@ fn aspect_ratio_flex_column_absolute_fill_width() { taffy::style::Style { display: taffy::style::Display::Flex, size: taffy::geometry::Size { - width: taffy::style::Dimension::Points(1280f32), - height: taffy::style::Dimension::Points(720f32), + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), }, ..Default::default() }, @@ -36,13 +36,13 @@ fn aspect_ratio_flex_column_absolute_fill_width() { taffy::debug::print_tree(&taffy, node); println!(); let Layout { size, location, .. } = taffy.layout(node).unwrap(); - assert_eq!(size.width, 1280f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 1280f32, size.width); - assert_eq!(size.height, 720f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 720f32, size.height); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); let Layout { size, location, .. } = taffy.layout(node0).unwrap(); - assert_eq!(size.width, 256f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 256f32, size.width); - assert_eq!(size.height, 85f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 85f32, size.height); - assert_eq!(location.x, 64f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 64f32, location.x); - assert_eq!(location.y, 36f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 36f32, location.y); + assert_eq!(size.width, 200f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 200f32, size.width); + assert_eq!(size.height, 67f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 67f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); } diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs b/tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs new file mode 100644 index 000000000..df896a853 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn aspect_ratio_flex_absolute_fill_height_from_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 320f32, size.width); + assert_eq!(size.height, 107f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 107f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_width.rs b/tests/generated/aspect_ratio_flex_absolute_fill_width.rs new file mode 100644 index 000000000..eacc05c31 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_fill_width.rs @@ -0,0 +1,48 @@ +#[test] +fn aspect_ratio_flex_absolute_fill_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.2f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 180f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs b/tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs new file mode 100644 index 000000000..97b5340e3 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn aspect_ratio_flex_absolute_fill_width_from_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 180f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs b/tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs new file mode 100644 index 000000000..7cd5658fa --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs @@ -0,0 +1,48 @@ +#[test] +fn aspect_ratio_flex_absolute_height_overrides_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.1f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 90f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, location.y); +} diff --git a/tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs b/tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs new file mode 100644 index 000000000..749d6fa28 --- /dev/null +++ b/tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs @@ -0,0 +1,48 @@ +#[test] +fn aspect_ratio_flex_absolute_width_overrides_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.4f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 160f32, size.width); + assert_eq!(size.height, 53f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 53f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/tests/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs new file mode 100644 index 000000000..8cbb2425c --- /dev/null +++ b/tests/generated/grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.05f32), + right: taffy::style::LengthPercentageAuto::Percent(0.05f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.05f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 360f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 360f32, size.width); + assert_eq!(size.height, 120f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 120f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 20f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index fc6d8c775..64e5de16a 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -111,7 +111,13 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_column_absolute_fill_width; +mod aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset; +mod aspect_ratio_flex_absolute_fill_height; +mod aspect_ratio_flex_absolute_fill_height_from_inset; +mod aspect_ratio_flex_absolute_fill_width; +mod aspect_ratio_flex_absolute_fill_width_from_inset; +mod aspect_ratio_flex_absolute_height_overrides_inset; +mod aspect_ratio_flex_absolute_width_overrides_inset; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; @@ -298,6 +304,8 @@ mod grid_align_items_sized_stretch; #[cfg(feature = "grid")] mod grid_align_self_sized_all; #[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset; +#[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_height; #[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_width; From 5c66c230c225eca83e7514e27ab3a6cc401a39db Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 7 Jan 2023 15:15:47 +0000 Subject: [PATCH 23/40] Exclude hidden items from absolute positioning --- .../generated/display_none_absolute_child.rs | 36 ++++++++++++ .../display_none_with_position_absolute.rs | 29 ++++++++++ benches/generated/mod.rs | 4 ++ src/compute/flexbox.rs | 5 +- .../display_none_absolute_child.html | 18 ++++++ .../display_none_with_position_absolute.html | 17 ++++++ .../generated/display_none_absolute_child.rs | 56 +++++++++++++++++++ .../display_none_with_position_absolute.rs | 44 +++++++++++++++ tests/generated/mod.rs | 2 + 9 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 benches/generated/display_none_absolute_child.rs create mode 100644 benches/generated/display_none_with_position_absolute.rs create mode 100644 test_fixtures/display_none_absolute_child.html create mode 100644 test_fixtures/display_none_with_position_absolute.html create mode 100644 tests/generated/display_none_absolute_child.rs create mode 100644 tests/generated/display_none_with_position_absolute.rs diff --git a/benches/generated/display_none_absolute_child.rs b/benches/generated/display_none_absolute_child.rs new file mode 100644 index 000000000..31e0950f1 --- /dev/null +++ b/benches/generated/display_none_absolute_child.rs @@ -0,0 +1,36 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, ..Default::default() }).unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + display: taffy::style::Display::None, + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/display_none_with_position_absolute.rs b/benches/generated/display_none_with_position_absolute.rs new file mode 100644 index 000000000..b53a1f491 --- /dev/null +++ b/benches/generated/display_none_with_position_absolute.rs @@ -0,0 +1,29 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + display: taffy::style::Display::None, + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 7a758af1e..9c80294e7 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -148,10 +148,12 @@ mod border_stretch_child; mod child_min_max_width_flexing; mod container_with_unsized_child; mod display_none; +mod display_none_absolute_child; mod display_none_fixed_size; mod display_none_with_child; mod display_none_with_margin; mod display_none_with_position; +mod display_none_with_position_absolute; mod flex_basis_and_main_dimen_set_when_flexing; mod flex_basis_flex_grow_column; mod flex_basis_flex_grow_row; @@ -723,10 +725,12 @@ fn benchmark(c: &mut Criterion) { child_min_max_width_flexing::compute(); container_with_unsized_child::compute(); display_none::compute(); + display_none_absolute_child::compute(); display_none_fixed_size::compute(); display_none_with_child::compute(); display_none_with_margin::compute(); display_none_with_position::compute(); + display_none_with_position_absolute::compute(); flex_basis_and_main_dimen_set_when_flexing::compute(); flex_basis_flex_grow_column::compute(); flex_basis_flex_grow_row::compute(); diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 822336030..98b0e47d2 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1591,7 +1591,10 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node .children(node) .cloned() .enumerate() - .filter(|(_, child)| tree.style(*child).position == Position::Absolute) + .filter(|(_, child)| { + let style = tree.style(*child); + style.display != Display::None && style.position == Position::Absolute + }) .collect::>(); for (order, child) in candidates { diff --git a/test_fixtures/display_none_absolute_child.html b/test_fixtures/display_none_absolute_child.html new file mode 100644 index 000000000..fccdd23d3 --- /dev/null +++ b/test_fixtures/display_none_absolute_child.html @@ -0,0 +1,18 @@ + + + + + + + Test description + + + + +
+
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/display_none_with_position_absolute.html b/test_fixtures/display_none_with_position_absolute.html new file mode 100644 index 000000000..6d7eee4a6 --- /dev/null +++ b/test_fixtures/display_none_with_position_absolute.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/display_none_absolute_child.rs b/tests/generated/display_none_absolute_child.rs new file mode 100644 index 000000000..cebdddb25 --- /dev/null +++ b/tests/generated/display_none_absolute_child.rs @@ -0,0 +1,56 @@ +#[test] +fn display_none_absolute_child() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy.new_leaf(taffy::style::Style { flex_grow: 1f32, ..Default::default() }).unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + display: taffy::style::Display::None, + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(20f32), + height: taffy::style::Dimension::Points(20f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0, node1], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 0f32, location.y); +} diff --git a/tests/generated/display_none_with_position_absolute.rs b/tests/generated/display_none_with_position_absolute.rs new file mode 100644 index 000000000..d323b3911 --- /dev/null +++ b/tests/generated/display_none_with_position_absolute.rs @@ -0,0 +1,44 @@ +#[test] +fn display_none_with_position_absolute() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + display: taffy::style::Display::None, + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 0f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, size.width); + assert_eq!(size.height, 0f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 64e5de16a..221c5fb9e 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -147,10 +147,12 @@ mod border_stretch_child; mod child_min_max_width_flexing; mod container_with_unsized_child; mod display_none; +mod display_none_absolute_child; mod display_none_fixed_size; mod display_none_with_child; mod display_none_with_margin; mod display_none_with_position; +mod display_none_with_position_absolute; mod flex_basis_and_main_dimen_set_when_flexing; mod flex_basis_flex_grow_column; mod flex_basis_flex_grow_row; From b147f78ee7cc5513c897f45a6d6570b636495fbb Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 7 Jan 2023 21:40:28 +0000 Subject: [PATCH 24/40] Apply min/max sizes when finally positioning grid items --- src/compute/grid/alignment.rs | 44 ++++++++++++++--------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/compute/grid/alignment.rs b/src/compute/grid/alignment.rs index fd796c93e..797f9cf33 100644 --- a/src/compute/grid/alignment.rs +++ b/src/compute/grid/alignment.rs @@ -140,7 +140,7 @@ pub(super) fn align_and_position_item( && alignment_styles.horizontal == AlignSelf::Stretch && position != Position::Absolute { - return Some(grid_area_minus_item_margins_size.width.maybe_min(max_size.width).maybe_max(min_size.width)); + return Some(grid_area_minus_item_margins_size.width); } None @@ -164,9 +164,7 @@ pub(super) fn align_and_position_item( && alignment_styles.vertical == AlignSelf::Stretch && position != Position::Absolute { - return Some( - grid_area_minus_item_margins_size.height.maybe_min(max_size.height).maybe_max(min_size.height), - ); + return Some(grid_area_minus_item_margins_size.height); } None @@ -174,6 +172,9 @@ pub(super) fn align_and_position_item( // Reapply aspect ratio after stretch and absolute position height adjustments let Size { width, height } = Size { width, height }.maybe_apply_aspect_ratio(aspect_ratio); + // Clamp size by min and max width/height + let Size { width, height } = Size { width, height }.maybe_clamp(min_size, max_size); + // Layout node let measured_size = compute_node_layout( tree, @@ -185,20 +186,21 @@ pub(super) fn align_and_position_item( SizingMode::InherentSize, ); - let (x, width) = align_and_size_item_within_area( + // Resolve final size + let Size { width, height } = Size { width, height }.unwrap_or(measured_size).maybe_clamp(min_size, max_size); + + let x = align_item_within_area( Line { start: grid_area.left, end: grid_area.right }, justify_self.unwrap_or(alignment_styles.horizontal), width, - measured_size.width, position, inset_horizontal, margin.horizontal_components(), ); - let (y, height) = align_and_size_item_within_area( + let y = align_item_within_area( Line { start: grid_area.top, end: grid_area.bottom }, align_self.unwrap_or(alignment_styles.vertical), height, - measured_size.height, position, inset_vertical, margin.vertical_components(), @@ -208,19 +210,18 @@ pub(super) fn align_and_position_item( } /// Align and size a grid item along a single axis -pub(super) fn align_and_size_item_within_area( +pub(super) fn align_item_within_area( grid_area: Line, alignment_style: AlignSelf, - style_size: Option, - measured_size: f32, + resolved_size: f32, position: Position, inset: Line>, margin: Line>, -) -> (f32, f32) { +) -> f32 { // Calculate grid area dimension in the axis let non_auto_margin = Line { start: margin.start.unwrap_or(0.0), end: margin.end.unwrap_or(0.0) }; let grid_area_size = f32_max(grid_area.end - grid_area.start, 0.0); - let free_space = f32_max(grid_area_size - style_size.unwrap_or(measured_size) - non_auto_margin.sum(), 0.0); + let free_space = f32_max(grid_area_size - resolved_size - non_auto_margin.sum(), 0.0); // Expand auto margins to fill available space let auto_margin_count = margin.start.is_none() as u8 + margin.end.is_none() as u8; @@ -228,20 +229,11 @@ pub(super) fn align_and_size_item_within_area( let resolved_margin = Line { start: margin.start.unwrap_or(auto_margin_size), end: margin.end.unwrap_or(auto_margin_size) }; - // Compute size in the axis - let size = style_size.unwrap_or_else(|| { - if alignment_style == AlignItems::Stretch && position != Position::Absolute { - f32_max(grid_area_size - resolved_margin.sum(), measured_size) - } else { - measured_size - } - }); - // Compute offset in the axis let alignment_based_offset = match alignment_style { AlignSelf::Start => resolved_margin.start, - AlignSelf::End => grid_area_size - size - resolved_margin.end, - AlignSelf::Center => (grid_area_size - size + resolved_margin.start - resolved_margin.end) / 2.0, + AlignSelf::End => grid_area_size - resolved_size - resolved_margin.end, + AlignSelf::Center => (grid_area_size - resolved_size + resolved_margin.start - resolved_margin.end) / 2.0, // TODO: Add support for baseline alignment. For now we treat it as "start". AlignSelf::Baseline => resolved_margin.start, AlignSelf::Stretch => resolved_margin.start, @@ -251,7 +243,7 @@ pub(super) fn align_and_size_item_within_area( if let Some(start) = inset.start { start + non_auto_margin.start } else if let Some(end) = inset.end { - grid_area_size - end - size - non_auto_margin.end + grid_area_size - end - resolved_size - non_auto_margin.end } else { alignment_based_offset } @@ -264,5 +256,5 @@ pub(super) fn align_and_size_item_within_area( start += inset.start.or(inset.end.map(|pos| -pos)).unwrap_or(0.0); } - (start, size) + start } From c20a307d1d8eb447c42949bdc60c600d5a33f2f2 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 00:10:15 +0000 Subject: [PATCH 25/40] Add tests for interaction between inset and aspect ratio for absolutely positioned grid children --- ...t_ratio_absolute_fill_height_from_inset.rs | 32 +++++++++++++ ...ct_ratio_absolute_fill_width_from_inset.rs | 32 +++++++++++++ ...t_ratio_absolute_height_overrides_inset.rs | 33 +++++++++++++ ...ct_ratio_absolute_width_overrides_inset.rs | 33 +++++++++++++ benches/generated/mod.rs | 16 +++++++ ...ratio_absolute_fill_height_from_inset.html | 17 +++++++ ..._ratio_absolute_fill_width_from_inset.html | 17 +++++++ ...ratio_absolute_height_overrides_inset.html | 17 +++++++ ..._ratio_absolute_width_overrides_inset.html | 17 +++++++ ...t_ratio_absolute_fill_height_from_inset.rs | 47 ++++++++++++++++++ ...ct_ratio_absolute_fill_width_from_inset.rs | 47 ++++++++++++++++++ ...t_ratio_absolute_height_overrides_inset.rs | 48 +++++++++++++++++++ ...ct_ratio_absolute_width_overrides_inset.rs | 48 +++++++++++++++++++ tests/generated/mod.rs | 8 ++++ 14 files changed, 412 insertions(+) create mode 100644 benches/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs create mode 100644 benches/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs create mode 100644 benches/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs create mode 100644 benches/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs create mode 100644 test_fixtures/grid_aspect_ratio_absolute_fill_height_from_inset.html create mode 100644 test_fixtures/grid_aspect_ratio_absolute_fill_width_from_inset.html create mode 100644 test_fixtures/grid_aspect_ratio_absolute_height_overrides_inset.html create mode 100644 test_fixtures/grid_aspect_ratio_absolute_width_overrides_inset.html create mode 100644 tests/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs create mode 100644 tests/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs create mode 100644 tests/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs create mode 100644 tests/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs diff --git a/benches/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs b/benches/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs new file mode 100644 index 000000000..7f8a8d52e --- /dev/null +++ b/benches/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs b/benches/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs new file mode 100644 index 000000000..44d0490b0 --- /dev/null +++ b/benches/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs @@ -0,0 +1,32 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs b/benches/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs new file mode 100644 index 000000000..694d0fcc4 --- /dev/null +++ b/benches/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.1f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs b/benches/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs new file mode 100644 index 000000000..96bceea54 --- /dev/null +++ b/benches/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs @@ -0,0 +1,33 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.4f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 9c80294e7..2d5744762 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -309,6 +309,14 @@ mod grid_align_self_sized_all; #[cfg(feature = "grid")] mod grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset; #[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_fill_height_from_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_fill_width_from_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_height_overrides_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_width_overrides_inset; +#[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_height; #[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_width; @@ -886,6 +894,14 @@ fn benchmark(c: &mut Criterion) { #[cfg(feature = "grid")] grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset::compute(); #[cfg(feature = "grid")] + grid_aspect_ratio_absolute_fill_height_from_inset::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_absolute_fill_width_from_inset::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_absolute_height_overrides_inset::compute(); + #[cfg(feature = "grid")] + grid_aspect_ratio_absolute_width_overrides_inset::compute(); + #[cfg(feature = "grid")] grid_aspect_ratio_child_fill_content_height::compute(); #[cfg(feature = "grid")] grid_aspect_ratio_child_fill_content_width::compute(); diff --git a/test_fixtures/grid_aspect_ratio_absolute_fill_height_from_inset.html b/test_fixtures/grid_aspect_ratio_absolute_fill_height_from_inset.html new file mode 100644 index 000000000..e30d0ffa7 --- /dev/null +++ b/test_fixtures/grid_aspect_ratio_absolute_fill_height_from_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/grid_aspect_ratio_absolute_fill_width_from_inset.html b/test_fixtures/grid_aspect_ratio_absolute_fill_width_from_inset.html new file mode 100644 index 000000000..423325007 --- /dev/null +++ b/test_fixtures/grid_aspect_ratio_absolute_fill_width_from_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/grid_aspect_ratio_absolute_height_overrides_inset.html b/test_fixtures/grid_aspect_ratio_absolute_height_overrides_inset.html new file mode 100644 index 000000000..75c82ed09 --- /dev/null +++ b/test_fixtures/grid_aspect_ratio_absolute_height_overrides_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/grid_aspect_ratio_absolute_width_overrides_inset.html b/test_fixtures/grid_aspect_ratio_absolute_width_overrides_inset.html new file mode 100644 index 000000000..77b5d38aa --- /dev/null +++ b/test_fixtures/grid_aspect_ratio_absolute_width_overrides_inset.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs b/tests/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs new file mode 100644 index 000000000..e5c2f1c24 --- /dev/null +++ b/tests/generated/grid_aspect_ratio_absolute_fill_height_from_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn grid_aspect_ratio_absolute_fill_height_from_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 320f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 320f32, size.width); + assert_eq!(size.height, 107f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 107f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs b/tests/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs new file mode 100644 index 000000000..d66ca520b --- /dev/null +++ b/tests/generated/grid_aspect_ratio_absolute_fill_width_from_inset.rs @@ -0,0 +1,47 @@ +#[test] +fn grid_aspect_ratio_absolute_fill_width_from_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 180f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 180f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, location.y); +} diff --git a/tests/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs b/tests/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs new file mode 100644 index 000000000..062932c08 --- /dev/null +++ b/tests/generated/grid_aspect_ratio_absolute_height_overrides_inset.rs @@ -0,0 +1,48 @@ +#[test] +fn grid_aspect_ratio_absolute_height_overrides_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Percent(0.1f32) }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: auto(), + right: auto(), + top: taffy::style::LengthPercentageAuto::Percent(0.3f32), + bottom: taffy::style::LengthPercentageAuto::Percent(0.5f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 90f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 90f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 90f32, location.y); +} diff --git a/tests/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs b/tests/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs new file mode 100644 index 000000000..6806d2a66 --- /dev/null +++ b/tests/generated/grid_aspect_ratio_absolute_width_overrides_inset.rs @@ -0,0 +1,48 @@ +#[test] +fn grid_aspect_ratio_absolute_width_overrides_inset() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { width: taffy::style::Dimension::Percent(0.4f32), height: auto() }, + aspect_ratio: Some(3f32), + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Percent(0.1f32), + right: taffy::style::LengthPercentageAuto::Percent(0.1f32), + top: taffy::style::LengthPercentageAuto::Percent(0.05f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 160f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 160f32, size.width); + assert_eq!(size.height, 53f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 53f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 15f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 15f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 221c5fb9e..5a6cfc5b0 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -308,6 +308,14 @@ mod grid_align_self_sized_all; #[cfg(feature = "grid")] mod grid_aspect_ratio_absolute_aspect_ratio_overrides_height_of_full_inset; #[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_fill_height_from_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_fill_width_from_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_height_overrides_inset; +#[cfg(feature = "grid")] +mod grid_aspect_ratio_absolute_width_overrides_inset; +#[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_height; #[cfg(feature = "grid")] mod grid_aspect_ratio_child_fill_content_width; From a2ef38c342ee9c07240c273327e4147ca6e2d566 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:28:53 +0000 Subject: [PATCH 26/40] Always apply margins to absolutely positioned grid items --- src/compute/grid/alignment.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compute/grid/alignment.rs b/src/compute/grid/alignment.rs index 797f9cf33..cd8cf13f2 100644 --- a/src/compute/grid/alignment.rs +++ b/src/compute/grid/alignment.rs @@ -127,11 +127,11 @@ pub(super) fn align_and_position_item( // positioned element being set if position == Position::Absolute { if let (Some(left), Some(right)) = (inset_horizontal.start, inset_horizontal.end) { - return Some(f32_max(grid_area_size.width - left - right, 0.0)); + return Some(f32_max(grid_area_minus_item_margins_size.width - left - right, 0.0)); } } - // Apply width based on stretch alignment (clamped by max size) if: + // Apply width based on stretch alignment if: // - Alignment style is "stretch" // - The node is not absolutely positioned // - The node does not have auto margins in this axis. @@ -151,11 +151,11 @@ pub(super) fn align_and_position_item( let height = height.or_else(|| { if position == Position::Absolute { if let (Some(top), Some(bottom)) = (inset_vertical.start, inset_vertical.end) { - return Some(f32_max(grid_area_size.height - top - bottom, 0.0)); + return Some(f32_max(grid_area_minus_item_margins_size.height - top - bottom, 0.0)); } } - // Apply height based on stretch alignment (clamped by max size) if: + // Apply height based on stretch alignment if: // - Alignment style is "stretch" // - The node is not absolutely positioned // - The node does not have auto margins in this axis. From befdef1d1155b3d86441af94788a29bb987f9c36 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:29:57 +0000 Subject: [PATCH 27/40] Rewrite flex item absolute positioning It now: - Applies margins correctly - Applies min/max correctly - Applies aspect ratio correctly --- src/compute/flexbox.rs | 232 ++++++++++++++++++++++------------------- src/geometry.rs | 6 ++ 2 files changed, 130 insertions(+), 108 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 98b0e47d2..c68e4e4a4 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -16,6 +16,7 @@ use crate::style::{ LengthPercentageAuto, Position, }; use crate::style::{FlexDirection, Style}; +use crate::sys::f32_max; use crate::sys::Vec; use crate::tree::LayoutTree; @@ -1586,46 +1587,29 @@ fn final_layout_pass(tree: &mut impl LayoutTree, node: Node, flex_lines: &mut [F /// Perform absolute layout on all absolutely positioned children. #[inline] fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node: Node, constants: &AlgoConstants) { - // TODO: remove number of Vec<_> generated - let candidates = tree - .children(node) - .cloned() - .enumerate() - .filter(|(_, child)| { - let style = tree.style(*child); - style.display != Display::None && style.position == Position::Absolute - }) - .collect::>(); - - for (order, child) in candidates { - let container_width = constants.container_size.width; - let container_height = constants.container_size.height; + let container_width = constants.container_size.width; + let container_height = constants.container_size.height; + for order in 0..tree.child_count(node) { + let child = tree.child(node, order); let child_style = tree.style(child); - // X-axis - let child_position_start = child_style.inset.left.maybe_resolve(container_width); - let child_margin_start = child_style.margin.left.maybe_resolve(container_width); - let start = child_position_start.maybe_add(child_margin_start); - - let child_position_end = child_style.inset.right.maybe_resolve(container_width); - let child_margin_end = child_style.margin.right.maybe_resolve(container_width); - let end = child_position_end.maybe_add(child_margin_end); - - // Y-axis - let child_position_top = child_style.inset.top.maybe_resolve(container_height); - let child_margin_top = child_style.margin.top.maybe_resolve(container_height); - let top = child_position_top.maybe_add(child_margin_top); + // Skip items that are display:none or are not position:absolute + if child_style.display == Display::None || child_style.position != Position::Absolute { + continue; + } - let child_position_bottom = child_style.inset.bottom.maybe_resolve(container_height); - let child_margin_bottom = child_style.margin.bottom.maybe_resolve(container_height); - let bottom = child_position_bottom.maybe_add(child_margin_bottom); + let aspect_ratio = child_style.aspect_ratio; + let margin = child_style.margin.map(|margin| margin.resolve_to_option(container_width)); + let align_self = child_style.align_self.unwrap_or(constants.align_items); - let (start_main, end_main) = if constants.is_row { (start, end) } else { (top, bottom) }; - let (start_cross, end_cross) = if constants.is_row { (top, bottom) } else { (start, end) }; + // Resolve inset + let left = child_style.inset.left.maybe_resolve(container_width); + let right = child_style.inset.right.maybe_resolve(container_width); + let top = child_style.inset.top.maybe_resolve(container_height); + let bottom = child_style.inset.bottom.maybe_resolve(container_height); // Compute known dimensions from min/max/inherent size styles - let aspect_ratio = child_style.aspect_ratio; let style_size = child_style.size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); let min_size = @@ -1634,19 +1618,25 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node child_style.max_size.maybe_resolve(constants.container_size).maybe_apply_aspect_ratio(aspect_ratio); let mut known_dimensions = style_size.maybe_clamp(min_size, max_size); - // Fill in width from left/right and reapply aspect ratio if appropriate - if known_dimensions.width.is_none() && start.is_some() && end.is_some() { - known_dimensions.width = Some(container_width.maybe_sub(start).maybe_sub(end)); - known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); + // Fill in width from left/right and reapply aspect ratio if: + // - Width is not already known + // - Item has both left and right inset properties set + if let (None, Some(left), Some(right)) = (known_dimensions.width, left, right) { + let new_width_raw = container_width.maybe_sub(margin.left).maybe_sub(margin.right) - left - right; + known_dimensions.width = Some(f32_max(new_width_raw, 0.0)); + known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio).maybe_clamp(min_size, max_size); } - // Fill in height from top/bottom and reapply aspect ratio if appropriate - if known_dimensions.height.is_none() && top.is_some() && bottom.is_some() { - known_dimensions.height = Some(container_height.maybe_sub(top).maybe_sub(bottom)); - known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio); + // Fill in height from top/bottom and reapply aspect ratio if: + // - Height is not already known + // - Item has both top and bottom inset properties set + if let (None, Some(top), Some(bottom)) = (known_dimensions.height, top, bottom) { + let new_height_raw = container_height.maybe_sub(margin.top).maybe_sub(margin.bottom) - top - bottom; + known_dimensions.height = Some(f32_max(new_height_raw, 0.0)); + known_dimensions = known_dimensions.maybe_apply_aspect_ratio(aspect_ratio).maybe_clamp(min_size, max_size); } - let preliminary_size = compute_node_layout( + let measured_size = compute_node_layout( tree, child, known_dimensions, @@ -1658,96 +1648,122 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node RunMode::PeformLayout, SizingMode::ContentSize, ); + let final_size = known_dimensions.unwrap_or(measured_size).maybe_clamp(min_size, max_size); - // Satisfy the borrow checker by re-requesting the style from above. - // This shortens the lifetime of the original binding - let child_style = tree.style(child); + let non_auto_margin = margin.map(|m| m.unwrap_or(0.0)); - let free_main_space = constants.container_size.main(constants.dir) - - preliminary_size - .main(constants.dir) - .maybe_max( - child_style - .min_size - .main(constants.dir) - .maybe_resolve(constants.node_inner_size.main(constants.dir)), - ) - .maybe_min( - child_style - .max_size - .main(constants.dir) - .maybe_resolve(constants.node_inner_size.main(constants.dir)), - ); + let free_space = Size { + width: constants.container_size.width - final_size.width - non_auto_margin.horizontal_axis_sum(), + height: constants.container_size.height - final_size.height - non_auto_margin.vertical_axis_sum(), + } + .f32_max(Size::ZERO); + + // Expand auto margins to fill available space + let resolved_margin = { + let auto_margin_size = Size { + width: { + let auto_margin_count = margin.left.is_none() as u8 + margin.right.is_none() as u8; + if auto_margin_count > 0 { + free_space.width / auto_margin_count as f32 + } else { + 0.0 + } + }, + height: { + let auto_margin_count = margin.top.is_none() as u8 + margin.bottom.is_none() as u8; + if auto_margin_count > 0 { + free_space.height / auto_margin_count as f32 + } else { + 0.0 + } + }, + }; - let free_cross_space = constants.container_size.cross(constants.dir) - - preliminary_size - .cross(constants.dir) - .maybe_max( - child_style - .min_size - .cross(constants.dir) - .maybe_resolve(constants.node_inner_size.cross(constants.dir)), - ) - .maybe_min( - child_style - .max_size - .cross(constants.dir) - .maybe_resolve(constants.node_inner_size.cross(constants.dir)), - ); + Rect { + left: margin.left.unwrap_or(auto_margin_size.width), + right: margin.right.unwrap_or(auto_margin_size.width), + top: margin.top.unwrap_or(auto_margin_size.height), + bottom: margin.bottom.unwrap_or(auto_margin_size.height), + } + }; - let offset_main = if start_main.is_some() { - start_main.unwrap_or(0.0) + constants.border.main_start(constants.dir) - } else if end_main.is_some() { - free_main_space - end_main.unwrap_or(0.0) - constants.border.main_end(constants.dir) + // Determine flex-relative insets + let (start_main, end_main) = if constants.is_row { (left, right) } else { (top, bottom) }; + let (start_cross, end_cross) = if constants.is_row { (top, bottom) } else { (left, right) }; + + // Apply main-axis alignment + // let free_main_space = free_space.main(constants.dir) - resolved_margin.main_axis_sum(constants.dir); + let offset_main = if let Some(start) = start_main { + start + constants.border.main_start(constants.dir) + resolved_margin.main_start(constants.dir) + } else if let Some(end) = end_main { + constants.container_size.main(constants.dir) + - constants.border.main_end(constants.dir) + - final_size.main(constants.dir) + - end + - resolved_margin.main_end(constants.dir) } else { match tree.style(node).justify_content.unwrap_or(JustifyContent::Start) { // Stretch is an invalid value for justify_content in the flexbox algorithm, so we // treat it as if it wasn't set (and thus we default to FlexStart behaviour) JustifyContent::SpaceBetween | JustifyContent::Start | JustifyContent::Stretch => { - constants.padding_border.main_start(constants.dir) + constants.padding_border.main_start(constants.dir) + resolved_margin.main_start(constants.dir) + } + JustifyContent::End => { + constants.container_size.main(constants.dir) + - constants.padding_border.main_end(constants.dir) + - final_size.main(constants.dir) + - resolved_margin.main_end(constants.dir) } - JustifyContent::End => free_main_space - constants.padding_border.main_end(constants.dir), JustifyContent::SpaceEvenly | JustifyContent::SpaceAround | JustifyContent::Center => { - free_main_space / 2.0 + (constants.container_size.main(constants.dir) + constants.padding_border.main_start(constants.dir) + - constants.padding_border.main_end(constants.dir) + - final_size.main(constants.dir) + + resolved_margin.main_start(constants.dir) + - resolved_margin.main_end(constants.dir)) + / 2.0 } } }; - let offset_cross = if start_cross.is_some() { - start_cross.unwrap_or(0.0) + constants.border.cross_start(constants.dir) - } else if end_cross.is_some() { - free_cross_space - end_cross.unwrap_or(0.0) - constants.border.cross_end(constants.dir) + // Apply cross-axis alignment + // let free_cross_space = free_space.cross(constants.dir) - resolved_margin.cross_axis_sum(constants.dir); + let offset_cross = if let Some(start) = start_cross { + start + constants.border.cross_start(constants.dir) + resolved_margin.cross_start(constants.dir) + } else if let Some(end) = end_cross { + constants.container_size.cross(constants.dir) + - constants.border.cross_end(constants.dir) + - final_size.cross(constants.dir) + - end + - resolved_margin.cross_end(constants.dir) } else { - match child_style.align_self.unwrap_or(constants.align_items) { - AlignSelf::Start => { - if constants.is_wrap_reverse { - free_cross_space - constants.padding_border.cross_end(constants.dir) - } else { - constants.padding_border.cross_start(constants.dir) - } + match (align_self, constants.is_wrap_reverse) { + // Stretch alignment does not apply to absolutely positioned items + // See "Example 3" at https://www.w3.org/TR/css-flexbox-1/#abspos-items + // Note: Stretch should be FlexStart not Start when we support both + (AlignSelf::Baseline | AlignSelf::Stretch | AlignSelf::Start, false) | (AlignSelf::End, true) => { + constants.padding_border.cross_start(constants.dir) + resolved_margin.cross_start(constants.dir) } - AlignSelf::End => { - if constants.is_wrap_reverse { - constants.padding_border.cross_start(constants.dir) - } else { - free_cross_space - constants.padding_border.cross_end(constants.dir) - } + (AlignSelf::Baseline | AlignSelf::Stretch | AlignSelf::Start, true) | (AlignSelf::End, false) => { + constants.container_size.cross(constants.dir) + - constants.padding_border.cross_end(constants.dir) + - final_size.cross(constants.dir) + - resolved_margin.cross_end(constants.dir) } - AlignSelf::Center => free_cross_space / 2.0, - AlignSelf::Baseline => free_cross_space / 2.0, // Treat as center for now until we have baseline support - AlignSelf::Stretch => { - if constants.is_wrap_reverse { - free_cross_space - constants.padding_border.cross_end(constants.dir) - } else { - constants.padding_border.cross_start(constants.dir) - } + (AlignSelf::Center, _) => { + (constants.container_size.cross(constants.dir) + + constants.padding_border.cross_start(constants.dir) + - constants.padding_border.cross_end(constants.dir) + - final_size.cross(constants.dir) + + resolved_margin.cross_start(constants.dir) + - resolved_margin.cross_end(constants.dir)) + / 2.0 } } }; *tree.layout_mut(child) = Layout { order: order as u32, - size: preliminary_size, + size: final_size, location: Point { x: if constants.is_row { offset_main } else { offset_cross }, y: if constants.is_column { offset_main } else { offset_cross }, diff --git a/src/geometry.rs b/src/geometry.rs index d0b187f7e..578349794 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,6 +1,7 @@ //! Geometric primitives useful for layout use crate::style::{Dimension, FlexDirection}; +use crate::sys::f32_max; use core::ops::Add; #[cfg(feature = "grid")] @@ -354,6 +355,11 @@ impl Size { impl Size { /// A [`Size`] with zero width and height pub const ZERO: Size = Self { width: 0.0, height: 0.0 }; + + /// Applies f32_max to each component separately + pub fn f32_max(self, rhs: Size) -> Size { + Size { width: f32_max(self.width, rhs.width), height: f32_max(self.height, rhs.height) } + } } impl Size> { From e9568cfab49107fa8bf45cc543f99b181c7c2d81 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:34:37 +0000 Subject: [PATCH 28/40] Take border into account when absolutely positioning grid items relative to the grid container --- .../grid_absolute_layout_within_border.rs | 107 ++++++++++++++ benches/generated/mod.rs | 4 + src/compute/grid/mod.rs | 14 +- .../grid_absolute_layout_within_border.html | 20 +++ .../grid_absolute_layout_within_border.rs | 137 ++++++++++++++++++ tests/generated/mod.rs | 2 + 6 files changed, 280 insertions(+), 4 deletions(-) create mode 100644 benches/generated/grid_absolute_layout_within_border.rs create mode 100644 test_fixtures/grid_absolute_layout_within_border.html create mode 100644 tests/generated/grid_absolute_layout_within_border.rs diff --git a/benches/generated/grid_absolute_layout_within_border.rs b/benches/generated/grid_absolute_layout_within_border.rs new file mode 100644 index 000000000..87bcab3de --- /dev/null +++ b/benches/generated/grid_absolute_layout_within_border.rs @@ -0,0 +1,107 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(0f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(0f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(0f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(0f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(0f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(0f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(0f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(0f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 2d5744762..94b0201ba 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -265,6 +265,8 @@ mod grid_absolute_container_top_right_margin; #[cfg(feature = "grid")] mod grid_absolute_justify_self_sized_all; #[cfg(feature = "grid")] +mod grid_absolute_layout_within_border; +#[cfg(feature = "grid")] mod grid_absolute_row_end; #[cfg(feature = "grid")] mod grid_absolute_row_start; @@ -850,6 +852,8 @@ fn benchmark(c: &mut Criterion) { #[cfg(feature = "grid")] grid_absolute_justify_self_sized_all::compute(); #[cfg(feature = "grid")] + grid_absolute_layout_within_border::compute(); + #[cfg(feature = "grid")] grid_absolute_row_end::compute(); #[cfg(feature = "grid")] grid_absolute_row_start::compute(); diff --git a/src/compute/grid/mod.rs b/src/compute/grid/mod.rs index daa4cd6fc..5cca095ce 100644 --- a/src/compute/grid/mod.rs +++ b/src/compute/grid/mod.rs @@ -325,10 +325,16 @@ pub fn compute( }); let grid_area = Rect { - top: maybe_row_indexes.start.map(|index| rows[index].offset).unwrap_or(0.0), - bottom: maybe_row_indexes.end.map(|index| rows[index].offset).unwrap_or(container_border_box.height), - left: maybe_col_indexes.start.map(|index| columns[index].offset).unwrap_or(0.0), - right: maybe_col_indexes.end.map(|index| columns[index].offset).unwrap_or(container_border_box.width), + top: maybe_row_indexes.start.map(|index| rows[index].offset).unwrap_or(border.top), + bottom: maybe_row_indexes + .end + .map(|index| rows[index].offset) + .unwrap_or(container_border_box.height - border.bottom), + left: maybe_col_indexes.start.map(|index| columns[index].offset).unwrap_or(border.left), + right: maybe_col_indexes + .end + .map(|index| columns[index].offset) + .unwrap_or(container_border_box.width - border.right), }; align_and_position_item(tree, child, order, grid_area, container_alignment_styles); order += 1; diff --git a/test_fixtures/grid_absolute_layout_within_border.html b/test_fixtures/grid_absolute_layout_within_border.html new file mode 100644 index 000000000..1470c383f --- /dev/null +++ b/test_fixtures/grid_absolute_layout_within_border.html @@ -0,0 +1,20 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/grid_absolute_layout_within_border.rs b/tests/generated/grid_absolute_layout_within_border.rs new file mode 100644 index 000000000..be52434ea --- /dev/null +++ b/tests/generated/grid_absolute_layout_within_border.rs @@ -0,0 +1,137 @@ +#[test] +fn grid_absolute_layout_within_border() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(0f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(0f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(0f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(0f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(0f32), + right: auto(), + top: taffy::style::LengthPercentageAuto::Points(0f32), + bottom: auto(), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(0f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(0f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x); + assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x); + assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.x); + assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.y); + let Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.height); + assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.x); + assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 5a6cfc5b0..a6ba11482 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -264,6 +264,8 @@ mod grid_absolute_container_top_right_margin; #[cfg(feature = "grid")] mod grid_absolute_justify_self_sized_all; #[cfg(feature = "grid")] +mod grid_absolute_layout_within_border; +#[cfg(feature = "grid")] mod grid_absolute_row_end; #[cfg(feature = "grid")] mod grid_absolute_row_start; From fad89190354656cc12bdfc2dc20d9a13ab1ba338 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:40:28 +0000 Subject: [PATCH 29/40] Add absolute positioning margin test --- .../generated/absolute_margin_bottom_left.rs | 36 +++++++++++++ benches/generated/mod.rs | 2 + .../absolute_margin_bottom_left.html | 17 +++++++ .../generated/absolute_margin_bottom_left.rs | 51 +++++++++++++++++++ tests/generated/mod.rs | 1 + 5 files changed, 107 insertions(+) create mode 100644 benches/generated/absolute_margin_bottom_left.rs create mode 100644 test_fixtures/absolute_margin_bottom_left.html create mode 100644 tests/generated/absolute_margin_bottom_left.rs diff --git a/benches/generated/absolute_margin_bottom_left.rs b/benches/generated/absolute_margin_bottom_left.rs new file mode 100644 index 000000000..9848f6ca6 --- /dev/null +++ b/benches/generated/absolute_margin_bottom_left.rs @@ -0,0 +1,36 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(10f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: zero(), + top: zero(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + flex_direction: taffy::style::FlexDirection::Column, + justify_content: Some(taffy::style::JustifyContent::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 94b0201ba..544122fba 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -82,6 +82,7 @@ mod absolute_layout_width_height_end_bottom; mod absolute_layout_width_height_start_top; mod absolute_layout_width_height_start_top_end_bottom; mod absolute_layout_within_border; +mod absolute_margin_bottom_left; mod align_baseline; mod align_baseline_child_multiline; mod align_baseline_nested_child; @@ -669,6 +670,7 @@ fn benchmark(c: &mut Criterion) { absolute_layout_width_height_start_top::compute(); absolute_layout_width_height_start_top_end_bottom::compute(); absolute_layout_within_border::compute(); + absolute_margin_bottom_left::compute(); align_baseline::compute(); align_baseline_child_multiline::compute(); align_baseline_nested_child::compute(); diff --git a/test_fixtures/absolute_margin_bottom_left.html b/test_fixtures/absolute_margin_bottom_left.html new file mode 100644 index 000000000..7a4480e6f --- /dev/null +++ b/test_fixtures/absolute_margin_bottom_left.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/absolute_margin_bottom_left.rs b/tests/generated/absolute_margin_bottom_left.rs new file mode 100644 index 000000000..7061fbcc4 --- /dev/null +++ b/tests/generated/absolute_margin_bottom_left.rs @@ -0,0 +1,51 @@ +#[test] +fn absolute_margin_bottom_left() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(10f32), + height: taffy::style::Dimension::Points(10f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: zero(), + top: zero(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + flex_direction: taffy::style::FlexDirection::Column, + justify_content: Some(taffy::style::JustifyContent::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 10f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.width); + assert_eq!(size.height, 10f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, size.height); + assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x); + assert_eq!(location.y, 80f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 80f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index a6ba11482..02e609fe6 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -81,6 +81,7 @@ mod absolute_layout_width_height_end_bottom; mod absolute_layout_width_height_start_top; mod absolute_layout_width_height_start_top_end_bottom; mod absolute_layout_within_border; +mod absolute_margin_bottom_left; mod align_baseline; mod align_baseline_child_multiline; mod align_baseline_nested_child; From f063cc02011a8d459e4b8410232bd610234116c9 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:52:18 +0000 Subject: [PATCH 30/40] Apply suggestions from code review Co-authored-by: Andreas Weibye <13300393+Weibye@users.noreply.github.com> --- scripts/gentest/test_helper.js | 2 +- src/geometry.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/gentest/test_helper.js b/scripts/gentest/test_helper.js index 22d5894f0..070f55906 100644 --- a/scripts/gentest/test_helper.js +++ b/scripts/gentest/test_helper.js @@ -104,7 +104,7 @@ function parseNumber(input) { } function parseRatio(input) { - if (!input) return undefined + if (!input) return undefined; if (input.includes('/')) { let [width, height] = input.split("/").map(part => parseFloat(part.trim())); diff --git a/src/geometry.rs b/src/geometry.rs index 578349794..a7b4baffb 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -374,7 +374,7 @@ impl Size> { /// Applies aspect_ratio (if one is supplied) to the Size: /// - If width is `Some` but height is `None`, then height is computed from width and aspect_ratio - /// - If height is `Some` but width is `None`, then width is computed from width and aspect_ratio + /// - If height is `Some` but width is `None`, then width is computed from height and aspect_ratio /// /// If aspect_ratio is `None` then this function simply returns self. pub fn maybe_apply_aspect_ratio(self, aspect_ratio: Option) -> Size> { From 01fadecddf1ebccbb6de2f114f9b8e16ca292386 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 14:55:42 +0000 Subject: [PATCH 31/40] Update release notes --- RELEASES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASES.md b/RELEASES.md index af9b1a56a..419cb094c 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -13,6 +13,9 @@ ### Fixes - Flexbox nodes sized under a min-content constraint now size correctly (#291) +- Aspect ratio is now applied correctly in many circumstances +- Absolutely positioned items now apply margins correctly +- Min/max size are now applied correctly ### Removed From 29161f068024d73237e288b3ab309aff5e57badc Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 15:03:30 +0000 Subject: [PATCH 32/40] Add test for absolutely positioned fallback to static position of grid item in container with border --- ...id_absolute_layout_within_border_static.rs | 91 +++++++++++++ benches/generated/mod.rs | 4 + ..._absolute_layout_within_border_static.html | 20 +++ ...id_absolute_layout_within_border_static.rs | 121 ++++++++++++++++++ tests/generated/mod.rs | 2 + 5 files changed, 238 insertions(+) create mode 100644 benches/generated/grid_absolute_layout_within_border_static.rs create mode 100644 test_fixtures/grid_absolute_layout_within_border_static.html create mode 100644 tests/generated/grid_absolute_layout_within_border_static.rs diff --git a/benches/generated/grid_absolute_layout_within_border_static.rs b/benches/generated/grid_absolute_layout_within_border_static.rs new file mode 100644 index 000000000..36d05bab9 --- /dev/null +++ b/benches/generated/grid_absolute_layout_within_border_static.rs @@ -0,0 +1,91 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::Start), + justify_self: Some(taffy::style::JustifySelf::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::End), + justify_self: Some(taffy::style::JustifySelf::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::Start), + justify_self: Some(taffy::style::JustifySelf::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::End), + justify_self: Some(taffy::style::JustifySelf::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 544122fba..c40341149 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -268,6 +268,8 @@ mod grid_absolute_justify_self_sized_all; #[cfg(feature = "grid")] mod grid_absolute_layout_within_border; #[cfg(feature = "grid")] +mod grid_absolute_layout_within_border_static; +#[cfg(feature = "grid")] mod grid_absolute_row_end; #[cfg(feature = "grid")] mod grid_absolute_row_start; @@ -856,6 +858,8 @@ fn benchmark(c: &mut Criterion) { #[cfg(feature = "grid")] grid_absolute_layout_within_border::compute(); #[cfg(feature = "grid")] + grid_absolute_layout_within_border_static::compute(); + #[cfg(feature = "grid")] grid_absolute_row_end::compute(); #[cfg(feature = "grid")] grid_absolute_row_start::compute(); diff --git a/test_fixtures/grid_absolute_layout_within_border_static.html b/test_fixtures/grid_absolute_layout_within_border_static.html new file mode 100644 index 000000000..b3fc38395 --- /dev/null +++ b/test_fixtures/grid_absolute_layout_within_border_static.html @@ -0,0 +1,20 @@ + + + + + + + Test description + + + + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/grid_absolute_layout_within_border_static.rs b/tests/generated/grid_absolute_layout_within_border_static.rs new file mode 100644 index 000000000..723e6e83a --- /dev/null +++ b/tests/generated/grid_absolute_layout_within_border_static.rs @@ -0,0 +1,121 @@ +#[test] +fn grid_absolute_layout_within_border_static() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::Start), + justify_self: Some(taffy::style::JustifySelf::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + ..Default::default() + }) + .unwrap(); + let node1 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::End), + justify_self: Some(taffy::style::JustifySelf::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + ..Default::default() + }) + .unwrap(); + let node2 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::Start), + justify_self: Some(taffy::style::JustifySelf::Start), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node3 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + align_self: Some(taffy::style::AlignSelf::End), + justify_self: Some(taffy::style::JustifySelf::End), + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(50f32), + }, + margin: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Grid, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + padding: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + border: taffy::geometry::Rect { + left: taffy::style::LengthPercentage::Points(10f32), + right: taffy::style::LengthPercentage::Points(10f32), + top: taffy::style::LengthPercentage::Points(10f32), + bottom: taffy::style::LengthPercentage::Points(10f32), + }, + ..Default::default() + }, + &[node0, node1, node2, node3], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x); + assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.y); + let Layout { size, location, .. } = taffy.layout(node1).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node1.data(), 50f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.x); + assert_eq!(location.y, 40f32, "y of node {:?}. Expected {}. Actual {}", node1.data(), 40f32, location.y); + let Layout { size, location, .. } = taffy.layout(node2).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node2.data(), 50f32, size.height); + assert_eq!(location.x, 20f32, "x of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.x); + assert_eq!(location.y, 20f32, "y of node {:?}. Expected {}. Actual {}", node2.data(), 20f32, location.y); + let Layout { size, location, .. } = taffy.layout(node3).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node3.data(), 50f32, size.height); + assert_eq!(location.x, 30f32, "x of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.x); + assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node3.data(), 30f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 02e609fe6..bf72905d0 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -267,6 +267,8 @@ mod grid_absolute_justify_self_sized_all; #[cfg(feature = "grid")] mod grid_absolute_layout_within_border; #[cfg(feature = "grid")] +mod grid_absolute_layout_within_border_static; +#[cfg(feature = "grid")] mod grid_absolute_row_end; #[cfg(feature = "grid")] mod grid_absolute_row_start; From db1bc72e5831964bb8b393f8c3b5110dda5384dc Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 19:02:14 +0000 Subject: [PATCH 33/40] Implement Add for Rect where the inner type implements Add --- src/compute/flexbox.rs | 22 ++++------------------ src/geometry.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index c68e4e4a4..929feabf7 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -395,12 +395,7 @@ fn compute_constants( let border = style.border.resolve_or_zero(parent_size.width); let align_items = style.align_items.unwrap_or(crate::style::AlignItems::Stretch); - let padding_border = Rect { - left: padding.left + border.left, - right: padding.right + border.right, - top: padding.top + border.top, - bottom: padding.bottom + border.bottom, - }; + let padding_border = padding + border; let node_outer_size = Size { width: known_dimensions @@ -1792,8 +1787,8 @@ mod tests { #![allow(clippy::redundant_clone)] use crate::{ + geometry::Size, math::MaybeMath, - prelude::{Rect, Size}, resolve::ResolveOrZero, style::{FlexWrap, Style}, Taffy, @@ -1822,18 +1817,9 @@ mod tests { assert_eq!(constants.margin, margin); let border = style.border.resolve_or_zero(parent_size); - assert_eq!(constants.border, border); - let padding = style.padding.resolve_or_zero(parent_size); - - // TODO: Replace with something less hardcoded? - let padding_border = Rect { - left: padding.left + border.left, - right: padding.right + border.right, - top: padding.top + border.top, - bottom: padding.bottom + border.bottom, - }; - + let padding_border = padding + border; + assert_eq!(constants.border, border); assert_eq!(constants.padding_border, padding_border); // TODO: Replace with something less hardcoded? diff --git a/src/geometry.rs b/src/geometry.rs index a7b4baffb..3df769443 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -43,6 +43,19 @@ impl Default for Rect { } } +impl> Add> for Rect { + type Output = Rect; + + fn add(self, rhs: Rect) -> Self::Output { + Rect { + left: self.left + rhs.left, + right: self.right + rhs.right, + top: self.top + rhs.top, + bottom: self.bottom + rhs.bottom, + } + } +} + impl Rect { /// Applies the function `f` to all four sides of the rect /// From dec6bc01227d032d8a4300aa5df554dbae597589 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 19:02:54 +0000 Subject: [PATCH 34/40] Apply aspect ratio and min/max size to flex container size --- src/compute/flexbox.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 929feabf7..f56e03b58 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -390,6 +390,11 @@ fn compute_constants( let is_column = dir.is_column(); let is_wrap_reverse = style.flex_wrap == FlexWrap::WrapReverse; + let aspect_ratio = style.aspect_ratio; + let size = style.size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let min_size = style.size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let max_size = style.size.maybe_resolve(parent_size).maybe_apply_aspect_ratio(aspect_ratio); + let margin = style.margin.resolve_or_zero(parent_size.width); let padding = style.padding.resolve_or_zero(parent_size.width); let border = style.border.resolve_or_zero(parent_size.width); @@ -400,10 +405,10 @@ fn compute_constants( let node_outer_size = Size { width: known_dimensions .width - .or_else(|| style.size.width.maybe_resolve(parent_size.width).maybe_sub(margin.horizontal_axis_sum())), - height: known_dimensions - .height - .or_else(|| style.size.height.maybe_resolve(parent_size.height).maybe_sub(margin.vertical_axis_sum())), + .or_else(|| size.width.maybe_sub(margin.horizontal_axis_sum()).maybe_clamp(min_size.width, max_size.width)), + height: known_dimensions.height.or_else(|| { + size.height.maybe_sub(margin.vertical_axis_sum()).maybe_clamp(min_size.height, max_size.height) + }), }; let node_inner_size = Size { From 0319a30145754235ca1a0c57a64c475ce8ab6f04 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 19:03:52 +0000 Subject: [PATCH 35/40] Cleanup TODOs in the flexbox algorithm --- src/compute/flexbox.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index f56e03b58..8f8204ab0 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -221,6 +221,11 @@ fn compute_preliminary( } // TODO: Add step 4 according to spec: https://www.w3.org/TR/css-flexbox-1/#algo-main-container + + // 4. Determine the main size of the flex container + + // This has already been done as part of compute_constants. The inner size is exposed as constants.node_inner_size. + // 9.3. Main Size Determination // 5. Collect flex items into flex lines. @@ -248,8 +253,7 @@ fn compute_preliminary( resolve_flexible_lengths(tree, line, &constants, original_gap); } - // TODO: Cleanup and make according to spec - // Not part of the spec from what i can see but seems correct + // Find the inner and outer used main_size of the container constants.container_size.set_main( constants.dir, known_dimensions.main(constants.dir).unwrap_or({ @@ -262,7 +266,6 @@ fn compute_preliminary( } }), ); - constants.inner_container_size.set_main( constants.dir, constants.container_size.main(constants.dir) - constants.padding_border.main_axis_sum(constants.dir), @@ -555,7 +558,6 @@ fn determine_flex_base_size( available_space: Size, flex_items: &mut Vec, ) { - // TODO - this does not follow spec. See the TODOs below for child in flex_items.iter_mut() { let child_style = tree.style(child.node); @@ -582,7 +584,8 @@ fn determine_flex_base_size( // size the item under that constraint. The flex base size is the item’s // resulting main size. - // TODO - Probably need to cover this case in future + // This is covered by the implementation of E below, which passes the available_space constraint + // through to the child size computation. It may need a separate implementation if/when D is implemented. // D. Otherwise, if the used flex basis is content or depends on its // available space, the available main size is infinite, and the flex item’s @@ -590,7 +593,7 @@ fn determine_flex_base_size( // for a box in an orthogonal flow [CSS3-WRITING-MODES]. The flex base size // is the item’s max-content main size. - // TODO - Probably need to cover this case in future + // TODO if/when vertical writing modes are supported // E. Otherwise, size the item into the available space using its used flex basis // in place of its main size, treating a value of content as max-content. @@ -783,7 +786,6 @@ fn resolve_flexible_lengths( // TODO this should really only be set inside the if-statement below but // that causes the target_main_size to never be set for some items - child .outer_target_size .set_main(constants.dir, child.target_size.main(constants.dir) + child.margin.main_axis_sum(constants.dir)); @@ -1811,7 +1813,6 @@ mod tests { let parent_size = Size::NONE; let constants = super::compute_constants(tree.style(node_id).unwrap(), node_size, parent_size); - // let constants = super::compute_constants(&tree.nodes[node_id], node_size, parent_size); assert!(constants.dir == style.flex_direction); assert!(constants.is_row == style.flex_direction.is_row()); @@ -1827,7 +1828,6 @@ mod tests { assert_eq!(constants.border, border); assert_eq!(constants.padding_border, padding_border); - // TODO: Replace with something less hardcoded? let inner_size = Size { width: node_size.width.maybe_sub(padding_border.horizontal_axis_sum()), height: node_size.height.maybe_sub(padding_border.vertical_axis_sum()), From e1ef9d8c8a58e67aaf65301ca04795e0e2c47a17 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sun, 8 Jan 2023 21:12:33 +0000 Subject: [PATCH 36/40] Remove one more TODO --- src/compute/flexbox.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index 8f8204ab0..e93bc824b 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -220,10 +220,7 @@ fn compute_preliminary( NODE_LOGGER.labelled_debug_log("item.resolved_minimum_size", item.resolved_minimum_size); } - // TODO: Add step 4 according to spec: https://www.w3.org/TR/css-flexbox-1/#algo-main-container - // 4. Determine the main size of the flex container - // This has already been done as part of compute_constants. The inner size is exposed as constants.node_inner_size. // 9.3. Main Size Determination From 1419e31e83316d494727921700b68fd5c1f6b53f Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 11 Jan 2023 00:02:24 +0000 Subject: [PATCH 37/40] Add min/max size tests for absolutely positioned flex items --- .../absolute_minmax_bottom_right_max.rs | 38 +++++++++++++ .../absolute_minmax_bottom_right_min_max.rs | 38 +++++++++++++ ...e_minmax_bottom_right_min_max_preferred.rs | 42 ++++++++++++++ ...solute_minmax_top_left_bottom_right_max.rs | 34 +++++++++++ ...te_minmax_top_left_bottom_right_min_max.rs | 38 +++++++++++++ benches/generated/mod.rs | 10 ++++ .../absolute_minmax_bottom_right_max.html | 17 ++++++ .../absolute_minmax_bottom_right_min_max.html | 17 ++++++ ...minmax_bottom_right_min_max_preferred.html | 17 ++++++ ...lute_minmax_top_left_bottom_right_max.html | 17 ++++++ ..._minmax_top_left_bottom_right_min_max.html | 17 ++++++ .../absolute_minmax_bottom_right_max.rs | 53 +++++++++++++++++ .../absolute_minmax_bottom_right_min_max.rs | 53 +++++++++++++++++ ...e_minmax_bottom_right_min_max_preferred.rs | 57 +++++++++++++++++++ ...solute_minmax_top_left_bottom_right_max.rs | 49 ++++++++++++++++ ...te_minmax_top_left_bottom_right_min_max.rs | 53 +++++++++++++++++ tests/generated/mod.rs | 5 ++ 17 files changed, 555 insertions(+) create mode 100644 benches/generated/absolute_minmax_bottom_right_max.rs create mode 100644 benches/generated/absolute_minmax_bottom_right_min_max.rs create mode 100644 benches/generated/absolute_minmax_bottom_right_min_max_preferred.rs create mode 100644 benches/generated/absolute_minmax_top_left_bottom_right_max.rs create mode 100644 benches/generated/absolute_minmax_top_left_bottom_right_min_max.rs create mode 100644 test_fixtures/absolute_minmax_bottom_right_max.html create mode 100644 test_fixtures/absolute_minmax_bottom_right_min_max.html create mode 100644 test_fixtures/absolute_minmax_bottom_right_min_max_preferred.html create mode 100644 test_fixtures/absolute_minmax_top_left_bottom_right_max.html create mode 100644 test_fixtures/absolute_minmax_top_left_bottom_right_min_max.html create mode 100644 tests/generated/absolute_minmax_bottom_right_max.rs create mode 100644 tests/generated/absolute_minmax_bottom_right_min_max.rs create mode 100644 tests/generated/absolute_minmax_bottom_right_min_max_preferred.rs create mode 100644 tests/generated/absolute_minmax_top_left_bottom_right_max.rs create mode 100644 tests/generated/absolute_minmax_top_left_bottom_right_min_max.rs diff --git a/benches/generated/absolute_minmax_bottom_right_max.rs b/benches/generated/absolute_minmax_bottom_right_max.rs new file mode 100644 index 000000000..50bd1c3c5 --- /dev/null +++ b/benches/generated/absolute_minmax_bottom_right_max.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_minmax_bottom_right_min_max.rs b/benches/generated/absolute_minmax_bottom_right_min_max.rs new file mode 100644 index 000000000..d392d2f07 --- /dev/null +++ b/benches/generated/absolute_minmax_bottom_right_min_max.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_minmax_bottom_right_min_max_preferred.rs b/benches/generated/absolute_minmax_bottom_right_min_max_preferred.rs new file mode 100644 index 000000000..2ad7f333f --- /dev/null +++ b/benches/generated/absolute_minmax_bottom_right_min_max_preferred.rs @@ -0,0 +1,42 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(200f32), + height: taffy::style::Dimension::Points(200f32), + }, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_minmax_top_left_bottom_right_max.rs b/benches/generated/absolute_minmax_top_left_bottom_right_max.rs new file mode 100644 index 000000000..0f09d6a2a --- /dev/null +++ b/benches/generated/absolute_minmax_top_left_bottom_right_max.rs @@ -0,0 +1,34 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_minmax_top_left_bottom_right_min_max.rs b/benches/generated/absolute_minmax_top_left_bottom_right_min_max.rs new file mode 100644 index 000000000..356ba3d97 --- /dev/null +++ b/benches/generated/absolute_minmax_top_left_bottom_right_min_max.rs @@ -0,0 +1,38 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index c40341149..587867b61 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -83,6 +83,11 @@ mod absolute_layout_width_height_start_top; mod absolute_layout_width_height_start_top_end_bottom; mod absolute_layout_within_border; mod absolute_margin_bottom_left; +mod absolute_minmax_bottom_right_max; +mod absolute_minmax_bottom_right_min_max; +mod absolute_minmax_bottom_right_min_max_preferred; +mod absolute_minmax_top_left_bottom_right_max; +mod absolute_minmax_top_left_bottom_right_min_max; mod align_baseline; mod align_baseline_child_multiline; mod align_baseline_nested_child; @@ -673,6 +678,11 @@ fn benchmark(c: &mut Criterion) { absolute_layout_width_height_start_top_end_bottom::compute(); absolute_layout_within_border::compute(); absolute_margin_bottom_left::compute(); + absolute_minmax_bottom_right_max::compute(); + absolute_minmax_bottom_right_min_max::compute(); + absolute_minmax_bottom_right_min_max_preferred::compute(); + absolute_minmax_top_left_bottom_right_max::compute(); + absolute_minmax_top_left_bottom_right_min_max::compute(); align_baseline::compute(); align_baseline_child_multiline::compute(); align_baseline_nested_child::compute(); diff --git a/test_fixtures/absolute_minmax_bottom_right_max.html b/test_fixtures/absolute_minmax_bottom_right_max.html new file mode 100644 index 000000000..49b90d674 --- /dev/null +++ b/test_fixtures/absolute_minmax_bottom_right_max.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_minmax_bottom_right_min_max.html b/test_fixtures/absolute_minmax_bottom_right_min_max.html new file mode 100644 index 000000000..16898105a --- /dev/null +++ b/test_fixtures/absolute_minmax_bottom_right_min_max.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_minmax_bottom_right_min_max_preferred.html b/test_fixtures/absolute_minmax_bottom_right_min_max_preferred.html new file mode 100644 index 000000000..a1a27952a --- /dev/null +++ b/test_fixtures/absolute_minmax_bottom_right_min_max_preferred.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_minmax_top_left_bottom_right_max.html b/test_fixtures/absolute_minmax_top_left_bottom_right_max.html new file mode 100644 index 000000000..0c2bf8aa2 --- /dev/null +++ b/test_fixtures/absolute_minmax_top_left_bottom_right_max.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_minmax_top_left_bottom_right_min_max.html b/test_fixtures/absolute_minmax_top_left_bottom_right_min_max.html new file mode 100644 index 000000000..d29b9f0c6 --- /dev/null +++ b/test_fixtures/absolute_minmax_top_left_bottom_right_min_max.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/absolute_minmax_bottom_right_max.rs b/tests/generated/absolute_minmax_bottom_right_max.rs new file mode 100644 index 000000000..19825a2e8 --- /dev/null +++ b/tests/generated/absolute_minmax_bottom_right_max.rs @@ -0,0 +1,53 @@ +#[test] +fn absolute_minmax_bottom_right_max() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height); + assert_eq!(location.x, 50f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, location.x); + assert_eq!(location.y, 60f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, location.y); +} diff --git a/tests/generated/absolute_minmax_bottom_right_min_max.rs b/tests/generated/absolute_minmax_bottom_right_min_max.rs new file mode 100644 index 000000000..16fdc80a7 --- /dev/null +++ b/tests/generated/absolute_minmax_bottom_right_min_max.rs @@ -0,0 +1,53 @@ +#[test] +fn absolute_minmax_bottom_right_min_max() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, location.y); +} diff --git a/tests/generated/absolute_minmax_bottom_right_min_max_preferred.rs b/tests/generated/absolute_minmax_bottom_right_min_max_preferred.rs new file mode 100644 index 000000000..006a1dafc --- /dev/null +++ b/tests/generated/absolute_minmax_bottom_right_min_max_preferred.rs @@ -0,0 +1,57 @@ +#[test] +fn absolute_minmax_bottom_right_min_max_preferred() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(200f32), + height: taffy::style::Dimension::Points(200f32), + }, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: auto(), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: auto(), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 40f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, location.x); + assert_eq!(location.y, 30f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, location.y); +} diff --git a/tests/generated/absolute_minmax_top_left_bottom_right_max.rs b/tests/generated/absolute_minmax_top_left_bottom_right_max.rs new file mode 100644 index 000000000..51b2ef5d1 --- /dev/null +++ b/tests/generated/absolute_minmax_top_left_bottom_right_max.rs @@ -0,0 +1,49 @@ +#[test] +fn absolute_minmax_top_left_bottom_right_max() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 40f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 40f32, size.width); + assert_eq!(size.height, 30f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 30f32, size.height); + assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x); + assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.y); +} diff --git a/tests/generated/absolute_minmax_top_left_bottom_right_min_max.rs b/tests/generated/absolute_minmax_top_left_bottom_right_min_max.rs new file mode 100644 index 000000000..52ca307dd --- /dev/null +++ b/tests/generated/absolute_minmax_top_left_bottom_right_min_max.rs @@ -0,0 +1,53 @@ +#[test] +fn absolute_minmax_top_left_bottom_right_min_max() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(50f32), + height: taffy::style::Dimension::Points(60f32), + }, + max_size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(40f32), + height: taffy::style::Dimension::Points(30f32), + }, + inset: taffy::geometry::Rect { + left: taffy::style::LengthPercentageAuto::Points(10f32), + right: taffy::style::LengthPercentageAuto::Points(10f32), + top: taffy::style::LengthPercentageAuto::Points(10f32), + bottom: taffy::style::LengthPercentageAuto::Points(10f32), + }, + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(100f32), + height: taffy::style::Dimension::Points(100f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 100f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.width); + assert_eq!(size.height, 100f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 100f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 60f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 60f32, size.height); + assert_eq!(location.x, 10f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.x); + assert_eq!(location.y, 10f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 10f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index bf72905d0..4faf7cda6 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -82,6 +82,11 @@ mod absolute_layout_width_height_start_top; mod absolute_layout_width_height_start_top_end_bottom; mod absolute_layout_within_border; mod absolute_margin_bottom_left; +mod absolute_minmax_bottom_right_max; +mod absolute_minmax_bottom_right_min_max; +mod absolute_minmax_bottom_right_min_max_preferred; +mod absolute_minmax_top_left_bottom_right_max; +mod absolute_minmax_top_left_bottom_right_min_max; mod align_baseline; mod align_baseline_child_multiline; mod align_baseline_nested_child; From 94df9c591f120e74c0339ac3ac9c2471c5aa4107 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 11 Jan 2023 00:05:42 +0000 Subject: [PATCH 38/40] Move absolute flex positioning aspect ratio tests under absolute namespace --- ...t_ratio_overrides_height_of_full_inset.rs} | 0 ...s => absolute_aspect_ratio_fill_height.rs} | 0 ...te_aspect_ratio_fill_height_from_inset.rs} | 0 ...rs => absolute_aspect_ratio_fill_width.rs} | 0 ...ute_aspect_ratio_fill_width_from_inset.rs} | 0 ...te_aspect_ratio_height_overrides_inset.rs} | 0 ...ute_aspect_ratio_width_overrides_inset.rs} | 0 benches/generated/mod.rs | 28 +++++++++---------- ...ratio_overrides_height_of_full_inset.html} | 0 ...=> absolute_aspect_ratio_fill_height.html} | 0 ..._aspect_ratio_fill_height_from_inset.html} | 0 ... => absolute_aspect_ratio_fill_width.html} | 0 ...e_aspect_ratio_fill_width_from_inset.html} | 0 ..._aspect_ratio_height_overrides_inset.html} | 0 ...e_aspect_ratio_width_overrides_inset.html} | 0 ...t_ratio_overrides_height_of_full_inset.rs} | 2 +- ...s => absolute_aspect_ratio_fill_height.rs} | 2 +- ...te_aspect_ratio_fill_height_from_inset.rs} | 2 +- ...rs => absolute_aspect_ratio_fill_width.rs} | 2 +- ...ute_aspect_ratio_fill_width_from_inset.rs} | 2 +- ...te_aspect_ratio_height_overrides_inset.rs} | 2 +- ...ute_aspect_ratio_width_overrides_inset.rs} | 2 +- tests/generated/mod.rs | 14 +++++----- 23 files changed, 28 insertions(+), 28 deletions(-) rename benches/generated/{aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs => absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_fill_height.rs => absolute_aspect_ratio_fill_height.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_fill_height_from_inset.rs => absolute_aspect_ratio_fill_height_from_inset.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_fill_width.rs => absolute_aspect_ratio_fill_width.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_fill_width_from_inset.rs => absolute_aspect_ratio_fill_width_from_inset.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_height_overrides_inset.rs => absolute_aspect_ratio_height_overrides_inset.rs} (100%) rename benches/generated/{aspect_ratio_flex_absolute_width_overrides_inset.rs => absolute_aspect_ratio_width_overrides_inset.rs} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html => absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_fill_height.html => absolute_aspect_ratio_fill_height.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_fill_height_from_inset.html => absolute_aspect_ratio_fill_height_from_inset.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_fill_width.html => absolute_aspect_ratio_fill_width.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_fill_width_from_inset.html => absolute_aspect_ratio_fill_width_from_inset.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_height_overrides_inset.html => absolute_aspect_ratio_height_overrides_inset.html} (100%) rename test_fixtures/{aspect_ratio_flex_absolute_width_overrides_inset.html => absolute_aspect_ratio_width_overrides_inset.html} (100%) rename tests/generated/{aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs => absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs} (96%) rename tests/generated/{aspect_ratio_flex_absolute_fill_height.rs => absolute_aspect_ratio_fill_height.rs} (98%) rename tests/generated/{aspect_ratio_flex_absolute_fill_height_from_inset.rs => absolute_aspect_ratio_fill_height_from_inset.rs} (97%) rename tests/generated/{aspect_ratio_flex_absolute_fill_width.rs => absolute_aspect_ratio_fill_width.rs} (98%) rename tests/generated/{aspect_ratio_flex_absolute_fill_width_from_inset.rs => absolute_aspect_ratio_fill_width_from_inset.rs} (97%) rename tests/generated/{aspect_ratio_flex_absolute_height_overrides_inset.rs => absolute_aspect_ratio_height_overrides_inset.rs} (97%) rename tests/generated/{aspect_ratio_flex_absolute_width_overrides_inset.rs => absolute_aspect_ratio_width_overrides_inset.rs} (97%) diff --git a/benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/benches/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs rename to benches/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_height.rs b/benches/generated/absolute_aspect_ratio_fill_height.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_fill_height.rs rename to benches/generated/absolute_aspect_ratio_fill_height.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs b/benches/generated/absolute_aspect_ratio_fill_height_from_inset.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs rename to benches/generated/absolute_aspect_ratio_fill_height_from_inset.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_width.rs b/benches/generated/absolute_aspect_ratio_fill_width.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_fill_width.rs rename to benches/generated/absolute_aspect_ratio_fill_width.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs b/benches/generated/absolute_aspect_ratio_fill_width_from_inset.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs rename to benches/generated/absolute_aspect_ratio_fill_width_from_inset.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs b/benches/generated/absolute_aspect_ratio_height_overrides_inset.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs rename to benches/generated/absolute_aspect_ratio_height_overrides_inset.rs diff --git a/benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs b/benches/generated/absolute_aspect_ratio_width_overrides_inset.rs similarity index 100% rename from benches/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs rename to benches/generated/absolute_aspect_ratio_width_overrides_inset.rs diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 587867b61..7cfb0f8b1 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -61,6 +61,13 @@ fn measure_standard_text( WritingMode::Vertical => Size { width: block_size, height: inline_size }, } } +mod absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset; +mod absolute_aspect_ratio_fill_height; +mod absolute_aspect_ratio_fill_height_from_inset; +mod absolute_aspect_ratio_fill_width; +mod absolute_aspect_ratio_fill_width_from_inset; +mod absolute_aspect_ratio_height_overrides_inset; +mod absolute_aspect_ratio_width_overrides_inset; mod absolute_layout_align_items_and_justify_content_center; mod absolute_layout_align_items_and_justify_content_center_and_bottom_position; mod absolute_layout_align_items_and_justify_content_center_and_left_position; @@ -118,13 +125,6 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset; -mod aspect_ratio_flex_absolute_fill_height; -mod aspect_ratio_flex_absolute_fill_height_from_inset; -mod aspect_ratio_flex_absolute_fill_width; -mod aspect_ratio_flex_absolute_fill_width_from_inset; -mod aspect_ratio_flex_absolute_height_overrides_inset; -mod aspect_ratio_flex_absolute_width_overrides_inset; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; @@ -656,6 +656,13 @@ mod wrapped_row_within_align_items_flex_start; fn benchmark(c: &mut Criterion) { c.bench_function("generated benchmarks", |b| { b.iter(|| { + absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset::compute(); + absolute_aspect_ratio_fill_height::compute(); + absolute_aspect_ratio_fill_height_from_inset::compute(); + absolute_aspect_ratio_fill_width::compute(); + absolute_aspect_ratio_fill_width_from_inset::compute(); + absolute_aspect_ratio_height_overrides_inset::compute(); + absolute_aspect_ratio_width_overrides_inset::compute(); absolute_layout_align_items_and_justify_content_center::compute(); absolute_layout_align_items_and_justify_content_center_and_bottom_position::compute(); absolute_layout_align_items_and_justify_content_center_and_left_position::compute(); @@ -713,13 +720,6 @@ fn benchmark(c: &mut Criterion) { align_self_flex_end_override_flex_start::compute(); align_self_flex_start::compute(); align_stretch_should_size_based_on_parent::compute(); - aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset::compute(); - aspect_ratio_flex_absolute_fill_height::compute(); - aspect_ratio_flex_absolute_fill_height_from_inset::compute(); - aspect_ratio_flex_absolute_fill_width::compute(); - aspect_ratio_flex_absolute_fill_width_from_inset::compute(); - aspect_ratio_flex_absolute_height_overrides_inset::compute(); - aspect_ratio_flex_absolute_width_overrides_inset::compute(); aspect_ratio_flex_column_fill_height::compute(); aspect_ratio_flex_column_fill_max_height::compute(); aspect_ratio_flex_column_fill_max_width::compute(); diff --git a/test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html b/test_fixtures/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.html rename to test_fixtures/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_height.html b/test_fixtures/absolute_aspect_ratio_fill_height.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_fill_height.html rename to test_fixtures/absolute_aspect_ratio_fill_height.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html b/test_fixtures/absolute_aspect_ratio_fill_height_from_inset.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_fill_height_from_inset.html rename to test_fixtures/absolute_aspect_ratio_fill_height_from_inset.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_width.html b/test_fixtures/absolute_aspect_ratio_fill_width.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_fill_width.html rename to test_fixtures/absolute_aspect_ratio_fill_width.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html b/test_fixtures/absolute_aspect_ratio_fill_width_from_inset.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_fill_width_from_inset.html rename to test_fixtures/absolute_aspect_ratio_fill_width_from_inset.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html b/test_fixtures/absolute_aspect_ratio_height_overrides_inset.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_height_overrides_inset.html rename to test_fixtures/absolute_aspect_ratio_height_overrides_inset.html diff --git a/test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html b/test_fixtures/absolute_aspect_ratio_width_overrides_inset.html similarity index 100% rename from test_fixtures/aspect_ratio_flex_absolute_width_overrides_inset.html rename to test_fixtures/absolute_aspect_ratio_width_overrides_inset.html diff --git a/tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs b/tests/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs similarity index 96% rename from tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs rename to tests/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs index 204bafa12..26b9c034b 100644 --- a/tests/generated/aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset.rs +++ b/tests/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset() { +fn absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_height.rs b/tests/generated/absolute_aspect_ratio_fill_height.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_absolute_fill_height.rs rename to tests/generated/absolute_aspect_ratio_fill_height.rs index 2b818698f..6f15c88f9 100644 --- a/tests/generated/aspect_ratio_flex_absolute_fill_height.rs +++ b/tests/generated/absolute_aspect_ratio_fill_height.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_fill_height() { +fn absolute_aspect_ratio_fill_height() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs b/tests/generated/absolute_aspect_ratio_fill_height_from_inset.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs rename to tests/generated/absolute_aspect_ratio_fill_height_from_inset.rs index df896a853..55718abc0 100644 --- a/tests/generated/aspect_ratio_flex_absolute_fill_height_from_inset.rs +++ b/tests/generated/absolute_aspect_ratio_fill_height_from_inset.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_fill_height_from_inset() { +fn absolute_aspect_ratio_fill_height_from_inset() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_width.rs b/tests/generated/absolute_aspect_ratio_fill_width.rs similarity index 98% rename from tests/generated/aspect_ratio_flex_absolute_fill_width.rs rename to tests/generated/absolute_aspect_ratio_fill_width.rs index eacc05c31..a69a193fb 100644 --- a/tests/generated/aspect_ratio_flex_absolute_fill_width.rs +++ b/tests/generated/absolute_aspect_ratio_fill_width.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_fill_width() { +fn absolute_aspect_ratio_fill_width() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs b/tests/generated/absolute_aspect_ratio_fill_width_from_inset.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs rename to tests/generated/absolute_aspect_ratio_fill_width_from_inset.rs index 97b5340e3..b7e8c524e 100644 --- a/tests/generated/aspect_ratio_flex_absolute_fill_width_from_inset.rs +++ b/tests/generated/absolute_aspect_ratio_fill_width_from_inset.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_fill_width_from_inset() { +fn absolute_aspect_ratio_fill_width_from_inset() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs b/tests/generated/absolute_aspect_ratio_height_overrides_inset.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs rename to tests/generated/absolute_aspect_ratio_height_overrides_inset.rs index 7cd5658fa..5c2165548 100644 --- a/tests/generated/aspect_ratio_flex_absolute_height_overrides_inset.rs +++ b/tests/generated/absolute_aspect_ratio_height_overrides_inset.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_height_overrides_inset() { +fn absolute_aspect_ratio_height_overrides_inset() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs b/tests/generated/absolute_aspect_ratio_width_overrides_inset.rs similarity index 97% rename from tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs rename to tests/generated/absolute_aspect_ratio_width_overrides_inset.rs index 749d6fa28..97a8052ea 100644 --- a/tests/generated/aspect_ratio_flex_absolute_width_overrides_inset.rs +++ b/tests/generated/absolute_aspect_ratio_width_overrides_inset.rs @@ -1,5 +1,5 @@ #[test] -fn aspect_ratio_flex_absolute_width_overrides_inset() { +fn absolute_aspect_ratio_width_overrides_inset() { use slotmap::Key; #[allow(unused_imports)] use taffy::{layout::Layout, prelude::*}; diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index 4faf7cda6..b2027bc75 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -60,6 +60,13 @@ fn measure_standard_text( WritingMode::Vertical => Size { width: block_size, height: inline_size }, } } +mod absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset; +mod absolute_aspect_ratio_fill_height; +mod absolute_aspect_ratio_fill_height_from_inset; +mod absolute_aspect_ratio_fill_width; +mod absolute_aspect_ratio_fill_width_from_inset; +mod absolute_aspect_ratio_height_overrides_inset; +mod absolute_aspect_ratio_width_overrides_inset; mod absolute_layout_align_items_and_justify_content_center; mod absolute_layout_align_items_and_justify_content_center_and_bottom_position; mod absolute_layout_align_items_and_justify_content_center_and_left_position; @@ -117,13 +124,6 @@ mod align_self_flex_end; mod align_self_flex_end_override_flex_start; mod align_self_flex_start; mod align_stretch_should_size_based_on_parent; -mod aspect_ratio_flex_absolute_aspect_ratio_overrides_height_of_full_inset; -mod aspect_ratio_flex_absolute_fill_height; -mod aspect_ratio_flex_absolute_fill_height_from_inset; -mod aspect_ratio_flex_absolute_fill_width; -mod aspect_ratio_flex_absolute_fill_width_from_inset; -mod aspect_ratio_flex_absolute_height_overrides_inset; -mod aspect_ratio_flex_absolute_width_overrides_inset; mod aspect_ratio_flex_column_fill_height; mod aspect_ratio_flex_column_fill_max_height; mod aspect_ratio_flex_column_fill_max_width; From 1ded18f128da87d7c8498a602ba3635b74ae5407 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 11 Jan 2023 00:13:47 +0000 Subject: [PATCH 39/40] Clamp available_space by min/max size for final layout --- src/compute/flexbox.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compute/flexbox.rs b/src/compute/flexbox.rs index e93bc824b..da92c3b31 100644 --- a/src/compute/flexbox.rs +++ b/src/compute/flexbox.rs @@ -1641,8 +1641,8 @@ fn perform_absolute_layout_on_absolute_children(tree: &mut impl LayoutTree, node known_dimensions, constants.node_inner_size, Size { - width: AvailableSpace::Definite(container_width), - height: AvailableSpace::Definite(container_height), + width: AvailableSpace::Definite(container_width.maybe_clamp(min_size.width, max_size.width)), + height: AvailableSpace::Definite(container_height.maybe_clamp(min_size.height, max_size.height)), }, RunMode::PeformLayout, SizingMode::ContentSize, From 355477edc2717dab5497516cf8a18ed44870e469 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Wed, 11 Jan 2023 00:14:49 +0000 Subject: [PATCH 40/40] Add tests for applying aspect ratio to min/max size of flex items --- .../absolute_aspect_ratio_fill_max_height.rs | 20 +++++++++ .../absolute_aspect_ratio_fill_max_width.rs | 20 +++++++++ .../absolute_aspect_ratio_fill_min_height.rs | 27 ++++++++++++ .../absolute_aspect_ratio_fill_min_width.rs | 27 ++++++++++++ benches/generated/mod.rs | 8 ++++ ...absolute_aspect_ratio_fill_max_height.html | 17 ++++++++ .../absolute_aspect_ratio_fill_max_width.html | 17 ++++++++ ...absolute_aspect_ratio_fill_min_height.html | 17 ++++++++ .../absolute_aspect_ratio_fill_min_width.html | 17 ++++++++ .../absolute_aspect_ratio_fill_max_height.rs | 35 ++++++++++++++++ .../absolute_aspect_ratio_fill_max_width.rs | 35 ++++++++++++++++ .../absolute_aspect_ratio_fill_min_height.rs | 42 +++++++++++++++++++ .../absolute_aspect_ratio_fill_min_width.rs | 42 +++++++++++++++++++ tests/generated/mod.rs | 4 ++ 14 files changed, 328 insertions(+) create mode 100644 benches/generated/absolute_aspect_ratio_fill_max_height.rs create mode 100644 benches/generated/absolute_aspect_ratio_fill_max_width.rs create mode 100644 benches/generated/absolute_aspect_ratio_fill_min_height.rs create mode 100644 benches/generated/absolute_aspect_ratio_fill_min_width.rs create mode 100644 test_fixtures/absolute_aspect_ratio_fill_max_height.html create mode 100644 test_fixtures/absolute_aspect_ratio_fill_max_width.html create mode 100644 test_fixtures/absolute_aspect_ratio_fill_min_height.html create mode 100644 test_fixtures/absolute_aspect_ratio_fill_min_width.html create mode 100644 tests/generated/absolute_aspect_ratio_fill_max_height.rs create mode 100644 tests/generated/absolute_aspect_ratio_fill_max_width.rs create mode 100644 tests/generated/absolute_aspect_ratio_fill_min_height.rs create mode 100644 tests/generated/absolute_aspect_ratio_fill_min_width.rs diff --git a/benches/generated/absolute_aspect_ratio_fill_max_height.rs b/benches/generated/absolute_aspect_ratio_fill_max_height.rs new file mode 100644 index 000000000..f3174beeb --- /dev/null +++ b/benches/generated/absolute_aspect_ratio_fill_max_height.rs @@ -0,0 +1,20 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { position : taffy :: style :: Position :: Absolute , max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (50f32) , height : auto () , } , aspect_ratio : Some (3f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (3f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_aspect_ratio_fill_max_width.rs b/benches/generated/absolute_aspect_ratio_fill_max_width.rs new file mode 100644 index 000000000..69b2fd603 --- /dev/null +++ b/benches/generated/absolute_aspect_ratio_fill_max_width.rs @@ -0,0 +1,20 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { position : taffy :: style :: Position :: Absolute , max_size : taffy :: geometry :: Size { width : auto () , height : taffy :: style :: Dimension :: Points (50f32) , } , aspect_ratio : Some (0.5f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (0.5f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_aspect_ratio_fill_min_height.rs b/benches/generated/absolute_aspect_ratio_fill_min_height.rs new file mode 100644 index 000000000..f2fa1084c --- /dev/null +++ b/benches/generated/absolute_aspect_ratio_fill_min_height.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(3f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/absolute_aspect_ratio_fill_min_width.rs b/benches/generated/absolute_aspect_ratio_fill_min_width.rs new file mode 100644 index 000000000..06d3649a5 --- /dev/null +++ b/benches/generated/absolute_aspect_ratio_fill_min_width.rs @@ -0,0 +1,27 @@ +pub fn compute() { + #[allow(unused_imports)] + use taffy::prelude::*; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(0.5f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); +} diff --git a/benches/generated/mod.rs b/benches/generated/mod.rs index 7cfb0f8b1..14b307b64 100644 --- a/benches/generated/mod.rs +++ b/benches/generated/mod.rs @@ -64,6 +64,10 @@ fn measure_standard_text( mod absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset; mod absolute_aspect_ratio_fill_height; mod absolute_aspect_ratio_fill_height_from_inset; +mod absolute_aspect_ratio_fill_max_height; +mod absolute_aspect_ratio_fill_max_width; +mod absolute_aspect_ratio_fill_min_height; +mod absolute_aspect_ratio_fill_min_width; mod absolute_aspect_ratio_fill_width; mod absolute_aspect_ratio_fill_width_from_inset; mod absolute_aspect_ratio_height_overrides_inset; @@ -659,6 +663,10 @@ fn benchmark(c: &mut Criterion) { absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset::compute(); absolute_aspect_ratio_fill_height::compute(); absolute_aspect_ratio_fill_height_from_inset::compute(); + absolute_aspect_ratio_fill_max_height::compute(); + absolute_aspect_ratio_fill_max_width::compute(); + absolute_aspect_ratio_fill_min_height::compute(); + absolute_aspect_ratio_fill_min_width::compute(); absolute_aspect_ratio_fill_width::compute(); absolute_aspect_ratio_fill_width_from_inset::compute(); absolute_aspect_ratio_height_overrides_inset::compute(); diff --git a/test_fixtures/absolute_aspect_ratio_fill_max_height.html b/test_fixtures/absolute_aspect_ratio_fill_max_height.html new file mode 100644 index 000000000..cbeea766d --- /dev/null +++ b/test_fixtures/absolute_aspect_ratio_fill_max_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_aspect_ratio_fill_max_width.html b/test_fixtures/absolute_aspect_ratio_fill_max_width.html new file mode 100644 index 000000000..aaab17279 --- /dev/null +++ b/test_fixtures/absolute_aspect_ratio_fill_max_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH​HHHH
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_aspect_ratio_fill_min_height.html b/test_fixtures/absolute_aspect_ratio_fill_min_height.html new file mode 100644 index 000000000..4c6b72080 --- /dev/null +++ b/test_fixtures/absolute_aspect_ratio_fill_min_height.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/test_fixtures/absolute_aspect_ratio_fill_min_width.html b/test_fixtures/absolute_aspect_ratio_fill_min_width.html new file mode 100644 index 000000000..a5d5fcfc3 --- /dev/null +++ b/test_fixtures/absolute_aspect_ratio_fill_min_width.html @@ -0,0 +1,17 @@ + + + + + + + Test description + + + + +
+
+
+ + + \ No newline at end of file diff --git a/tests/generated/absolute_aspect_ratio_fill_max_height.rs b/tests/generated/absolute_aspect_ratio_fill_max_height.rs new file mode 100644 index 000000000..4eb2afcbd --- /dev/null +++ b/tests/generated/absolute_aspect_ratio_fill_max_height.rs @@ -0,0 +1,35 @@ +#[test] +fn absolute_aspect_ratio_fill_max_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { position : taffy :: style :: Position :: Absolute , max_size : taffy :: geometry :: Size { width : taffy :: style :: Dimension :: Points (50f32) , height : auto () , } , aspect_ratio : Some (3f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (3f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 17f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 17f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/absolute_aspect_ratio_fill_max_width.rs b/tests/generated/absolute_aspect_ratio_fill_max_width.rs new file mode 100644 index 000000000..b5174abec --- /dev/null +++ b/tests/generated/absolute_aspect_ratio_fill_max_width.rs @@ -0,0 +1,35 @@ +#[test] +fn absolute_aspect_ratio_fill_max_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy . new_leaf_with_measure (taffy :: style :: Style { position : taffy :: style :: Position :: Absolute , max_size : taffy :: geometry :: Size { width : auto () , height : taffy :: style :: Dimension :: Points (50f32) , } , aspect_ratio : Some (0.5f32) , .. Default :: default () } , taffy :: node :: MeasureFunc :: Raw (| known_dimensions , available_space | { const TEXT : & str = "HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH\u{200b}HHHH" ; super :: measure_standard_text (known_dimensions , available_space , TEXT , super :: WritingMode :: Horizontal , Some (0.5f32)) }) ,) . unwrap () ; + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 25f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/absolute_aspect_ratio_fill_min_height.rs b/tests/generated/absolute_aspect_ratio_fill_min_height.rs new file mode 100644 index 000000000..939b47849 --- /dev/null +++ b/tests/generated/absolute_aspect_ratio_fill_min_height.rs @@ -0,0 +1,42 @@ +#[test] +fn absolute_aspect_ratio_fill_min_height() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { width: taffy::style::Dimension::Points(50f32), height: auto() }, + aspect_ratio: Some(3f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 50f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.width); + assert_eq!(size.height, 17f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 17f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/absolute_aspect_ratio_fill_min_width.rs b/tests/generated/absolute_aspect_ratio_fill_min_width.rs new file mode 100644 index 000000000..e91f28059 --- /dev/null +++ b/tests/generated/absolute_aspect_ratio_fill_min_width.rs @@ -0,0 +1,42 @@ +#[test] +fn absolute_aspect_ratio_fill_min_width() { + use slotmap::Key; + #[allow(unused_imports)] + use taffy::{layout::Layout, prelude::*}; + let mut taffy = taffy::Taffy::new(); + let node0 = taffy + .new_leaf(taffy::style::Style { + position: taffy::style::Position::Absolute, + min_size: taffy::geometry::Size { width: auto(), height: taffy::style::Dimension::Points(50f32) }, + aspect_ratio: Some(0.5f32), + ..Default::default() + }) + .unwrap(); + let node = taffy + .new_with_children( + taffy::style::Style { + display: taffy::style::Display::Flex, + size: taffy::geometry::Size { + width: taffy::style::Dimension::Points(400f32), + height: taffy::style::Dimension::Points(300f32), + }, + ..Default::default() + }, + &[node0], + ) + .unwrap(); + taffy.compute_layout(node, taffy::geometry::Size::MAX_CONTENT).unwrap(); + println!("\nComputed tree:"); + taffy::debug::print_tree(&taffy, node); + println!(); + let Layout { size, location, .. } = taffy.layout(node).unwrap(); + assert_eq!(size.width, 400f32, "width of node {:?}. Expected {}. Actual {}", node.data(), 400f32, size.width); + assert_eq!(size.height, 300f32, "height of node {:?}. Expected {}. Actual {}", node.data(), 300f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node.data(), 0f32, location.y); + let Layout { size, location, .. } = taffy.layout(node0).unwrap(); + assert_eq!(size.width, 25f32, "width of node {:?}. Expected {}. Actual {}", node0.data(), 25f32, size.width); + assert_eq!(size.height, 50f32, "height of node {:?}. Expected {}. Actual {}", node0.data(), 50f32, size.height); + assert_eq!(location.x, 0f32, "x of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.x); + assert_eq!(location.y, 0f32, "y of node {:?}. Expected {}. Actual {}", node0.data(), 0f32, location.y); +} diff --git a/tests/generated/mod.rs b/tests/generated/mod.rs index b2027bc75..659a0cd77 100644 --- a/tests/generated/mod.rs +++ b/tests/generated/mod.rs @@ -63,6 +63,10 @@ fn measure_standard_text( mod absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset; mod absolute_aspect_ratio_fill_height; mod absolute_aspect_ratio_fill_height_from_inset; +mod absolute_aspect_ratio_fill_max_height; +mod absolute_aspect_ratio_fill_max_width; +mod absolute_aspect_ratio_fill_min_height; +mod absolute_aspect_ratio_fill_min_width; mod absolute_aspect_ratio_fill_width; mod absolute_aspect_ratio_fill_width_from_inset; mod absolute_aspect_ratio_height_overrides_inset;