use masonry::kurbo::Affine;
use masonry::core::{FromDynWidget, HasProperty, Property, Widget};
use crate::core::{View, ViewSequence};
use crate::view::{Prop, Transformed, transformed};
use crate::{AnyWidgetView, Pod, ViewCtx};
#[expect(missing_docs, reason = "TODO - Document these items")]
pub trait WidgetView<State, Action = ()>:
View<State, Action, ViewCtx, Element = Pod<Self::Widget>> + Send + Sync
{
type Widget: Widget + FromDynWidget + ?Sized;
fn boxed(self) -> Box<AnyWidgetView<State, Action>>
where
State: 'static,
Action: 'static,
Self: Sized,
{
Box::new(self)
}
fn transform(self, by: Affine) -> Transformed<Self, State, Action>
where
Self: Sized,
{
transformed(self).transform(by)
}
fn prop<P>(self, property: P) -> Prop<P, Self, State, Action>
where
State: 'static,
Action: 'static,
Self: Sized,
Self::Widget: HasProperty<P>,
P: Property + PartialEq + Clone,
{
Prop {
property,
child: self,
phantom: std::marker::PhantomData,
}
}
}
impl<V, State, Action, W> WidgetView<State, Action> for V
where
V: View<State, Action, ViewCtx, Element = Pod<W>> + Send + Sync,
W: Widget + FromDynWidget + ?Sized,
{
type Widget = W;
}
pub trait WidgetViewSequence<State, Action = ()>:
ViewSequence<State, Action, ViewCtx, Pod<dyn Widget>>
{
}
impl<Seq, State, Action> WidgetViewSequence<State, Action> for Seq where
Seq: ViewSequence<State, Action, ViewCtx, Pod<dyn Widget>>
{
}