Path: blob/main/examples/ui/widgets/virtual_keyboard.rs
9345 views
//! Virtual keyboard example12use bevy::{3color::palettes::css::NAVY,4feathers::{5controls::{virtual_keyboard, VirtualKeyPressed},6dark_theme::create_dark_theme,7theme::UiTheme,8FeathersPlugins,9},10prelude::*,11ui_widgets::observe,12};1314fn main() {15App::new()16.add_plugins((DefaultPlugins, FeathersPlugins))17.insert_resource(UiTheme(create_dark_theme()))18.add_systems(Startup, setup)19.run();20}2122fn on_virtual_key_pressed(virtual_key_pressed: On<VirtualKeyPressed<&'static str>>) {23println!("key pressed: {}", virtual_key_pressed.key);24}2526fn setup(mut commands: Commands) {27// ui camera28commands.spawn(Camera2d);2930let layout = [31vec!["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ","],32vec!["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],33vec!["A", "S", "D", "F", "G", "H", "J", "K", "L", "'"],34vec!["Z", "X", "C", "V", "B", "N", "M", "-", "/"],35vec!["space", "enter", "backspace"],36vec!["left", "right", "up", "down", "home", "end"],37];3839commands.spawn((40Node {41width: percent(100),42height: percent(100),43align_items: AlignItems::End,44justify_content: JustifyContent::Center,45..default()46},47children![(48Node {49flex_direction: FlexDirection::Column,50border: px(5).into(),51row_gap: px(5),52padding: px(5).into(),53align_items: AlignItems::Center,54margin: px(25).into(),55border_radius: BorderRadius::all(px(10)),56..Default::default()57},58BackgroundColor(NAVY.into()),59BorderColor::all(Color::WHITE),60children![61Text::new("virtual keyboard"),62(63virtual_keyboard(layout.into_iter()),64observe(on_virtual_key_pressed)65)66]67)],68));69}707172