tengri/examples/mode_00.rs
facile pop culture reference a27dacff93 moar flat
2026-08-01 17:52:37 +03:00

38 lines
926 B
Rust

//! Mode 00: Direct draw, direct control
use ::tengri::{
*,
dizzle::*,
crossterm::event::{KeyEvent, Event::*, KeyCode::*},
ratatui::style::Color,
};
tui_app!(State {
/** User-controllable value. */
counter: usize,
});
tui_view!(self: State {
draw(|to: &mut Tui|{
let _ = "Demo [Mode 00]".align_sw().draw(to);
let _ = ShowSize.align_se().draw(to);
let _ = format!("Counter:\n{}", self.counter).align_c().draw(to);
Ok(Some(to.area()))
})
});
tui_keys!(self: State, input {
Ok(if let Key(KeyEvent { code, .. }) = input.0 {
match code {
Up | Right => {
self.counter = (self.counter + 1) % 10;
()
},
Down | Left => {
self.counter = if self.counter > 0 { self.counter - 1 } else { 10 - 1 };
()
},
_ => {}
}
})
});