956 lines
32 KiB
MoonBit
956 lines
32 KiB
MoonBit
// Copyright 2025 International Digital Economy Academy
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
///|
|
|
test "upstream/generated/flex/justify_content_row_max_width_and_margin" {
|
|
// Ported from taffy-reference/tests/generated/flex/justify_content_row_max_width_and_margin.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(20.0), height=length(20.0)))
|
|
.with_margin(
|
|
Rect(
|
|
left=length(100.0),
|
|
right=length(0.0),
|
|
top=length(0.0),
|
|
bottom=length(0.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_size(Size(width=length(100.0), height=auto()))
|
|
.with_max_size(Size(width=length(80.0), height=auto())),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 80.0)
|
|
assert_eq(lnode.size.height, 20.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 0.0)
|
|
assert_eq(l0.size.height, 20.0)
|
|
assert_eq(l0.location.x, 90.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/justify_content_row_min_width_and_margin" {
|
|
// Ported from taffy-reference/tests/generated/flex/justify_content_row_min_width_and_margin.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(20.0), height=length(20.0)))
|
|
.with_margin(
|
|
Rect(
|
|
left=length(10.0),
|
|
right=length(0.0),
|
|
top=length(0.0),
|
|
bottom=length(0.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_min_size(Size(width=length(50.0), height=auto())),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 50.0)
|
|
assert_eq(lnode.size.height, 20.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 20.0)
|
|
assert_eq(l0.size.height, 20.0)
|
|
assert_eq(l0.location.x, 20.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/justify_content_row_space_around" {
|
|
// Ported from taffy-reference/tests/generated/flex/justify_content_row_space_around.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node2 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_space_around())
|
|
.with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0, node1, node2],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 10.0)
|
|
assert_eq(l0.size.height, 100.0)
|
|
assert_eq(l0.location.x, 12.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 10.0)
|
|
assert_eq(l1.size.height, 100.0)
|
|
assert_eq(l1.location.x, 45.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
let l2 = taffy.layout(node2)
|
|
assert_eq(l2.size.width, 10.0)
|
|
assert_eq(l2.size.height, 100.0)
|
|
assert_eq(l2.location.x, 78.0)
|
|
assert_eq(l2.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/justify_content_row_space_between" {
|
|
// Ported from taffy-reference/tests/generated/flex/justify_content_row_space_between.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node2 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(10.0), height=auto())),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_space_between())
|
|
.with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0, node1, node2],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 10.0)
|
|
assert_eq(l0.size.height, 100.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 10.0)
|
|
assert_eq(l1.size.height, 100.0)
|
|
assert_eq(l1.location.x, 45.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
let l2 = taffy.layout(node2)
|
|
assert_eq(l2.size.width, 10.0)
|
|
assert_eq(l2.size.height, 100.0)
|
|
assert_eq(l2.location.x, 90.0)
|
|
assert_eq(l2.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/justify_content_row_space_evenly" {
|
|
// Ported from taffy-reference/tests/generated/flex/justify_content_row_space_evenly.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=auto(), height=length(10.0))),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=auto(), height=length(10.0))),
|
|
)
|
|
let node2 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=auto(), height=length(10.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_space_evenly())
|
|
.with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0, node1, node2],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 0.0)
|
|
assert_eq(l0.size.height, 10.0)
|
|
assert_eq(l0.location.x, 25.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 0.0)
|
|
assert_eq(l1.size.height, 10.0)
|
|
assert_eq(l1.location.x, 50.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
let l2 = taffy.layout(node2)
|
|
assert_eq(l2.size.width, 0.0)
|
|
assert_eq(l2.size.height, 10.0)
|
|
assert_eq(l2.location.x, 75.0)
|
|
assert_eq(l2.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_and_flex_column" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_and_flex_column.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_flex_grow(1.0)
|
|
.with_margin(
|
|
Rect(
|
|
left=length(0.0),
|
|
right=length(0.0),
|
|
top=length(10.0),
|
|
bottom=length(10.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_flex_direction(flex_direction_column())
|
|
.with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 100.0)
|
|
assert_eq(l0.size.height, 80.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 10.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_and_flex_row" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_and_flex_row.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_flex_grow(1.0)
|
|
.with_margin(
|
|
Rect(
|
|
left=length(10.0),
|
|
right=length(10.0),
|
|
top=length(0.0),
|
|
bottom=length(0.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default().with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 80.0)
|
|
assert_eq(l0.size.height, 100.0)
|
|
assert_eq(l0.location.x, 10.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_and_stretch_column" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_and_stretch_column.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_flex_grow(1.0)
|
|
.with_margin(
|
|
Rect(
|
|
left=length(10.0),
|
|
right=length(10.0),
|
|
top=length(0.0),
|
|
bottom=length(0.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_flex_direction(flex_direction_column())
|
|
.with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 80.0)
|
|
assert_eq(l0.size.height, 100.0)
|
|
assert_eq(l0.location.x, 10.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_and_stretch_row" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_and_stretch_row.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_flex_grow(1.0)
|
|
.with_margin(
|
|
Rect(
|
|
left=length(0.0),
|
|
right=length(0.0),
|
|
top=length(10.0),
|
|
bottom=length(10.0),
|
|
),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default().with_size(Size(width=length(100.0), height=length(100.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 100.0)
|
|
assert_eq(lnode.size.height, 100.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 100.0)
|
|
assert_eq(l0.size.height, 80.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 10.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_bottom" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_bottom.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=length(0.0), bottom=auto()),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 50.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_bottom_and_top" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_bottom_and_top.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=auto(), bottom=auto()),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 50.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_bottom_and_top_justify_center" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_bottom_and_top_justify_center.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=auto(), bottom=auto()),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 50.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 100.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=length(0.0), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 100.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_and_right" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_and_right.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default().with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 50.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_and_right_column" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_and_right_column.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 50.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_and_right_column_and_center" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_and_right_column_and_center.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 50.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_and_right_stretch" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_and_right_stretch.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_stretch())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 50.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_child_bigger_than_parent" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_child_bigger_than_parent.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(72.0), height=length(72.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=length(0.0), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_size(Size(width=length(52.0), height=length(52.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 52.0)
|
|
assert_eq(lnode.size.height, 52.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 52.0)
|
|
assert_eq(l0.size.height, 72.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_fix_right_child_bigger_than_parent" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_fix_right_child_bigger_than_parent.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(72.0), height=length(72.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=length(10.0), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_size(Size(width=length(52.0), height=length(52.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 52.0)
|
|
assert_eq(lnode.size.height, 52.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 42.0)
|
|
assert_eq(l0.size.height, 72.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_right_child_bigger_than_parent" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_right_child_bigger_than_parent.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(72.0), height=length(72.0)))
|
|
.with_margin(
|
|
Rect(left=auto(), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_justify_content(justify_content_center())
|
|
.with_size(Size(width=length(52.0), height=length(52.0))),
|
|
[node0],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 52.0)
|
|
assert_eq(lnode.size.height, 52.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 52.0)
|
|
assert_eq(l0.size.height, 72.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 0.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_left_stretching_child" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_left_stretching_child.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_flex_grow(1.0)
|
|
.with_flex_shrink(1.0)
|
|
.with_flex_basis(percent(0.0))
|
|
.with_margin(
|
|
Rect(left=auto(), right=length(0.0), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 150.0)
|
|
assert_eq(l0.size.height, 0.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 100.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_multiple_children_column" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_multiple_children_column.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=auto(), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=auto(), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node2 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_flex_direction(flex_direction_column())
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1, node2],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 75.0)
|
|
assert_eq(l0.location.y, 25.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 75.0)
|
|
assert_eq(l1.location.y, 100.0)
|
|
let l2 = taffy.layout(node2)
|
|
assert_eq(l2.size.width, 50.0)
|
|
assert_eq(l2.size.height, 50.0)
|
|
assert_eq(l2.location.x, 75.0)
|
|
assert_eq(l2.location.y, 150.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_multiple_children_row" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_multiple_children_row.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node2 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1, node2],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 75.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
let l2 = taffy.layout(node2)
|
|
assert_eq(l2.size.width, 50.0)
|
|
assert_eq(l2.size.height, 50.0)
|
|
assert_eq(l2.location.x, 150.0)
|
|
assert_eq(l2.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_right" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_right.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=auto(), top=length(0.0), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 75.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 150.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|
|
|
|
///|
|
|
test "upstream/generated/flex/margin_auto_top" {
|
|
// Ported from taffy-reference/tests/generated/flex/margin_auto_top.rs
|
|
let taffy : ChicleTree[TextMeasure] = ChicleTree()
|
|
let node0 = taffy.new_leaf(
|
|
Style::default()
|
|
.with_size(Size(width=length(50.0), height=length(50.0)))
|
|
.with_margin(
|
|
Rect(left=length(0.0), right=length(0.0), top=auto(), bottom=length(0.0)),
|
|
),
|
|
)
|
|
let node1 = taffy.new_leaf(
|
|
Style::default().with_size(Size(width=length(50.0), height=length(50.0))),
|
|
)
|
|
let node = taffy.new_with_children(
|
|
Style::default()
|
|
.with_align_items(align_items_center())
|
|
.with_size(Size(width=length(200.0), height=length(200.0))),
|
|
[node0, node1],
|
|
)
|
|
taffy.compute_layout_with_measure(node, Size::max_content(), measure_text)
|
|
let lnode = taffy.layout(node)
|
|
assert_eq(lnode.size.width, 200.0)
|
|
assert_eq(lnode.size.height, 200.0)
|
|
assert_eq(lnode.location.x, 0.0)
|
|
assert_eq(lnode.location.y, 0.0)
|
|
let l0 = taffy.layout(node0)
|
|
assert_eq(l0.size.width, 50.0)
|
|
assert_eq(l0.size.height, 50.0)
|
|
assert_eq(l0.location.x, 0.0)
|
|
assert_eq(l0.location.y, 150.0)
|
|
let l1 = taffy.layout(node1)
|
|
assert_eq(l1.size.width, 50.0)
|
|
assert_eq(l1.size.height, 50.0)
|
|
assert_eq(l1.location.x, 50.0)
|
|
assert_eq(l1.location.y, 75.0)
|
|
}
|