Compare commits
7 Commits
e159346b89
...
87a4c6fd40
| Author | SHA1 | Date |
|---|---|---|
|
|
87a4c6fd40 | 2 years ago |
|
|
28d1bd8790 | 2 years ago |
|
|
41be0f42bf | 2 years ago |
|
|
bb9b37ef17 | 2 years ago |
|
|
f47d32b54d | 2 years ago |
|
|
a2a4b11087 | 2 years ago |
|
|
eef3acdade | 2 years ago |
@ -1,26 +0,0 @@
|
||||
# Exploration
|
||||
|
||||
## Inspectors
|
||||
|
||||
### Model Inspector
|
||||
|
||||
- [ ] Construct Scene from Nodes/Meshes (not auto-scene builder)
|
||||
- [ ] Show debug info about selected model
|
||||
- [ ] Wireframe view
|
||||
- [ ] Automatic tighter bounding box for selection
|
||||
|
||||
### Audio Inspector
|
||||
|
||||
- [ ] UI for selecting sound
|
||||
- [ ] Play/Pause/Volume
|
||||
- [x] Load sounds
|
||||
- [ ] Scrolling list of sounds
|
||||
|
||||
## WASM
|
||||
|
||||
- [ ] Build and run using model/text inspector
|
||||
- https://github.com/bevyengine/bevy/blob/main/examples/README.md#wasm
|
||||
|
||||
## Text Inspector
|
||||
|
||||
- [ ] Performance improvements?
|
||||
@ -1,101 +1,350 @@
|
||||
use bevy::{input::mouse::MouseWheel, prelude::*};
|
||||
use bevy::{
|
||||
input::{keyboard::KeyboardInput, ButtonState},
|
||||
prelude::*,
|
||||
window::PrimaryWindow,
|
||||
};
|
||||
use monologue_trees::{debug::*, ui::*};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "UI WTF".into(),
|
||||
resolution: (640., 480.).into(),
|
||||
.add_plugins((
|
||||
DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "UI WTF".into(),
|
||||
resolution: (640., 480.).into(),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_systems(Startup, (init,))
|
||||
.add_systems(Update, (scroll,))
|
||||
GameUiPlugin,
|
||||
))
|
||||
// .init_resource::<Icon>()
|
||||
.add_systems(Startup, init_ui2)
|
||||
.add_systems(Update, toggle)
|
||||
// .add_systems(Startup, init_ui)
|
||||
// .add_systems(Update, (cursors, container()))
|
||||
.run();
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct ScrollingList;
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle(
|
||||
mut events: Query<
|
||||
(&mut BackgroundColor, &Interaction, &Children),
|
||||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
mut styles: Query<&mut Style>,
|
||||
) {
|
||||
events
|
||||
.iter_mut()
|
||||
.for_each(|(mut bg_color, interaction, children)| match interaction {
|
||||
Interaction::Pressed => {
|
||||
bg_color.0 = Color::RED;
|
||||
children.iter().for_each(|&child| {
|
||||
if let Ok(mut style) = styles.get_mut(child) {
|
||||
style.display = match style.display {
|
||||
Display::Flex => Display::None,
|
||||
Display::None | _ => Display::Flex,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
Interaction::Hovered => {
|
||||
bg_color.0 = Color::RED;
|
||||
}
|
||||
Interaction::None => {
|
||||
bg_color.0 = Color::PINK;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// const CURSORS: [CursorIcon; 35] = [
|
||||
// CursorIcon::Default,
|
||||
// CursorIcon::Crosshair,
|
||||
// CursorIcon::Hand,
|
||||
// CursorIcon::Arrow,
|
||||
// CursorIcon::Move,
|
||||
// CursorIcon::Text,
|
||||
// CursorIcon::Wait,
|
||||
// CursorIcon::Help,
|
||||
// CursorIcon::Progress,
|
||||
// CursorIcon::NotAllowed,
|
||||
// CursorIcon::ContextMenu,
|
||||
// CursorIcon::Cell,
|
||||
// CursorIcon::VerticalText,
|
||||
// CursorIcon::Alias,
|
||||
// CursorIcon::Copy,
|
||||
// CursorIcon::NoDrop,
|
||||
// CursorIcon::Grab,
|
||||
// CursorIcon::Grabbing,
|
||||
// CursorIcon::AllScroll,
|
||||
// CursorIcon::ZoomIn,
|
||||
// CursorIcon::ZoomOut,
|
||||
// CursorIcon::EResize,
|
||||
// CursorIcon::NResize,
|
||||
// CursorIcon::NeResize,
|
||||
// CursorIcon::NwResize,
|
||||
// CursorIcon::SResize,
|
||||
// CursorIcon::SeResize,
|
||||
// CursorIcon::SwResize,
|
||||
// CursorIcon::WResize,
|
||||
// CursorIcon::EwResize,
|
||||
// CursorIcon::NsResize,
|
||||
// CursorIcon::NeswResize,
|
||||
// CursorIcon::NwseResize,
|
||||
// CursorIcon::ColResize,
|
||||
// CursorIcon::RowResize,
|
||||
// ];
|
||||
|
||||
fn init(mut commands: Commands) {
|
||||
info!("Spawning camera");
|
||||
commands.spawn(Camera2dBundle { ..default() });
|
||||
fn init_ui2(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Camera2dBundle { ..default() },
|
||||
UiCameraConfig { show_ui: true },
|
||||
));
|
||||
|
||||
info!("Initializing UI");
|
||||
commands
|
||||
.spawn(NodeBundle {
|
||||
background_color: BackgroundColor(Color::WHITE),
|
||||
style: Style {
|
||||
justify_content: JustifyContent::Center,
|
||||
width: Val::Percent(90.0),
|
||||
height: Val::Percent(90.0),
|
||||
overflow: Overflow::clip(),
|
||||
border: UiRect::all(Val::Px(2.0)),
|
||||
flex_direction: FlexDirection::Column,
|
||||
..default()
|
||||
},
|
||||
background_color: BackgroundColor(Color::PURPLE),
|
||||
border_color: BorderColor(Color::BLACK),
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn((
|
||||
NodeBundle {
|
||||
background_color: BackgroundColor(Color::OLIVE),
|
||||
style: Style {
|
||||
flex_wrap: FlexWrap::Wrap,
|
||||
flex_direction: FlexDirection::Row,
|
||||
justify_content: JustifyContent::SpaceAround,
|
||||
width: Val::Auto,
|
||||
height: Val::Auto,
|
||||
max_width: Val::Auto,
|
||||
max_height: Val::Auto,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
ScrollingList,
|
||||
))
|
||||
.with_children(|parent| {
|
||||
info!("Initializing Child Element");
|
||||
let colors = [
|
||||
Color::ORANGE,
|
||||
Color::BLUE,
|
||||
Color::GREEN,
|
||||
Color::SALMON,
|
||||
Color::SEA_GREEN,
|
||||
Color::MAROON,
|
||||
Color::ORANGE,
|
||||
Color::BLUE,
|
||||
Color::GREEN,
|
||||
Color::SALMON,
|
||||
Color::SEA_GREEN,
|
||||
Color::MAROON,
|
||||
];
|
||||
for i in 0..12 {
|
||||
parent.spawn(NodeBundle {
|
||||
background_color: BackgroundColor(colors[i]),
|
||||
style: Style {
|
||||
width: Val::Px(256.0),
|
||||
height: Val::Px(256.0),
|
||||
padding: UiRect::all(Val::Px(5.0)),
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
}
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
parent.spawn(spec(Color::PINK)).with_children(|parent| {
|
||||
parent.spawn(container()).with_children(|parent| {
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
parent.spawn(spec(Color::PINK));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn scroll(
|
||||
mut scroll_evr: EventReader<MouseWheel>,
|
||||
mut query: Query<&mut Style, With<ScrollingList>>,
|
||||
) {
|
||||
for ev in scroll_evr.iter() {
|
||||
for mut s in query.iter_mut() {
|
||||
s.top = match s.top {
|
||||
Val::Px(current) => Val::Px(current + (ev.y * 5.0)),
|
||||
_ => Val::Px(0.0),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
// #[derive(Debug, Component, Resource, Default)]
|
||||
// struct Icon(CursorIcon);
|
||||
//
|
||||
// fn init_ui(mut commands: Commands) {
|
||||
// commands.spawn((
|
||||
// Camera2dBundle { ..default() },
|
||||
// UiCameraConfig { show_ui: true },
|
||||
// ));
|
||||
//
|
||||
// commands
|
||||
// .spawn(NodeBundle {
|
||||
// style: Style {
|
||||
// height: Val::Percent(100.0),
|
||||
// width: Val::Percent(100.0),
|
||||
// justify_content: JustifyContent::Start,
|
||||
// align_items: AlignItems::Start,
|
||||
// ..default()
|
||||
// },
|
||||
// background_color: BackgroundColor(Color::GRAY),
|
||||
// ..default()
|
||||
// })
|
||||
// .with_children(|parent| {
|
||||
// parent
|
||||
// .spawn((
|
||||
// GameUiNav,
|
||||
// // Name::new("Game Nav"),
|
||||
// NodeBundle { ..default() },
|
||||
// ))
|
||||
// .with_children(|parent| {
|
||||
// parent
|
||||
// .spawn((
|
||||
// GameUiTab,
|
||||
// Name::new("Grow/Shrink Tab"),
|
||||
// NodeBundle { ..default() },
|
||||
// ))
|
||||
// .with_children(|parent| {
|
||||
// parent.spawn((
|
||||
// container,
|
||||
// GameUiSet,
|
||||
// // Name::new("Grow/Shrink Set"),
|
||||
// NodeBundle { ..default() },
|
||||
// ));
|
||||
// });
|
||||
//
|
||||
// parent
|
||||
// .spawn((
|
||||
// GameUiTab,
|
||||
// Name::new("Cursor Icons Tab"),
|
||||
// NodeBundle { ..default() },
|
||||
// ))
|
||||
// .with_children(|parent| {
|
||||
// parent
|
||||
// .spawn((
|
||||
// GameUiSet,
|
||||
// // Name::new("Cursor Icons Set"),
|
||||
// NodeBundle { ..default() },
|
||||
// ))
|
||||
// .with_children(|parent| {
|
||||
// CURSORS.iter().for_each(|&icon| {
|
||||
// parent.spawn((
|
||||
// GameUiButton,
|
||||
// Name::new(format!("{:?}", icon)),
|
||||
// NodeBundle { ..default() },
|
||||
// Icon(icon),
|
||||
// ));
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// fn cursors(
|
||||
// events: Query<(&Interaction, &Icon), (Changed<Interaction>, With<Button>)>,
|
||||
// mut primary_window: Query<&mut Window, With<PrimaryWindow>>,
|
||||
// mut curr: ResMut<Icon>,
|
||||
// ) {
|
||||
// events.iter().for_each(|(&interaction, &ref icon)| {
|
||||
// let mut window = primary_window.single_mut();
|
||||
//
|
||||
// match interaction {
|
||||
// Interaction::Hovered => {
|
||||
// (*window).cursor.icon = icon.0.clone();
|
||||
// }
|
||||
// Interaction::Pressed => {
|
||||
// curr.0 = icon.0.clone();
|
||||
// }
|
||||
// Interaction::None => {
|
||||
// (*window).cursor.icon = curr.0.clone();
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// #[derive(Debug, Component)]
|
||||
// struct container;
|
||||
//
|
||||
// fn container(
|
||||
// mut events: EventReader<KeyboardInput>,
|
||||
// mut commands: Commands,
|
||||
// root: Query<Entity, With<container>>,
|
||||
// children: Query<&Children, With<container>>,
|
||||
// ) {
|
||||
// events.iter().for_each(
|
||||
// |KeyboardInput {
|
||||
// key_code, state, ..
|
||||
// }| {
|
||||
// match (key_code, state) {
|
||||
// (Some(KeyCode::Up), ButtonState::Pressed) => {
|
||||
// commands.entity(root.single()).with_children(|parent| {
|
||||
// parent.spawn((
|
||||
// GameUiButton,
|
||||
// Name::new("asdfwtf"),
|
||||
// NodeBundle { ..default() },
|
||||
// ));
|
||||
// });
|
||||
// }
|
||||
// (Some(KeyCode::Down), ButtonState::Pressed) => {
|
||||
// children.single().iter().last().iter().for_each(|&&child| {
|
||||
// commands.entity(child).despawn_recursive();
|
||||
// });
|
||||
// }
|
||||
// _ => (),
|
||||
// }
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
|
||||
@ -1,121 +1,101 @@
|
||||
/// TODO:
|
||||
/// * Titles on top left of window/tab
|
||||
/// *
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
|
||||
pub struct GameUiPlugin;
|
||||
|
||||
impl Plugin for GameUiPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
manage_ui_list,
|
||||
manage_ui_set,
|
||||
manage_ui_button,
|
||||
manage_cursor,
|
||||
),
|
||||
);
|
||||
app.add_systems(PreUpdate, (spawn_nav, spawn_tab, spawn_set, spawn_button))
|
||||
.add_systems(Update, (manage_names, manage_tab));
|
||||
}
|
||||
}
|
||||
|
||||
/// GameUiList for holding ordered collections of objects
|
||||
#[derive(Debug, Component)]
|
||||
pub struct GameUiList;
|
||||
/// Navigation UI Container
|
||||
/// Buttons in a nav correspond to Tabs in a navbar/navmenu
|
||||
#[derive(Component, PartialEq)]
|
||||
pub struct GameUiNav;
|
||||
|
||||
/// Manage UI Lists: lists of UI entities.
|
||||
fn manage_ui_list(events: Query<(Entity, &Name), Added<GameUiList>>, mut commands: Commands) {
|
||||
events.iter().for_each(|(entity, name)| {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(NodeBundle {
|
||||
style: Style {
|
||||
// width: Val::Px(100.0),
|
||||
margin: UiRect::all(Val::Px(2.0)),
|
||||
padding: UiRect::all(Val::Px(2.0)),
|
||||
border: UiRect::all(Val::Px(2.0)),
|
||||
flex_direction: FlexDirection::Column,
|
||||
align_items: AlignItems::Stretch,
|
||||
justify_items: JustifyItems::Center,
|
||||
align_content: AlignContent::FlexStart,
|
||||
..default()
|
||||
},
|
||||
background_color: BackgroundColor(Color::RED),
|
||||
border_color: BorderColor(Color::BLACK),
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn(TextBundle::from_section(name, TextStyle { ..default() }));
|
||||
});
|
||||
/// Sets contain a variety of elements like action buttons
|
||||
/// Usually the "leaf" of a navigation tree
|
||||
#[derive(Component, PartialEq)]
|
||||
pub struct GameUiSet;
|
||||
|
||||
/// Buttons are used for interaction in the UI
|
||||
#[derive(Component, PartialEq)]
|
||||
pub struct GameUiButton;
|
||||
|
||||
#[derive(Component, PartialEq)]
|
||||
pub struct GameUiTab;
|
||||
|
||||
fn spawn_nav(events: Query<(Entity, &GameUiNav), Added<GameUiNav>>, mut commands: Commands) {
|
||||
events.iter().for_each(|(entity, _)| {
|
||||
info!("Spawning Nav UI");
|
||||
});
|
||||
}
|
||||
|
||||
/// GameUiSet Component for holding collections of objects
|
||||
#[derive(Debug, Component)]
|
||||
pub struct GameUiSet;
|
||||
fn spawn_tab(events: Query<Entity, Added<GameUiTab>>, mut commands: Commands) {
|
||||
events.iter().for_each(|entity| {});
|
||||
}
|
||||
|
||||
/// Manage UI Sets: collections of UI entities.
|
||||
fn manage_ui_set(events: Query<(Entity, &Name), Added<GameUiSet>>, mut commands: Commands) {
|
||||
events.iter().for_each(|(entity, name)| {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(NodeBundle {
|
||||
style: Style {
|
||||
// width: Val::Px(100.0),
|
||||
margin: UiRect::all(Val::Px(2.0)),
|
||||
padding: UiRect::all(Val::Px(2.0)),
|
||||
border: UiRect::all(Val::Px(2.0)),
|
||||
align_items: AlignItems::FlexStart,
|
||||
align_content: AlignContent::FlexStart,
|
||||
flex_direction: FlexDirection::Row,
|
||||
flex_wrap: FlexWrap::Wrap,
|
||||
..default()
|
||||
},
|
||||
background_color: BackgroundColor(Color::BLUE),
|
||||
border_color: BorderColor(Color::BLACK),
|
||||
fn spawn_set(events: Query<Entity, Added<GameUiSet>>, mut commands: Commands) {
|
||||
events.iter().for_each(|entity| {});
|
||||
}
|
||||
|
||||
fn spawn_button(
|
||||
events: Query<(Entity, &GameUiButton), Added<GameUiButton>>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
events.iter().for_each(|(entity, _)| {
|
||||
info!("Spawning UI Button");
|
||||
commands.entity(entity).insert(ButtonBundle {
|
||||
style: Style {
|
||||
padding: UiRect::all(Val::Px(3.0)),
|
||||
margin: UiRect::all(Val::Px(3.0)),
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn(TextBundle::from_section(name, TextStyle { ..default() }));
|
||||
});
|
||||
},
|
||||
background_color: BackgroundColor(Color::BLUE),
|
||||
..default()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// GameUiButton for interactive elements
|
||||
#[derive(Debug, Component)]
|
||||
pub struct GameUiButton;
|
||||
|
||||
/// Manage UI Buttons. interactive buttons.
|
||||
fn manage_ui_button(events: Query<(Entity, &Name), Added<GameUiButton>>, mut commands: Commands) {
|
||||
fn manage_names(
|
||||
events: Query<
|
||||
(Entity, &Name),
|
||||
(
|
||||
Or<(With<GameUiNav>, With<GameUiButton>)>,
|
||||
Or<(Added<Name>, Changed<Name>)>,
|
||||
),
|
||||
>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
events.iter().for_each(|(entity, name)| {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(ButtonBundle {
|
||||
style: Style {
|
||||
margin: UiRect::all(Val::Px(2.0)),
|
||||
padding: UiRect::all(Val::Px(2.0)),
|
||||
border: UiRect::all(Val::Px(2.0)),
|
||||
justify_content: JustifyContent::Center,
|
||||
commands.entity(entity).with_children(|parent| {
|
||||
parent
|
||||
.spawn(NodeBundle {
|
||||
style: Style {
|
||||
align_self: AlignSelf::FlexStart,
|
||||
padding: UiRect::all(Val::Px(3.0)),
|
||||
margin: UiRect::all(Val::Px(3.0)),
|
||||
..default()
|
||||
},
|
||||
background_color: BackgroundColor(Color::CRIMSON),
|
||||
..default()
|
||||
},
|
||||
background_color: BackgroundColor(Color::GREEN),
|
||||
border_color: BorderColor(Color::BLACK),
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn(TextBundle::from_section(name, TextStyle::default()));
|
||||
});
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent.spawn(TextBundle::from_section(
|
||||
name.as_str(),
|
||||
TextStyle { ..default() },
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Manage the cursor icon for better immersion
|
||||
fn manage_cursor(
|
||||
mut primary_window: Query<&mut Window, With<PrimaryWindow>>,
|
||||
events: Query<&Interaction, With<Interaction>>,
|
||||
) {
|
||||
events.iter().for_each(|event| {
|
||||
let mut window = primary_window.single_mut();
|
||||
window.cursor.icon = match event {
|
||||
Interaction::Pressed => CursorIcon::Grabbing,
|
||||
Interaction::Hovered => CursorIcon::Hand,
|
||||
Interaction::None => CursorIcon::Default,
|
||||
}
|
||||
fn manage_tab(events: Query<&Interaction, Changed<Interaction>>) {
|
||||
events.iter().for_each(|interaction| {
|
||||
info!("When tab is clicked, show/hide content");
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
if *duration > Duration::ZERO {
|
||||
let mut text = texts.single_mut();
|
||||
let total_sections = text.sections.len();
|
||||
|
||||
*duration = duration.saturating_sub(time.delta());
|
||||
|
||||
for (idx, section) in text.sections.iter_mut().enumerate() {
|
||||
let ratio = ((idx + 1) as f32) / (total_sections as f32);
|
||||
let cursor = 1.0 - ((*duration).as_secs_f32() / 30.0);
|
||||
let alpha = if cursor > ratio { 1.0 } else { 0.0 };
|
||||
section.style.color.set_a(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue