about to raze editor code

main
Elijah Voigt 2 years ago
parent 6ae7b094ad
commit a100fa8f4a

@ -22,7 +22,7 @@ use bevy::{
prelude::*, prelude::*,
utils::HashSet, utils::HashSet,
}; };
use monologue_trees::{debug::*, ui::*}; use monologue_trees::debug::*;
fn main() { fn main() {
App::new() App::new()
@ -36,7 +36,6 @@ fn main() {
..default() ..default()
}), }),
DebugInfoPlugin, DebugInfoPlugin,
GameUiPlugin,
)) ))
.init_resource::<AssetRegistry>() .init_resource::<AssetRegistry>()
.add_systems(Startup, (initialize_ui,)) .add_systems(Startup, (initialize_ui,))
@ -63,7 +62,6 @@ fn main() {
export_level, export_level,
import_level, import_level,
// Misc/Debug Systems // Misc/Debug Systems
load_bogus,
), ),
) )
.run(); .run();
@ -101,8 +99,8 @@ fn initialize_ui(mut commands: Commands) {
.with_children(|parent| { .with_children(|parent| {
parent parent
.spawn(( .spawn((
GameUiList,
Name::new("GLTFs"), Name::new("GLTFs"),
GltfsUi,
NodeBundle { NodeBundle {
style: Style { style: Style {
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
@ -110,31 +108,19 @@ fn initialize_ui(mut commands: Commands) {
}, },
..default() ..default()
}, },
GltfsUi,
)) ))
.with_children(|parent| { .with_children(|parent| {
parent.spawn((Name::new("Scenes"), ScenesUi, NodeBundle { ..default() }));
parent.spawn((Name::new("Cameras"), CamerasUi, NodeBundle { ..default() }));
parent.spawn(( parent.spawn((
GameUiList,
Name::new("Scenes"),
NodeBundle { ..default() },
ScenesUi,
));
parent.spawn((
GameUiList,
Name::new("Cameras"),
NodeBundle { ..default() },
CamerasUi,
));
parent.spawn((
GameUiList,
Name::new("Animations"), Name::new("Animations"),
NodeBundle { ..default() },
AnimationsUi, AnimationsUi,
NodeBundle { ..default() },
)); ));
}); });
parent.spawn(( parent.spawn((
GameUiSet,
Name::new("Audio Clips"), Name::new("Audio Clips"),
AudioClipsUi,
NodeBundle { NodeBundle {
style: Style { style: Style {
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
@ -142,30 +128,10 @@ fn initialize_ui(mut commands: Commands) {
}, },
..default() ..default()
}, },
AudioClipsUi,
)); ));
}); });
} }
fn load_bogus(
mut events: EventReader<KeyboardInput>,
root: Query<Entity, (With<AnimationsUi>, Without<UiRef<Handle<AnimationClip>>>)>,
mut commands: Commands,
) {
events
.iter()
.filter(
|&KeyboardInput {
key_code, state, ..
}| *key_code == Some(KeyCode::Space) && *state == ButtonState::Pressed,
)
.for_each(|_| {
commands
.spawn((GameUiButton, Name::new("bogus"), NodeBundle { ..default() }))
.set_parent(root.single());
})
}
#[derive(Resource, Default, Debug)] #[derive(Resource, Default, Debug)]
struct AssetRegistry(HashSet<HandleUntyped>); struct AssetRegistry(HashSet<HandleUntyped>);
@ -233,10 +199,9 @@ fn manage_gltf_ui(
}); });
commands commands
.spawn(( .spawn((
GameUiButton,
Name::new(name), Name::new(name),
NodeBundle { ..default() },
GltfsUi, GltfsUi,
ButtonBundle { ..default() },
UiRef::Handle(handle.clone()), UiRef::Handle(handle.clone()),
)) ))
.set_parent(root.single()); .set_parent(root.single());
@ -283,10 +248,9 @@ fn manage_scene_ui(
.for_each(|(handle, name)| { .for_each(|(handle, name)| {
commands commands
.spawn(( .spawn((
GameUiButton,
Name::new(name), Name::new(name),
NodeBundle { ..default() },
ScenesUi, ScenesUi,
ButtonBundle { ..default() },
UiRef::Handle(handle.clone()), UiRef::Handle(handle.clone()),
)) ))
.set_parent(root.single()); .set_parent(root.single());
@ -336,10 +300,9 @@ fn manage_animation_ui(
.for_each(|(handle, name)| { .for_each(|(handle, name)| {
commands commands
.spawn(( .spawn((
GameUiButton,
Name::new(name), Name::new(name),
NodeBundle { ..default() },
AnimationsUi, AnimationsUi,
ButtonBundle { ..default() },
UiRef::Handle(handle.clone()), UiRef::Handle(handle.clone()),
)) ))
.set_parent(root.single()); .set_parent(root.single());
@ -390,9 +353,8 @@ fn manage_audio_ui(
.for_each(|(handle, name)| { .for_each(|(handle, name)| {
commands commands
.spawn(( .spawn((
GameUiButton,
Name::new(name), Name::new(name),
NodeBundle { ..default() }, ButtonBundle { ..default() },
AudioClipsUi, AudioClipsUi,
AudioBundle { AudioBundle {
source: handle.clone(), source: handle.clone(),
@ -409,21 +371,13 @@ fn manage_audio_ui(
/// Play/Loop Audio /// Play/Loop Audio
fn play_audio( fn play_audio(
mut events: Query< mut events: Query<(&Interaction, &AudioSink), (Changed<Interaction>, With<AudioClipsUi>)>,
(&Interaction, &AudioSink, &mut UiElementState),
(Changed<Interaction>, With<AudioClipsUi>),
>,
) { ) {
events events
.iter_mut() .iter_mut()
.for_each(|(interaction, sink, mut state)| match interaction { .for_each(|(interaction, sink)| match interaction {
Interaction::Pressed => { Interaction::Pressed => {
sink.toggle(); sink.toggle();
*state = match *state {
UiElementState::Enabled => UiElementState::Active,
_ => UiElementState::Enabled,
}
} }
_ => (), _ => (),
}); });

@ -68,140 +68,27 @@ fn spawn_tree(parent: &mut ChildBuilder, pos: UiKitPosition, depth: u8, length:
}; };
(0..length).for_each(|_| { (0..length).for_each(|_| {
parent parent
.spawn(UiKitButton::new(Color::PINK)) .spawn((
UiKitButton { color: Color::PINK },
UiKitSelect::default(),
UiKitLabel {
name: "Button".into(),
},
))
.with_children(|parent| { .with_children(|parent| {
if depth > 1 { if depth > 1 {
parent parent
.spawn(UiKitContainer::new(pos)) .spawn((
UiKitContainer { position: pos },
UiKitSelect::default(),
UiKitLabel { name: "Tab".into() },
))
.with_children(|parent| { .with_children(|parent| {
spawn_tree(parent, pos2, depth - 1, length); spawn_tree(parent, pos2, depth - 1, length);
}); });
} }
}); });
}); });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos))
// .with_children(|parent| {
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos))
// .with_children(|parent| {
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos))
// .with_children(|parent| {
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// parent
// .spawn(UiKitButton::new(Color::PINK))
// .with_children(|parent| {
// parent
// .spawn(UiKitContainer::new(pos2))
// .with_children(|parent| {
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// parent.spawn(UiKitButton::new(Color::PINK));
// });
// });
// });
// });
} }
fn init_ui2(mut commands: Commands) { fn init_ui2(mut commands: Commands) {
@ -226,8 +113,8 @@ fn init_ui2(mut commands: Commands) {
.spawn(ButtonBundle { .spawn(ButtonBundle {
style: Style { style: Style {
border: UiRect::all(Val::Px(1.0)), border: UiRect::all(Val::Px(1.0)),
width: Val::Px(200.0), // width: Val::Px(200.0),
height: Val::Px(150.0), // height: Val::Px(150.0),
align_self: AlignSelf::Center, align_self: AlignSelf::Center,
..default() ..default()
}, },
@ -254,7 +141,7 @@ fn init_ui2(mut commands: Commands) {
..default() ..default()
}) })
.with_children(|parent| { .with_children(|parent| {
spawn_tree(parent, UiKitPosition::Left, 3, 7); spawn_tree(parent, UiKitPosition::Left, 3, 4);
}); });
parent parent
@ -289,7 +176,7 @@ fn init_ui2(mut commands: Commands) {
..default() ..default()
}) })
.with_children(|parent| { .with_children(|parent| {
spawn_tree(parent, UiKitPosition::Top, 3, 7); spawn_tree(parent, UiKitPosition::Top, 3, 3);
}); });
}); });
} }

@ -22,156 +22,349 @@ pub struct GameUiPlugin;
impl Plugin for GameUiPlugin { impl Plugin for GameUiPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Update, (select_tab, select_textbox, text_editor, scroll)) app.add_systems(Update, (select_tab, select_textbox, text_editor, scroll))
.add_systems(PostUpdate, selection); .add_systems(
PreUpdate,
(
spawn_container,
spawn_button,
/* manage_labels */ selection,
),
);
} }
} }
#[derive(Debug, Bundle)] pub use self::container::*;
pub struct UiKitContainer { mod container {
node_bundle: NodeBundle, use super::*;
select: UiKitSelect,
}
#[derive(Copy, Clone)] #[derive(Debug, Component)]
pub enum UiKitPosition { pub struct UiKitContainer {
Top, pub position: UiKitPosition,
Left, }
Right,
}
impl UiKitContainer { #[derive(Debug, Copy, Clone)]
pub fn new(position: UiKitPosition) -> Self { pub enum UiKitPosition {
let style = match position { Top,
UiKitPosition::Top => Style { Left,
border: UiRect::all(Val::Px(1.0)), Right,
top: Val::Percent(102.0), }
left: Val::Px(-2.0),
flex_direction: FlexDirection::Column, pub fn spawn_container(
align_items: AlignItems::FlexStart, events: Query<(Entity, &UiKitContainer, Option<&UiKitLabel>), Added<UiKitContainer>>,
display: Display::None, mut commands: Commands,
..default() ) {
}, events.iter().for_each(|(entity, container, label)| {
UiKitPosition::Left => Style { let base_style = 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)), border: UiRect::all(Val::Px(1.0)),
right: Val::Percent(104.0),
top: Val::Px(-2.0),
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
justify_items: JustifyItems::Start,
display: Display::None, display: Display::None,
..default() ..default()
}, };
}; let style = match container.position {
UiKitContainer { UiKitPosition::Top => Style {
node_bundle: NodeBundle { top: Val::Percent(100.0),
style, align_items: AlignItems::Start,
background_color: BackgroundColor(Color::PURPLE), ..base_style
border_color: BorderColor(Color::BLACK), },
..default() UiKitPosition::Left => Style {
}, left: Val::Percent(100.0),
select: UiKitSelect::None, justify_items: JustifyItems::Start,
} ..base_style
},
UiKitPosition::Right => Style {
right: Val::Percent(104.0),
justify_items: JustifyItems::Start,
..base_style
},
};
commands
.entity(entity)
.insert(NodeBundle {
style,
background_color: BackgroundColor(Color::PURPLE),
border_color: BorderColor(Color::BLACK),
..default()
})
.with_children(|parent| {
if let Some(label) = label {
parent.spawn(
TextBundle::from_section(
label.name.clone(),
TextStyle {
color: Color::BLACK,
..default()
},
)
.with_style(Style {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
..default()
}),
);
}
});
})
} }
} }
#[derive(Debug, Bundle)] pub use self::label::*;
pub struct UiKitButton { mod label {
button_bundle: ButtonBundle, use super::*;
select: UiKitSelect,
#[derive(Debug, Component)]
pub struct UiKitLabel {
pub name: String,
}
// TODO: Handle modified labels
pub fn manage_labels(
events: Query<(Entity, &UiKitLabel), Added<UiKitLabel>>,
mut commands: Commands,
) {
events.iter().for_each(|(entity, label)| {
commands.entity(entity).with_children(|parent| {
parent.spawn(
TextBundle::from_section(
label.name.clone(),
TextStyle {
color: Color::BLACK,
..default()
},
)
.with_style(Style {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
..default()
}),
);
});
});
}
} }
impl UiKitButton { pub use self::button::*;
pub fn new(color: Color) -> Self { mod button {
UiKitButton { use super::*;
button_bundle: ButtonBundle {
style: Style { #[derive(Debug, Component)]
border: UiRect::all(Val::Px(1.0)), pub struct UiKitButton {
width: Val::Px(100.0), pub color: Color,
height: Val::Px(50.0), }
flex_direction: FlexDirection::Column,
pub fn spawn_button(
events: Query<(Entity, &UiKitButton, Option<&UiKitLabel>), Added<UiKitButton>>,
mut commands: Commands,
) {
events.iter().for_each(|(entity, button, label)| {
commands
.entity(entity)
.insert(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(button.color),
border_color: BorderColor(Color::BLACK),
..default() ..default()
}, })
background_color: BackgroundColor(color), .with_children(|parent| {
border_color: BorderColor(Color::BLACK), if let Some(label) = label {
..default() parent.spawn(
}, TextBundle::from_section(
select: UiKitSelect::None, label.name.clone(),
} TextStyle {
color: Color::BLACK,
..default()
},
)
.with_style(Style {
align_self: AlignSelf::Center,
justify_self: JustifySelf::Center,
..default()
}),
);
}
});
});
} }
} }
#[derive(Debug, Component, Copy, Clone, PartialEq)] pub use self::select::*;
pub enum UiKitSelect { mod select {
Active, use super::*;
None,
}
#[derive(Debug, Bundle)] #[derive(Debug, Component, Copy, Clone, PartialEq)]
pub struct UiKitTextInput { pub enum UiKitSelect {
text_bundle: TextBundle, Active,
interaction: Interaction, None,
select: UiKitSelect, }
impl Default for UiKitSelect {
fn default() -> Self {
UiKitSelect::None
}
}
/// When an item is selected/de-selected change it's display accordingly
pub fn selection(
mut events: Query<
(&mut BackgroundColor, &UiKitSelect, &Children),
(Changed<UiKitSelect>, With<Button>),
>,
mut styles: Query<&mut Style>,
) {
events
.iter_mut()
.for_each(|(mut bg_color, select, children)| {
bg_color.0 = match select {
UiKitSelect::Active => Color::RED,
UiKitSelect::None => Color::WHITE,
};
children.iter().for_each(|&child| {
if let Ok(mut style) = styles.get_mut(child) {
style.display = match select {
UiKitSelect::Active => Display::Flex,
UiKitSelect::None => Display::None,
}
}
});
});
}
} }
impl UiKitTextInput { pub use self::text_input::*;
pub fn new() -> Self { mod text_input {
UiKitTextInput { use super::*;
text_bundle: TextBundle {
style: Style { #[derive(Debug, Bundle)]
width: Val::Percent(100.0), pub struct UiKitTextInput {
height: Val::Percent(100.0), text_bundle: TextBundle,
interaction: Interaction,
select: UiKitSelect,
}
impl UiKitTextInput {
pub fn new() -> Self {
UiKitTextInput {
text_bundle: TextBundle {
style: Style {
// width: Val::Percent(100.0),
// height: Val::Percent(100.0),
..default()
},
..default() ..default()
}, },
..default() interaction: Interaction::None,
}, select: UiKitSelect::None,
interaction: Interaction::None, }
select: UiKitSelect::None,
} }
} }
}
/// When an item is selected/de-selected change it's display accordingly pub fn select_textbox(
fn selection( mut events: Query<(&Interaction, &mut UiKitSelect), (With<Text>, Changed<Interaction>)>,
mut events: Query< ) {
(&mut BackgroundColor, &UiKitSelect, &Children), events.iter_mut().for_each(|(interaction, mut select)| {
(Changed<UiKitSelect>, With<Button>), *select = match interaction {
>, Interaction::Pressed => UiKitSelect::Active,
mut styles: Query<&mut Style>, Interaction::Hovered => UiKitSelect::Active,
) { Interaction::None => UiKitSelect::None,
events }
.iter_mut() });
.for_each(|(mut bg_color, select, children)| { }
bg_color.0 = match select {
UiKitSelect::Active => Color::RED, pub fn text_editor(
UiKitSelect::None => Color::WHITE, keyboard: Res<Input<KeyCode>>,
}; mut events: EventReader<KeyboardInput>,
children.iter().for_each(|&child| { mut query: Query<&mut Text, With<UiKitSelect>>,
if let Ok(mut style) = styles.get_mut(child) { ) {
style.display = match select { events.iter().for_each(
UiKitSelect::Active => Display::Flex, |KeyboardInput {
UiKitSelect::None => Display::None, key_code,
state,
scan_code,
..
}| {
match state {
ButtonState::Pressed => {
if let Some(kc) = key_code {
query.iter_mut().for_each(|mut text| {
use KeyCode::*;
let style = TextStyle {
color: Color::BLACK,
..default()
};
if *kc == Back {
text.sections.pop();
} else {
let c = match kc {
// Letters
A | B | C | D | E | F | G | H | I | J | K | L | M | N
| O | P | Q | R | S | T | U | V | W | X | Y | Z => {
if keyboard.any_pressed([ShiftLeft, ShiftRight]) {
format!("{:?}", kc).to_uppercase()
} else {
format!("{:?}", kc).to_lowercase()
}
}
// Top Row
Grave => "`".to_string(),
Key1 | Numpad1 => "1".to_string(),
Key2 | Numpad2 => "2".to_string(),
Key3 | Numpad3 => "3".to_string(),
Key4 | Numpad4 => "4".to_string(),
Key5 | Numpad5 => "5".to_string(),
Key6 | Numpad6 => "6".to_string(),
Key7 | Numpad7 => "7".to_string(),
Key8 | Numpad8 => "8".to_string(),
Key9 | Numpad9 => "9".to_string(),
Key0 | Numpad0 => "0".to_string(),
Minus => "-".to_string(),
Equals => "=".to_string(),
// Left side
Tab => "\t".to_string(),
// Right side
// Row 2
BracketLeft => "[".to_string(),
BracketRight => "]".to_string(),
Backslash => "\\".to_string(),
// Row 3
Semicolon => ";".to_string(),
Apostrophe => "'".to_string(),
Return => "\n".to_string(),
// Row 4
Comma => ",".to_string(),
Period => ".".to_string(),
Slash => "/".to_string(),
// Space
Space => " ".to_string(),
// None
_ => "".to_string(),
};
if c.len() > 0 {
text.sections.push(TextSection::new(c, style));
}
}
});
}
} }
_ => (),
} }
}); },
}); )
}
} }
/// Toggle a UI Nav tree open/closed /// Toggle a UI Nav tree open/closed
/// ///
/// PERF: This is hella not performant, we just usually don't have many elements to iterate over so /// PERF: This is hella not performant, we just usually don't have many elements to iterate over so
/// it's tolerable. /// it's tolerable.
/// pub fn select_tab(
// TODO: Should not be able to select multiple children in branch of tree
// TODO: Port to ui.rs
fn select_tab(
events: Query<Entity, (Changed<Interaction>, With<Button>)>, events: Query<Entity, (Changed<Interaction>, With<Button>)>,
interactions: Query<&Interaction, With<Button>>, interactions: Query<&Interaction, With<Button>>,
mut selects: Query<&mut UiKitSelect>, mut selects: Query<&mut UiKitSelect>,
@ -250,102 +443,6 @@ fn select_tab(
}); });
} }
fn select_textbox(
mut events: Query<(&Interaction, &mut UiKitSelect), (With<Text>, Changed<Interaction>)>,
) {
events.iter_mut().for_each(|(interaction, mut select)| {
*select = match interaction {
Interaction::Pressed => UiKitSelect::Active,
Interaction::Hovered => UiKitSelect::Active,
Interaction::None => UiKitSelect::None,
}
});
}
fn text_editor(
keyboard: Res<Input<KeyCode>>,
mut events: EventReader<KeyboardInput>,
mut query: Query<&mut Text, With<UiKitSelect>>,
) {
events.iter().for_each(
|KeyboardInput {
key_code,
state,
scan_code,
..
}| {
match state {
ButtonState::Pressed => {
if let Some(kc) = key_code {
query.iter_mut().for_each(|mut text| {
use KeyCode::*;
let style = TextStyle {
color: Color::BLACK,
..default()
};
if *kc == Back {
text.sections.pop();
} else {
let c = match kc {
// Letters
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O
| P | Q | R | S | T | U | V | W | X | Y | Z => {
if keyboard.any_pressed([ShiftLeft, ShiftRight]) {
format!("{:?}", kc).to_uppercase()
} else {
format!("{:?}", kc).to_lowercase()
}
}
// Top Row
Grave => "`".to_string(),
Key1 | Numpad1 => "1".to_string(),
Key2 | Numpad2 => "2".to_string(),
Key3 | Numpad3 => "3".to_string(),
Key4 | Numpad4 => "4".to_string(),
Key5 | Numpad5 => "5".to_string(),
Key6 | Numpad6 => "6".to_string(),
Key7 | Numpad7 => "7".to_string(),
Key8 | Numpad8 => "8".to_string(),
Key9 | Numpad9 => "9".to_string(),
Key0 | Numpad0 => "0".to_string(),
Minus => "-".to_string(),
Equals => "=".to_string(),
// Left side
Tab => "\t".to_string(),
// Right side
// Row 2
BracketLeft => "[".to_string(),
BracketRight => "]".to_string(),
Backslash => "\\".to_string(),
// Row 3
Semicolon => ";".to_string(),
Apostrophe => "'".to_string(),
Return => "\n".to_string(),
// Row 4
Comma => ",".to_string(),
Period => ".".to_string(),
Slash => "/".to_string(),
// Space
Space => " ".to_string(),
// None
_ => "".to_string(),
};
if c.len() > 0 {
text.sections.push(TextSection::new(c, style));
}
}
});
}
}
_ => (),
}
},
)
}
// TODO: Reset default position when de-activated // TODO: Reset default position when de-activated
fn scroll( fn scroll(
mut scrolls: EventReader<MouseWheel>, mut scrolls: EventReader<MouseWheel>,
@ -367,7 +464,7 @@ fn scroll(
// Find the leaf selected entity // Find the leaf selected entity
let leaf = query let leaf = query
.iter() .iter()
.find(|(_, select, _, children, parent)| { .find(|(_, select, _, children, _)| {
// This node is active // This node is active
let self_active = **select == UiKitSelect::Active; let self_active = **select == UiKitSelect::Active;
// All children are not selected // All children are not selected
@ -391,7 +488,6 @@ fn scroll(
MouseScrollUnit::Pixel => 5.0, MouseScrollUnit::Pixel => 5.0,
}; };
style.top.try_sub_assign(Val::Px(delta)); style.top.try_sub_assign(Val::Px(delta));
info!("Top: {:?}", style.top);
} }
} }
}; };

Loading…
Cancel
Save