Skip to content

Commit

Permalink
Fix tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Feb 13, 2024
1 parent 605cc1d commit 3a7e8f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/layout/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,18 +586,18 @@ mod tests {
);
assert_eq!(
taffy_style.grid_template_rows,
vec![sh::points(10.0), sh::percent(0.5), sh::fr(1.0)]
vec![sh::length(10.0), sh::percent(0.5), sh::fr(1.0)]
);
assert_eq!(
taffy_style.grid_template_columns,
vec![sh::repeat(5, vec![sh::points(10.0)])]
vec![sh::repeat(5, vec![sh::length(10.0)])]
);
assert_eq!(
taffy_style.grid_auto_rows,
vec![
sh::fit_content(taffy::style::LengthPercentage::Length(10.0)),
sh::fit_content(taffy::style::LengthPercentage::Percent(0.25)),
sh::minmax(sh::points(0.0), sh::fr(2.0)),
sh::minmax(sh::length(0.0), sh::fr(2.0)),
]
);
assert_eq!(
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_ui/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ mod tests {
use bevy_window::WindowResized;
use bevy_window::WindowResolution;
use bevy_window::WindowScaleFactorChanged;
use taffy::tree::LayoutTree;
use taffy::TraversePartialTree;

#[test]
fn round_layout_coords_must_round_ties_up() {
Expand Down Expand Up @@ -712,7 +712,7 @@ mod tests {
let ui_parent_node = ui_surface.entity_to_taffy[&ui_parent_entity];

// `ui_parent_node` shouldn't have any children yet
assert_eq!(ui_surface.taffy.child_count(ui_parent_node).unwrap(), 0);
assert_eq!(ui_surface.taffy.child_count(ui_parent_node), 0);

let mut ui_child_entities = (0..10)
.map(|_| {
Expand All @@ -731,7 +731,7 @@ mod tests {
1 + ui_child_entities.len()
);
assert_eq!(
ui_surface.taffy.child_count(ui_parent_node).unwrap(),
ui_surface.taffy.child_count(ui_parent_node),
ui_child_entities.len()
);

Expand Down Expand Up @@ -762,7 +762,7 @@ mod tests {
1 + ui_child_entities.len()
);
assert_eq!(
ui_surface.taffy.child_count(ui_parent_node).unwrap(),
ui_surface.taffy.child_count(ui_parent_node),
ui_child_entities.len()
);

Expand Down Expand Up @@ -853,8 +853,8 @@ mod tests {
let ui_surface = world.resource::<UiSurface>();
let ui_node = ui_surface.entity_to_taffy[&ui_entity];

// a node with a content size needs to be measured
assert!(ui_surface.taffy.needs_measure(ui_node));
// a node with a content size should have taffy context
assert!(ui_surface.taffy.get_node_context(ui_node).is_some());
let layout = ui_surface.get_layout(ui_entity).unwrap();
assert_eq!(layout.size.width, content_size.x);
assert_eq!(layout.size.height, content_size.y);
Expand All @@ -864,8 +864,8 @@ mod tests {
ui_schedule.run(&mut world);

let ui_surface = world.resource::<UiSurface>();
// a node without a content size does not need to be measured
assert!(!ui_surface.taffy.needs_measure(ui_node));
// a node without a content size should not have taffy context
assert!(ui_surface.taffy.get_node_context(ui_node).is_none());

// Without a content size, the node has no width or height constraints so the length of both dimensions is 0.
let layout = ui_surface.get_layout(ui_entity).unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/ui/display_and_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl TargetUpdate for Target<Display> {
Display::Flex => Display::None,
Display::None => Display::Flex,
Display::Grid => unreachable!(),
Display::Block => unreachable!(),
};
format!("{}::{:?} ", Self::NAME, style.display)
}
Expand Down
12 changes: 9 additions & 3 deletions examples/ui/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
// Align content towards the center in the horizontal axis
justify_items: JustifyItems::Center,
// Add 10px padding
padding: UiRect::all(Val::Px(10.)),
// padding: UiRect::all(Val::Px(10.)),
// Add an fr track to take up all the available space at the bottom of the column so that the text nodes
// can be top-aligned. Normally you'd use flexbox for this, but this is the CSS Grid example so we're using grid.
grid_template_rows: vec![GridTrack::auto(), GridTrack::auto(), GridTrack::fr(1.0)],
Expand All @@ -146,15 +146,21 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
font_size: 24.0,
..default()
},
));
).with_style(Style {
padding: UiRect::all(Val::Px(10.)),
..Default::default()
}));
builder.spawn(TextBundle::from_section(
"A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely. A paragraph of text which ought to wrap nicely.",
TextStyle {
font: font.clone(),
font_size: 16.0,
..default()
},
));
).with_style(Style {
padding: UiRect::all(Val::Px(10.)),
..Default::default()
}));
builder.spawn(NodeBundle::default());
});

Expand Down

0 comments on commit 3a7e8f3

Please sign in to comment.