1use ascii_forge::prelude::*;
7use std::io;
8use widget_forge::prelude::*;
9
10#[derive(Default)]
11pub struct AppData {
12 should_exit: bool,
13}
14
15fn hello(w: &mut Window, _d: &mut AppData) {
16 let center = {
17 let s = w.size();
18 vec2(s.x / 2, s.y / 2)
19 };
20
21 render!(w, (center.x - 13/2, center.y) => [ "Hello, World!".green() ]);
22}
23
24fn quit_handler(w: &mut Window, d: &mut AppData) {
25 if event!(w, Event::Key(e) => e.code == KeyCode::Char('q')) {
26 d.should_exit = true;
27 }
28}
29
30fn main() -> io::Result<()> {
31 let window = Window::init()?;
32 handle_panics();
33 Scene::new(window, AppData::default())
34 .insert_widgets((hello, quit_handler))
36 .run(100, |scene| !scene.data().should_exit)?;
38 Ok(())
39}