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