handlers and ids
This commit is contained in:
+27
-4
@@ -1,11 +1,34 @@
|
||||
pub mod id;
|
||||
pub mod tick;
|
||||
pub mod velocity;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::widget::Widget;
|
||||
use crate::{render_scope::RenderScope, widget::Widget};
|
||||
|
||||
pub trait Extension {
|
||||
fn init(&self, _widgets: &Vec<Arc<Widget>>) {}
|
||||
fn render(&self, _widget: &Arc<Widget>) {}
|
||||
fn init(&mut self, _widgets: &Vec<Arc<Widget>>) {}
|
||||
fn render_widget(&mut self, _scope: &mut RenderScope, _widget: &Arc<Widget>) {}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Handler(pub Arc<Mutex<dyn FnMut(&Arc<Widget>) + Send + Sync>>);
|
||||
|
||||
impl Handler {
|
||||
pub fn new<F: FnMut(&Arc<Widget>) + Send + Sync + 'static>(f: F) -> Handler {
|
||||
Handler(Arc::new(Mutex::new(f)))
|
||||
}
|
||||
|
||||
pub fn call(&self, w: &Arc<Widget>) {
|
||||
(self.0.lock().unwrap())(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Handler {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Handler")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user