diff --git a/src/main.rs b/src/main.rs index 0323db3..097ca83 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,20 @@ fn main() { })) .add_plugins(EguiPlugin::default()) .add_plugins(WorldInspectorPlugin::new()) - .add_systems(Startup, assets::load_assets) + .add_systems( + Startup, + (setup, assets::load_assets, widgets::spawn_cutter_machine_ui), + ) .run(); } + +fn setup(mut commands: Commands) { + commands.spawn(Camera2d); +} + +/// Generic utility for despawning entities that have a given component. +fn despawn(mut commands: Commands, to_despawn: Query>) { + for entity in to_despawn { + commands.entity(entity).despawn(); + } +} diff --git a/src/widgets.rs b/src/widgets.rs index f127cc1..6b82c95 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1 +1,57 @@ //! Catch-all location for UI bits + +use bevy::{ + color::palettes::{css::*, tailwind::*}, + prelude::*, + ui::Val::*, +}; + +pub fn spawn_cutter_machine_ui(mut commands: Commands) { + commands.spawn(( + machine_ui_base(), + children![ + ( + Node::default(), // TODO: A real node with stuff in it (buttons, maybe?) + BackgroundColor(RED.into()), + Pickable::default() + ), + ( + Node::default(), + BackgroundColor(GREEN.into()), + Pickable::default() + ), + ( + Node::default(), + BackgroundColor(BLUE.into()), + Pickable::default(), + ) + ], + )); +} + +/// The base panel for the machines that manipulate the room cards. +fn machine_ui_base() -> impl Bundle { + ( + Node { + // Position & size + position_type: PositionType::Relative, + width: Percent(60.0), + height: Percent(60.0), + top: Percent(20.0), + left: Percent(20.0), + + // 5x5 grid, padding & gutters, etc + aspect_ratio: Some(1.0), + display: Display::Grid, + padding: UiRect::all(Val::Px(10.0)), + grid_template_columns: RepeatedGridTrack::flex(5, 1.0), + grid_template_rows: RepeatedGridTrack::flex(5, 1.0), + row_gap: Val::Px(5.0), + column_gap: Val::Px(5.0), + + ..default() + }, + BackgroundColor(SLATE_100.into()), + BorderRadius::all(Percent(2.0)), + ) +}