use crate::{Alignment, Event, Frame, Handler, Insets, Modified, ModifierNode, Vec2, View};
use super::Overlay;
pub trait ViewExt: Sized {
fn modifier(self, modifier: ModifierNode) -> Modified<Self> {
Modified::new(self, modifier)
}
fn overlay_at<O>(self, alignment: Alignment, overlayed: O) -> Overlay<Self, O> {
Overlay::new(self, alignment, overlayed)
}
fn overlay<O>(self, overlayed: O) -> Overlay<Self, O> {
self.overlay_at(Alignment::Center, overlayed)
}
fn padding(self, insets: impl Into<Insets>) -> Modified<Self> {
self.modifier(ModifierNode::Padding { insets: insets.into() })
}
fn position(self, position: Vec2<f64>) -> Modified<Self> {
self.modifier(ModifierNode::Position { position })
}
fn frame(self, frame: impl Into<Frame>) -> Modified<Self> {
self.modifier(ModifierNode::Frame { frame: frame.into() })
}
fn on_appear(self, action: impl Fn() + 'static) -> Handler<Self, impl Fn(Event)> {
Handler::new(self, move |e| {
if let Event::Appear = e {
action();
}
})
}
fn on_disappear(self, action: impl Fn() + 'static) -> Handler<Self, impl Fn(Event)> {
Handler::new(self, move |e| {
if let Event::Disappear = e {
action();
}
})
}
}
impl<T> ViewExt for T where T: View {}