AIT/src/controller/event_handlers/button_event_handlers.rs

29 lines
588 B
Rust

use crate::{gtk::prelude::*, model::models::*};
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,
}
}
}
pub trait BtnEventHandler {
fn on_click(self);
}
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));
}
}