Colored squares on a grid layout
I'm still kinda figuring out how to do more complex UIs, so I'll be making several commits that aren't very interesting to review... such as this one.
This commit is contained in:
16
src/main.rs
16
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<T: Component>(mut commands: Commands, to_despawn: Query<Entity, With<T>>) {
|
||||
for entity in to_despawn {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user