input handling #17

This commit is contained in:
2025-08-02 06:47:03 -05:00
parent d00fbb6565
commit 911968a1cb
4 changed files with 30 additions and 0 deletions
+3
View File
@@ -12,6 +12,9 @@ pub fn app() -> Rsx {
}); });
rsx! { rsx! {
@Handler::new(|_, _: &crossterm::event::Event| {
panic!("idk lol");
});
FlexRow { FlexRow {
FlexCol { FlexCol {
@Transform::new().padding(2, 2); @Transform::new().padding(2, 2);
+24
View File
@@ -0,0 +1,24 @@
use crate::{extensions::Extension, prelude::Handler};
pub struct InputExtension;
impl Extension for InputExtension {
fn init(&mut self, screen: std::sync::Arc<crate::Screen>) {
crossterm::terminal::enable_raw_mode().unwrap();
std::thread::spawn(move || loop {
if let Ok(e) = crossterm::event::read() {
for widget in screen.widgets.lock().unwrap().iter() {
if let Some(h) = widget.get::<Handler<crossterm::event::Event>>() {
h.call(widget, &e);
}
}
}
});
}
}
impl crate::extensions::Event for crossterm::event::Event {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
+2
View File
@@ -1,8 +1,10 @@
pub mod id; pub mod id;
pub mod input_handling;
pub mod tick; pub mod tick;
pub mod velocity; pub mod velocity;
pub use id::*; pub use id::*;
pub use input_handling::*;
pub use tick::*; pub use tick::*;
pub use velocity::*; pub use velocity::*;
+1
View File
@@ -3,6 +3,7 @@ use osui::prelude::*;
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
let screen = Screen::new(); let screen = Screen::new();
screen.extension(InputExtension);
demos::app().draw(&screen); demos::app().draw(&screen);