// TODO: Z-index of children should be higher than parents use bevy::prelude::*; use monologue_trees::ui::*; fn main() { App::new() .add_plugins(( DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "UI WTF".into(), resolution: (640., 480.).into(), ..default() }), ..default() }), GameUiPlugin, )) // .init_resource::() .add_systems(Startup, init_ui2) .add_systems(Update, toggle) .add_systems(PostUpdate, selection) // .add_systems(Startup, init_ui) // .add_systems(Update, (cursors, container)) .run(); } #[derive(Debug, Bundle)] struct UiKitContainer { node_bundle: NodeBundle, select: Select, } #[derive(Copy, Clone)] enum UiKitPosition { Top, Left, Right, } impl UiKitContainer { fn new(position: UiKitPosition) -> Self { let style = match position { UiKitPosition::Top => Style { border: UiRect::all(Val::Px(1.0)), top: Val::Percent(102.0), left: Val::Px(-2.0), flex_direction: FlexDirection::Column, align_items: AlignItems::FlexStart, display: Display::None, ..default() }, UiKitPosition::Left => Style { border: UiRect::all(Val::Px(1.0)), left: Val::Percent(100.0), top: Val::Px(-2.0), flex_direction: FlexDirection::Column, justify_items: JustifyItems::Start, display: Display::None, ..default() }, UiKitPosition::Right => Style { border: UiRect::all(Val::Px(1.0)), right: Val::Percent(104.0), top: Val::Px(-2.0), flex_direction: FlexDirection::Column, justify_items: JustifyItems::Start, display: Display::None, ..default() }, }; UiKitContainer { node_bundle: NodeBundle { style, background_color: BackgroundColor(Color::PURPLE), border_color: BorderColor(Color::BLACK), ..default() }, select: Select::None, } } } #[derive(Debug, Bundle)] struct UiKitButton { button_bundle: ButtonBundle, select: Select, } impl UiKitButton { fn new(color: Color) -> Self { UiKitButton { button_bundle: ButtonBundle { style: Style { border: UiRect::all(Val::Px(1.0)), width: Val::Px(100.0), height: Val::Px(50.0), flex_direction: FlexDirection::Column, ..default() }, background_color: BackgroundColor(color), border_color: BorderColor(Color::BLACK), ..default() }, select: Select::None, } } } #[derive(Debug, Component, Copy, Clone)] enum Select { Active, None, } /// When an item is selected/de-selected change it's display accordingly fn selection( mut events: Query<(&mut BackgroundColor, &Select, &Children), (Changed