From db7d12f6282bce538aa33a5b7d00bc24fe52f041 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 26 Oct 2023 10:59:27 +0200 Subject: [PATCH] WIP --- crates/ui2/src/components/panes.rs | 53 ++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 789898cb9d..8ad1d4091d 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -13,17 +13,18 @@ pub enum SplitDirection { } // #[derive(Element)] -pub struct Pane { +pub struct Pane { id: ElementId, - state_type: PhantomData, + state_type: PhantomData, size: Size, fill: Hsla, - children: SmallVec<[AnyElement; 2]>, + children: SmallVec<[AnyElement; 2]>, } impl IntoAnyElement for Pane { fn into_any(self) -> AnyElement { - let render = move |view_state, cx| self.render(view_state, cx); + let render = + move |view_state: &mut V, cx: &mut ViewContext<'_, '_, V>| self.render(view_state, cx); AnyElement::new(ElementRenderer { render: Some(render), @@ -35,20 +36,36 @@ impl IntoAnyElement for Pane { struct ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, { render: Option, view_type: PhantomData, element_type: PhantomData, } +unsafe impl Send for ElementRenderer +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, +{ +} + +unsafe impl Sync for ElementRenderer +where + V: 'static, + E: 'static + IntoAnyElement + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, +{ +} + impl Element for ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, - F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, + F: FnOnce(&mut V, &mut ViewContext<'_, '_, V>) -> E + 'static + Send + Sync, { type ElementState = AnyElement; @@ -88,7 +105,7 @@ where impl IntoAnyElement for ElementRenderer where - V: 'static + Send + Sync, + V: 'static, E: 'static + IntoAnyElement + Send + Sync, F: FnOnce(&mut V, &mut ViewContext) -> E + 'static + Send + Sync, { @@ -97,7 +114,7 @@ where } } -impl Pane { +impl Pane { pub fn new(id: impl Into, size: Size) -> Self { // Fill is only here for debugging purposes, remove before release @@ -116,7 +133,7 @@ impl Pane { self } - fn render(self, view: &mut V, cx: &mut ViewContext) -> Div> IntoAnyElement { + fn render(self, view: &mut V, cx: &mut ViewContext) -> impl IntoAnyElement { div() .id(self.id.clone()) .flex() @@ -141,17 +158,17 @@ impl Pane { } } -impl ParentElement for Pane { - fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { +impl ParentElement for Pane { + fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> { &mut self.children } } #[derive(Element)] -pub struct PaneGroup { - state_type: PhantomData, - groups: Vec>, - panes: Vec>, +pub struct PaneGroup { + state_type: PhantomData, + groups: Vec>, + panes: Vec>, split_direction: SplitDirection, } @@ -201,7 +218,7 @@ impl PaneGroup { .w_full() .h_full() .bg(theme.editor) - .children(self.groups.iter_mut().map(| group| group.render(view, cx))); + .children(self.groups.iter_mut().map(|group| group.render(view, cx))); if self.split_direction == SplitDirection::Horizontal { return el;