input handling #17
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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::*;
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user