Add derive macro for IntoAnyElement

This commit is contained in:
Nathan Sobo 2023-10-26 12:20:46 +02:00
parent 927278e20d
commit 315744ec20
4 changed files with 79 additions and 9 deletions

View file

@ -12,6 +12,7 @@ pub enum SplitDirection {
Vertical,
}
#[derive(IntoAnyElement)]
pub struct Pane<V: 'static> {
id: ElementId,
size: Size<Length>,
@ -19,12 +20,12 @@ pub struct Pane<V: 'static> {
children: SmallVec<[AnyElement<V>; 2]>,
}
impl<V: 'static> IntoAnyElement<V> for Pane<V> {
fn into_any(self) -> AnyElement<V> {
(move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx))
.into_any()
}
}
// impl<V: 'static> IntoAnyElement<V> for Pane<V> {
// fn into_any(self) -> AnyElement<V> {
// (move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx))
// .into_any()
// }
// }
impl<V: 'static> Pane<V> {
pub fn new(id: impl Into<ElementId>, size: Size<Length>) -> Self {