use auralis_task::TaskScope;
use crate::core::context::MountContext;
use crate::core::widget::Widget;
use crate::core::ElementId;
pub struct Compositor<F, W> {
build: F,
_phantom: std::marker::PhantomData<fn() -> W>,
}
impl<F, W> Compositor<F, W> {
pub fn new(build: F) -> Self
where
F: FnOnce(&TaskScope) -> W,
{
Self {
build,
_phantom: std::marker::PhantomData,
}
}
}
impl<F, W> Widget for Compositor<F, W>
where
F: FnOnce(&TaskScope) -> W + 'static,
W: Widget + 'static,
{
fn mount_box(self: Box<Self>, ctx: &mut MountContext<'_>) -> ElementId {
let child_scope = TaskScope::new();
let widget: W = (self.build)(&child_scope);
Box::new(widget).mount_box(ctx)
}
}
impl<F, W> std::fmt::Debug for Compositor<F, W> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Compositor").finish_non_exhaustive()
}
}