//! 教程中复用的外观代码。业务逻辑都留在各章对应的 bin 中。
use bevy::prelude::*;
pub fn app(title: &str) -> App {
let mut app = App::new();
app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: title.to_owned(),
..default()
}),
..default()
}));
app
}
pub fn camera(mut commands: Commands) {
commands.spawn(Camera2d);
}
pub fn panel() -> impl Bundle {
(
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::FlexStart,
padding: UiRect::all(Val::Px(24.0)),
row_gap: Val::Px(12.0),
..default()
},
BackgroundColor(Color::srgb(0.08, 0.09, 0.12)),
)
}
pub fn button() -> impl Bundle {
(
bevy::ui_widgets::Button,
bevy::picking::hover::Hovered::default(),
Node {
padding: UiRect::all(Val::Px(12.0)),
..default()
},
BackgroundColor(Color::srgb(0.18, 0.28, 0.46)),
)
}