Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom window size from flex_layout example #11876

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
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
24 changes: 14 additions & 10 deletions examples/ui/flex_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ use bevy::prelude::*;

const ALIGN_ITEMS_COLOR: Color = Color::rgb(1., 0.066, 0.349);
const JUSTIFY_CONTENT_COLOR: Color = Color::rgb(0.102, 0.522, 1.);
const MARGIN: Val = Val::Px(5.);
const MARGIN: Val = Val::Px(12.);

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: [870., 1066.].into(),
title: "Bevy Flex Layout Example".to_string(),
..Default::default()
}),
Expand All @@ -27,8 +26,11 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
style: Style {
// fill the entire window
width: Val::Percent(100.),
height: Val::Percent(100.),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
padding: UiRect::all(MARGIN),
row_gap: MARGIN,
..Default::default()
},
background_color: BackgroundColor(Color::BLACK),
Expand All @@ -40,7 +42,6 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
margin: UiRect::top(MARGIN),
..Default::default()
},
..Default::default()
Expand All @@ -65,9 +66,10 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
builder
.spawn(NodeBundle {
style: Style {
width: Val::Px(850.),
height: Val::Px(1020.),
width: Val::Percent(100.),
height: Val::Percent(100.),
flex_direction: FlexDirection::Column,
row_gap: MARGIN,
..Default::default()
},
..Default::default()
Expand All @@ -89,17 +91,20 @@ fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
AlignItems::FlexEnd,
AlignItems::Stretch,
];
for justify_content in justifications {
for align_items in alignments {
builder
.spawn(NodeBundle {
style: Style {
width: Val::Percent(100.),
height: Val::Percent(100.),
flex_direction: FlexDirection::Row,
column_gap: MARGIN,
..Default::default()
},
..Default::default()
})
.with_children(|builder| {
for align_items in alignments {
for justify_content in justifications {
spawn_child_node(
builder,
font.clone(),
Expand All @@ -125,9 +130,8 @@ fn spawn_child_node(
flex_direction: FlexDirection::Column,
align_items,
justify_content,
width: Val::Px(160.),
height: Val::Px(160.),
margin: UiRect::all(MARGIN),
width: Val::Percent(100.),
height: Val::Percent(100.),
..Default::default()
},
background_color: BackgroundColor(Color::DARK_GRAY),
Expand Down