AIT/src/controller/event_handlers/button_event_handlers.rs

30 lines
636 B
Rust
Raw Normal View History

2024-03-10 11:54:32 +03:00
use crate::{
model::model::*,
gtk::{
*,
prelude::*
},
};
2024-03-10 11:54:32 +03:00
impl<F, C> EventHandler<F, C>
where F: Fn(&C) + FnOnce(&C) + FnMut(&C){
pub fn new(component: C, callback: F) -> EventHandler<F, C>{
Self{
component,
callback,
}
}
2024-03-10 11:54:32 +03:00
}
2024-03-10 11:54:32 +03:00
pub trait BtnEventHandler{
fn on_click(self) -> ();
}
2024-03-10 11:54:32 +03:00
impl<F, C> BtnEventHandler for EventHandler<F, C>
where F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static, C: ButtonExt + WidgetExt{
fn on_click(self) -> () {
self.component.connect_clicked(move |button| {
(self.callback)(button)
});
}
}