use std::marker::PhantomData;
use crate::{
prelude::{BuildCtx, ComposeChild, Declare, DeclareBuilder},
state::State,
widget::Widget,
};
#[derive(Declare)]
pub struct Decorator<Host, F: Fn(Host) -> Widget> {
decorate_fn: F,
#[declare(skip)]
_marker: PhantomData<*const Host>,
}
impl<Host, F: Fn(Host) -> Widget> ComposeChild for Decorator<Host, F> {
type Child = Host;
fn compose_child(this: State<Self>, child: Self::Child) -> Widget {
let this = match this {
State::Stateless(this) => this,
State::Stateful(_) => panic!("A hasn't any public fields, it should never be stateful."),
};
(this.decorate_fn)(child)
}
}