use druid::{
    widget::{prelude::*, ControllerHost},
    Selector, WidgetExt as _,
};
use crate::widgets::{OnChange, OnCmd, OnNotify, ShowIf, ShowIfCallback};
pub trait WidgetExt<T: Data>: Widget<T> + Sized + 'static {
    fn on_command<CT: 'static>(
        self,
        selector: Selector<CT>,
        handler: impl Fn(&mut EventCtx, &CT, &mut T) + 'static,
    ) -> ControllerHost<Self, OnCmd<CT, T>> {
        self.controller(OnCmd::new(selector, handler))
    }
    fn on_notify<CT: 'static>(
        self,
        selector: Selector<CT>,
        handler: impl Fn(&mut EventCtx, &CT, &mut T) + 'static,
    ) -> OnNotify<CT, T> {
        OnNotify::new(selector, handler, self)
    }
    fn on_change(
        self,
        f: impl Fn(&mut EventCtx, &T, &mut T, &Env) + 'static,
    ) -> ControllerHost<Self, OnChange<T>> {
        self.controller(OnChange::new(f))
    }
    fn show_if(self, f: ShowIfCallback<T>) -> ShowIf<T> {
        ShowIf::new(self, f)
    }
}
impl<T: Data, W: Widget<T> + 'static> WidgetExt<T> for W {}