2024-04-16 20:45:31 +03:00
|
|
|
use crate::{gtk::prelude::*, model::model::*, view::components::switch::SwitchExt};
|
2024-03-10 11:35:02 +03:00
|
|
|
|
2024-04-16 20:45:31 +03:00
|
|
|
pub trait SwEventHandler {
|
2024-03-10 11:54:32 +03:00
|
|
|
fn on_toggle(self) -> ();
|
|
|
|
}
|
2024-03-10 11:35:02 +03:00
|
|
|
|
2024-03-10 11:54:32 +03:00
|
|
|
impl<F, C> SwEventHandler for EventHandler<F, C>
|
2024-04-16 20:45:31 +03:00
|
|
|
where
|
|
|
|
F: Fn(&C) + FnOnce(&C) + FnMut(&C) + 'static,
|
|
|
|
C: SwitchExt + WidgetExt,
|
|
|
|
{
|
2024-03-10 11:54:32 +03:00
|
|
|
fn on_toggle(self) -> () {
|
2024-04-16 20:45:31 +03:00
|
|
|
self.component
|
|
|
|
.connect_state_notify(move |switch| (self.callback)(switch));
|
2024-03-10 11:35:02 +03:00
|
|
|
}
|
2024-03-10 11:54:32 +03:00
|
|
|
}
|