use super::*;
pub trait Filter<E>: Clone + Default + Sized where E: Env, EEFilter<E>: From<Self> {
fn _filter(&self, dest: &Link<E>, e: &EventCompound<E>) -> Option<EventCompound<E>>;
fn attach_path_prefix(self, prefix: E::WidgetPath) -> Self;
}
#[derive(Clone)]
pub struct StdFilter<E> where E: Env, EEFilter<E>: From<Self> {
pub filter_path: E::WidgetPath,
pub filter_bounds: bool,
}
impl<E> Filter<E> for StdFilter<E> where E: Env, EEFilter<E>: From<Self> {
fn _filter(&self, dest: &Link<E>, e: &EventCompound<E>) -> Option<EventCompound<E>> {
if !self.filter_path.is_empty() {
dest.widget.resolved_by_path(&self.filter_path)
.map(#[inline] |r| EventCompound{
filter: StdFilter{
filter_path: r.sub_path,
filter_bounds: self.filter_bounds,
}.into(),
..e.clone()
} )
}else if self.filter_bounds {
e.filter_bounds()
}else{
Some(e.clone())
}
}
fn attach_path_prefix(mut self, prefix: E::WidgetPath) -> Self {
self.filter_path = prefix.attached_subpath(&self.filter_path);
self
}
}
impl<E> Default for StdFilter<E> where E: Env, EEFilter<E>: From<Self> {
fn default() -> Self {
Self{
filter_bounds: true,
filter_path: E::WidgetPath::empty(),
}
}
}