mirror of
https://github.com/bevyengine/bevy.git
synced 2026-05-06 06:06:42 -04:00
6b0fb37e2c
# Objective Part 3 of #23619 ## Solution Renames `bevy_scene2` to `bevy_scene` and adds it to the prelude.
70 lines
2.0 KiB
Rust
70 lines
2.0 KiB
Rust
//! Virtual keyboard example
|
|
|
|
use bevy::{
|
|
color::palettes::css::NAVY,
|
|
feathers::{
|
|
controls::{virtual_keyboard, VirtualKeyPressed},
|
|
dark_theme::create_dark_theme,
|
|
theme::UiTheme,
|
|
FeathersPlugins,
|
|
},
|
|
prelude::*,
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins((DefaultPlugins, FeathersPlugins))
|
|
.insert_resource(UiTheme(create_dark_theme()))
|
|
.add_systems(Startup, setup)
|
|
.run();
|
|
}
|
|
|
|
fn on_virtual_key_pressed(virtual_key_pressed: On<VirtualKeyPressed<&'static str>>) {
|
|
println!("key pressed: {}", virtual_key_pressed.key);
|
|
}
|
|
|
|
fn setup(world: &mut World) -> Result {
|
|
world.spawn_scene_list(bsn_list![Camera2d, keyboard()])?;
|
|
Ok(())
|
|
}
|
|
|
|
fn keyboard() -> impl Scene {
|
|
let layout = [
|
|
vec!["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ","],
|
|
vec!["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],
|
|
vec!["A", "S", "D", "F", "G", "H", "J", "K", "L", "'"],
|
|
vec!["Z", "X", "C", "V", "B", "N", "M", "-", "/"],
|
|
vec!["space", "enter", "backspace"],
|
|
vec!["left", "right", "up", "down", "home", "end"],
|
|
];
|
|
|
|
bsn! {
|
|
Node {
|
|
width: percent(100),
|
|
height: percent(100),
|
|
align_items: AlignItems::End,
|
|
justify_content: JustifyContent::Center,
|
|
}
|
|
Children [(
|
|
Node {
|
|
flex_direction: FlexDirection::Column,
|
|
border: px(5),
|
|
row_gap: px(5),
|
|
padding: px(5),
|
|
align_items: AlignItems::Center,
|
|
margin: px(25),
|
|
border_radius: BorderRadius::all(px(10)),
|
|
}
|
|
BackgroundColor(NAVY)
|
|
BorderColor::all(Color::WHITE)
|
|
Children [
|
|
Text("virtual keyboard"),
|
|
(
|
|
virtual_keyboard(layout.into_iter())
|
|
on(on_virtual_key_pressed)
|
|
)
|
|
]
|
|
)]
|
|
}
|
|
}
|