|
|
|
|
@ -22,156 +22,349 @@ pub struct GameUiPlugin;
|
|
|
|
|
impl Plugin for GameUiPlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
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 struct UiKitContainer {
|
|
|
|
|
node_bundle: NodeBundle,
|
|
|
|
|
select: UiKitSelect,
|
|
|
|
|
}
|
|
|
|
|
pub use self::container::*;
|
|
|
|
|
mod container {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
|
pub enum UiKitPosition {
|
|
|
|
|
Top,
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
}
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct UiKitContainer {
|
|
|
|
|
pub position: UiKitPosition,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl UiKitContainer {
|
|
|
|
|
pub 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 {
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
|
pub enum UiKitPosition {
|
|
|
|
|
Top,
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn spawn_container(
|
|
|
|
|
events: Query<(Entity, &UiKitContainer, Option<&UiKitLabel>), Added<UiKitContainer>>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|(entity, container, label)| {
|
|
|
|
|
let base_style = 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: UiKitSelect::None,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let style = match container.position {
|
|
|
|
|
UiKitPosition::Top => Style {
|
|
|
|
|
top: Val::Percent(100.0),
|
|
|
|
|
align_items: AlignItems::Start,
|
|
|
|
|
..base_style
|
|
|
|
|
},
|
|
|
|
|
UiKitPosition::Left => Style {
|
|
|
|
|
left: Val::Percent(100.0),
|
|
|
|
|
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 struct UiKitButton {
|
|
|
|
|
button_bundle: ButtonBundle,
|
|
|
|
|
select: UiKitSelect,
|
|
|
|
|
pub use self::label::*;
|
|
|
|
|
mod label {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[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 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,
|
|
|
|
|
pub use self::button::*;
|
|
|
|
|
mod button {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
pub struct UiKitButton {
|
|
|
|
|
pub color: Color,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
},
|
|
|
|
|
background_color: BackgroundColor(color),
|
|
|
|
|
border_color: BorderColor(Color::BLACK),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
select: UiKitSelect::None,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.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, Component, Copy, Clone, PartialEq)]
|
|
|
|
|
pub enum UiKitSelect {
|
|
|
|
|
Active,
|
|
|
|
|
None,
|
|
|
|
|
}
|
|
|
|
|
pub use self::select::*;
|
|
|
|
|
mod select {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Bundle)]
|
|
|
|
|
pub struct UiKitTextInput {
|
|
|
|
|
text_bundle: TextBundle,
|
|
|
|
|
interaction: Interaction,
|
|
|
|
|
select: UiKitSelect,
|
|
|
|
|
#[derive(Debug, Component, Copy, Clone, PartialEq)]
|
|
|
|
|
pub enum UiKitSelect {
|
|
|
|
|
Active,
|
|
|
|
|
None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 fn new() -> Self {
|
|
|
|
|
UiKitTextInput {
|
|
|
|
|
text_bundle: TextBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
|
pub use self::text_input::*;
|
|
|
|
|
mod text_input {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Bundle)]
|
|
|
|
|
pub struct UiKitTextInput {
|
|
|
|
|
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()
|
|
|
|
|
},
|
|
|
|
|
interaction: Interaction::None,
|
|
|
|
|
select: UiKitSelect::None,
|
|
|
|
|
interaction: Interaction::None,
|
|
|
|
|
select: UiKitSelect::None,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When an item is selected/de-selected change it's display accordingly
|
|
|
|
|
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,
|
|
|
|
|
pub 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,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub 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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => (),
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
/// it's tolerable.
|
|
|
|
|
///
|
|
|
|
|
// TODO: Should not be able to select multiple children in branch of tree
|
|
|
|
|
// TODO: Port to ui.rs
|
|
|
|
|
fn select_tab(
|
|
|
|
|
pub fn select_tab(
|
|
|
|
|
events: Query<Entity, (Changed<Interaction>, With<Button>)>,
|
|
|
|
|
interactions: Query<&Interaction, With<Button>>,
|
|
|
|
|
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
|
|
|
|
|
fn scroll(
|
|
|
|
|
mut scrolls: EventReader<MouseWheel>,
|
|
|
|
|
@ -367,7 +464,7 @@ fn scroll(
|
|
|
|
|
// Find the leaf selected entity
|
|
|
|
|
let leaf = query
|
|
|
|
|
.iter()
|
|
|
|
|
.find(|(_, select, _, children, parent)| {
|
|
|
|
|
.find(|(_, select, _, children, _)| {
|
|
|
|
|
// This node is active
|
|
|
|
|
let self_active = **select == UiKitSelect::Active;
|
|
|
|
|
// All children are not selected
|
|
|
|
|
@ -391,7 +488,6 @@ fn scroll(
|
|
|
|
|
MouseScrollUnit::Pixel => 5.0,
|
|
|
|
|
};
|
|
|
|
|
style.top.try_sub_assign(Val::Px(delta));
|
|
|
|
|
info!("Top: {:?}", style.top);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|