//! Example demonstrating bordered UI nodes use bevy::{color::palettes::css::*, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); let root = commands .spawn(NodeBundle { style: Style { margin: UiRect::all(Val::Px(25.0)), align_self: AlignSelf::Stretch, justify_self: JustifySelf::Stretch, flex_wrap: FlexWrap::Wrap, justify_content: JustifyContent::FlexStart, align_items: AlignItems::FlexStart, align_content: AlignContent::FlexStart, ..Default::default() }, background_color: Color::srgb(0.25, 0.25, 0.25).into(), ..Default::default() }) .id(); // all the different combinations of border edges let borders = [ UiRect::default(), UiRect::all(Val::Px(10.)), UiRect::left(Val::Px(10.)), UiRect::right(Val::Px(10.)), UiRect::top(Val::Px(10.)), UiRect::bottom(Val::Px(10.)), UiRect::horizontal(Val::Px(10.)), UiRect::vertical(Val::Px(10.)), UiRect { left: Val::Px(10.), top: Val::Px(10.), ..Default::default() }, UiRect { left: Val::Px(10.), bottom: Val::Px(10.), ..Default::default() }, UiRect { right: Val::Px(10.), top: Val::Px(10.), ..Default::default() }, UiRect { right: Val::Px(10.), bottom: Val::Px(10.), ..Default::default() }, UiRect { right: Val::Px(10.), top: Val::Px(10.), bottom: Val::Px(10.), ..Default::default() }, UiRect { left: Val::Px(10.), top: Val::Px(10.), bottom: Val::Px(10.), ..Default::default() }, UiRect { left: Val::Px(10.), right: Val::Px(10.), top: Val::Px(10.), ..Default::default() }, UiRect { left: Val::Px(10.), right: Val::Px(10.), bottom: Val::Px(10.), ..Default::default() }, ]; for i in 0..64 { let inner_spot = commands .spawn(NodeBundle { style: Style { width: Val::Px(10.), height: Val::Px(10.), ..Default::default() }, background_color: YELLOW.into(), ..Default::default() }) .id(); let bordered_node = commands .spawn(( NodeBundle { style: Style { width: Val::Px(50.), height: Val::Px(50.), border: borders[i % borders.len()], margin: UiRect::all(Val::Px(20.)), align_items: AlignItems::Center, justify_content: JustifyContent::Center, ..Default::default() }, background_color: MAROON.into(), border_color: RED.into(), ..Default::default() }, Outline { width: Val::Px(6.), offset: Val::Px(6.), color: Color::WHITE, }, )) .add_child(inner_spot) .id(); commands.entity(root).add_child(bordered_node); } }