dioxus/packages/tui/tests/margin.rs

92 lines
3 KiB
Rust
Raw Normal View History

2022-01-01 04:53:37 +00:00
#[test]
fn margin_and_flex_row() {
2022-06-10 22:47:43 +00:00
let mut taffy = taffy::Taffy::new();
let node0 = taffy
2022-01-01 04:53:37 +00:00
.new_node(
2022-06-10 22:47:43 +00:00
taffy::style::Style {
2022-01-01 04:53:37 +00:00
flex_grow: 1f32,
2022-06-10 22:47:43 +00:00
margin: taffy::geometry::Rect {
start: taffy::style::Dimension::Points(10f32),
end: taffy::style::Dimension::Points(10f32),
2022-01-01 04:53:37 +00:00
..Default::default()
},
..Default::default()
},
&[],
)
.unwrap();
2022-06-10 22:47:43 +00:00
let node = taffy
2022-01-01 04:53:37 +00:00
.new_node(
2022-06-10 22:47:43 +00:00
taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(100f32),
height: taffy::style::Dimension::Points(100f32),
2022-01-01 04:53:37 +00:00
},
..Default::default()
},
&[node0],
)
.unwrap();
2022-06-10 22:47:43 +00:00
taffy
.compute_layout(node, taffy::geometry::Size::undefined())
2022-01-01 04:53:37 +00:00
.unwrap();
2022-06-10 22:47:43 +00:00
assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
assert_eq!(taffy.layout(node0).unwrap().size.width, 80f32);
assert_eq!(taffy.layout(node0).unwrap().size.height, 100f32);
assert_eq!(taffy.layout(node0).unwrap().location.x, 10f32);
assert_eq!(taffy.layout(node0).unwrap().location.y, 0f32);
2022-01-01 04:53:37 +00:00
}
#[test]
fn margin_and_flex_row2() {
2022-06-10 22:47:43 +00:00
let mut taffy = taffy::Taffy::new();
let node0 = taffy
2022-01-01 04:53:37 +00:00
.new_node(
2022-06-10 22:47:43 +00:00
taffy::style::Style {
2022-01-01 04:53:37 +00:00
flex_grow: 1f32,
2022-06-10 22:47:43 +00:00
margin: taffy::geometry::Rect {
2022-01-01 04:53:37 +00:00
// left
2022-06-10 22:47:43 +00:00
start: taffy::style::Dimension::Points(10f32),
2022-01-01 04:53:37 +00:00
// right?
2022-06-10 22:47:43 +00:00
end: taffy::style::Dimension::Points(10f32),
2022-01-01 04:53:37 +00:00
// top?
2022-06-10 22:47:43 +00:00
// top: taffy::style::Dimension::Points(10f32),
2022-01-01 04:53:37 +00:00
// bottom?
2022-06-10 22:47:43 +00:00
// bottom: taffy::style::Dimension::Points(10f32),
2022-01-01 04:53:37 +00:00
..Default::default()
},
..Default::default()
},
&[],
)
.unwrap();
2022-06-10 22:47:43 +00:00
let node = taffy
2022-01-01 04:53:37 +00:00
.new_node(
2022-06-10 22:47:43 +00:00
taffy::style::Style {
size: taffy::geometry::Size {
width: taffy::style::Dimension::Points(100f32),
height: taffy::style::Dimension::Points(100f32),
2022-01-01 04:53:37 +00:00
},
..Default::default()
},
&[node0],
)
.unwrap();
2022-06-10 22:47:43 +00:00
taffy
.compute_layout(node, taffy::geometry::Size::undefined())
2022-01-01 04:53:37 +00:00
.unwrap();
2022-06-10 22:47:43 +00:00
assert_eq!(taffy.layout(node).unwrap().size.width, 100f32);
assert_eq!(taffy.layout(node).unwrap().size.height, 100f32);
assert_eq!(taffy.layout(node).unwrap().location.x, 0f32);
assert_eq!(taffy.layout(node).unwrap().location.y, 0f32);
2022-01-01 04:53:37 +00:00
}