diff --git a/bin/ui-wtf.rs b/bin/ui-wtf.rs index a39bd28..066512e 100644 --- a/bin/ui-wtf.rs +++ b/bin/ui-wtf.rs @@ -1,9 +1,7 @@ -use bevy::{ - input::{keyboard::KeyboardInput, ButtonState}, - prelude::*, - window::PrimaryWindow, -}; -use monologue_trees::{debug::*, ui::*}; +// TODO: Z-index of children should be higher than parents + +use bevy::prelude::*; +use monologue_trees::ui::*; fn main() { App::new() @@ -21,72 +19,174 @@ fn main() { // .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())) + // .add_systems(Update, (cursors, container)) .run(); } -fn container() -> NodeBundle { - NodeBundle { - style: Style { - border: UiRect::all(Val::Px(2.0)), - right: Val::Percent(-100.0), - top: Val::Px(-4.0), - flex_direction: FlexDirection::Column, - display: Display::None, - ..default() - }, - background_color: BackgroundColor(Color::PURPLE), - border_color: BorderColor(Color::BLACK), - ..default() +#[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, + } } } -fn spec(color: Color) -> ButtonBundle { - ButtonBundle { - style: Style { - border: UiRect::all(Val::Px(2.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() +#[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, + } } } -fn toggle( - mut events: Query< - (&mut BackgroundColor, &Interaction, &Children), - (Changed, With