Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,155 @@ mod tests {
assert!((b_top - a_bottom - 40.).abs() <= 1e-5);
}

#[test]
fn block_layouts_respect_align_content() {
let mut app = setup_ui_test_app();
let world = app.world_mut();
let child = world
.spawn(Node {
height: px(20),
..default()
})
.id();
world
.spawn(Node {
display: Display::Block,
align_content: AlignContent::End,
height: px(100),
..default()
})
.add_child(child);

app.update();

assert_eq!(
app.world()
.get::<UiGlobalTransform>(child)
.map(|transform| transform.translation.y),
Some(90.)
);
}

#[test]
fn test_border_radius_updates() {
let mut app = setup_ui_test_app();

let entity = app
.world_mut()
.spawn((Node {
height: px(100),
width: px(50),
..default()
},))
.id();

app.update();

let computed = app.world().get::<ComputedNode>(entity).unwrap();
assert_eq!(computed.border_radius, ResolvedBorderRadius::ZERO);

app.world_mut()
.get_mut::<Node>(entity)
.unwrap()
.border_radius = BorderRadius::all(px(10));

app.update();

let computed = app.world().get::<ComputedNode>(entity).unwrap();
assert_eq!(
computed.border_radius,
ResolvedBorderRadius {
top_left: Vec2::splat(10.),
top_right: Vec2::splat(10.),
bottom_left: Vec2::splat(10.),
bottom_right: Vec2::splat(10.)
}
);

app.world_mut()
.get_mut::<Node>(entity)
.unwrap()
.border_radius
.top_left = CornerRadius::circular(vh(30));

app.update();

assert_eq!(
app.world()
.get::<ComputedNode>(entity)
.unwrap()
.border_radius,
ResolvedBorderRadius {
top_left: Vec2::splat(TARGET_HEIGHT as f32 * 30. / 100.).min(Vec2::splat(25.)),
top_right: Vec2::splat(10.),
bottom_left: Vec2::splat(10.),
bottom_right: Vec2::splat(10.)
}
);

let border_radius = &mut app
.world_mut()
.get_mut::<Node>(entity)
.unwrap()
.border_radius;
border_radius.top_right = CornerRadius::circular(percent(100));
border_radius.bottom_left = CornerRadius::new(percent(100), percent(100));

app.update();

assert_eq!(
app.world()
.get::<ComputedNode>(entity)
.unwrap()
.border_radius,
ResolvedBorderRadius {
top_left: Vec2::splat(TARGET_HEIGHT as f32 * 30. / 100.).min(Vec2::splat(25.)),
top_right: Vec2::splat(25.),
bottom_left: Vec2::new(25., 50.),
bottom_right: Vec2::splat(10.)
}
);

app.world_mut().get_mut::<Node>(entity).unwrap().width = px(200.);

app.update();

assert_eq!(
app.world()
.get::<ComputedNode>(entity)
.unwrap()
.border_radius,
ResolvedBorderRadius {
top_left: Vec2::splat(TARGET_HEIGHT as f32 * 30. / 100.).min(Vec2::splat(50.)),
top_right: Vec2::splat(50.),
bottom_left: Vec2::new(100., 50.),
bottom_right: Vec2::splat(10.)
}
);

let world = app.world_mut();
let mut camera_query = world.query::<&mut Camera>();
camera_query
.single_mut(world)
.unwrap()
.viewport
.as_mut()
.unwrap()
.physical_size
.y = TARGET_HEIGHT / 2;

app.update();

assert_eq!(
app.world()
.get::<ComputedNode>(entity)
.unwrap()
.border_radius
.top_left,
Vec2::splat(15.)
);
}

#[cfg(feature = "ghost_nodes")]
mod ghost_node_tests {
use super::*;
Expand Down