use super::styles::{UiColors, UiSizes};
use bevy::prelude::*;
use bevy::ui::{
AlignItems, BackgroundColor, FlexDirection, Node, Overflow, ScrollPosition, UiRect, Val,
};
pub struct LayoutPlugin;
impl Plugin for LayoutPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, (setup_ui_camera, setup_layout).chain());
}
}
#[derive(Component)]
pub struct UiOnlyCamera;
fn setup_ui_camera(mut commands: Commands) {
println!("[UI] Setting up UI camera...");
commands.spawn((
Camera2d,
Camera {
order: 1,
clear_color: bevy::prelude::ClearColorConfig::None,
..default()
},
UiOnlyCamera,
));
}
#[derive(Component)]
pub struct UiRoot;
#[derive(Component)]
pub struct ToolbarContainer;
#[derive(Component)]
pub struct LeftPanel;
#[derive(Component)]
pub struct RightPanel;
#[derive(Component)]
pub struct ViewportArea;
#[derive(Component)]
pub struct StatusBar;
pub fn setup_layout(mut commands: Commands) {
println!("[UI] Setting up layout...");
commands
.spawn((
UiRoot,
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
..default()
},
BackgroundColor(Color::NONE),
))
.with_children(|parent| {
parent.spawn((
ToolbarContainer,
Node {
width: Val::Percent(100.0),
height: Val::Px(UiSizes::TOOLBAR_HEIGHT),
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
padding: UiRect::horizontal(Val::Px(UiSizes::PADDING)),
..default()
},
BackgroundColor(UiColors::TOOLBAR_BG),
));
parent
.spawn((
Node {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Row,
..default()
},
BackgroundColor(Color::NONE),
))
.with_children(|content| {
content.spawn((
LeftPanel,
super::ScrollablePanel,
Node {
width: Val::Px(UiSizes::PANEL_WIDTH),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
padding: UiRect::all(Val::Px(UiSizes::PADDING)),
overflow: Overflow::scroll_y(),
..default()
},
BackgroundColor(UiColors::PANEL_BG),
Interaction::default(),
ScrollPosition::default(),
));
content.spawn((
ViewportArea,
Node {
flex_grow: 1.0,
height: Val::Percent(100.0),
..default()
},
BackgroundColor(Color::NONE),
));
content.spawn((
RightPanel,
super::ScrollablePanel,
Node {
width: Val::Px(UiSizes::PANEL_WIDTH),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
padding: UiRect::all(Val::Px(UiSizes::PADDING)),
overflow: Overflow::scroll_y(),
..default()
},
BackgroundColor(UiColors::PANEL_BG),
Interaction::default(),
ScrollPosition::default(),
));
});
parent.spawn((
StatusBar,
Node {
width: Val::Percent(100.0),
height: Val::Px(24.0),
flex_direction: FlexDirection::Row,
align_items: AlignItems::Center,
padding: UiRect::horizontal(Val::Px(UiSizes::PADDING)),
..default()
},
BackgroundColor(UiColors::TOOLBAR_BG),
));
});
}