keyboard/
keyboard.rs

1use arkham::prelude::*;
2
3fn main() {
4    App::new(root).run().expect("couldnt launch app");
5}
6
7fn root(ctx: &mut ViewContext) {
8    let size = ctx.size();
9    ctx.fill(size, Rune::new().bg(Color::DarkGrey));
10    ctx.component(((10, 10), (30, 1)), hello_world);
11    ctx.component(((10, 11), (20, 1)), show_key_press);
12    ctx.component((0, (size.width, 1)), quit_nag);
13}
14
15fn hello_world(ctx: &mut ViewContext) {
16    ctx.insert(0, "Hello World, Press a key");
17}
18
19fn show_key_press(ctx: &mut ViewContext, kb: Res<Keyboard>) {
20    if let Some(c) = kb.char() {
21        ctx.insert(0, format!("Key press: {}", c));
22    }
23}
24
25fn quit_nag(ctx: &mut ViewContext) {
26    let size = ctx.size();
27    ctx.insert(
28        ((size.width / 2) - 7, 0),
29        "Press Q to Quit".to_runes().fg(Color::Red),
30    );
31}