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 {

View file

@ -28,14 +28,23 @@ impl Default for ToolGroup {
}
}
#[derive(Element)]
#[element(view_state = "Workspace")]
#[derive(IntoAnyElement)]
#[element(view_type = "Workspace")]
pub struct StatusBar {
left_tools: Option<ToolGroup>,
right_tools: Option<ToolGroup>,
bottom_tools: Option<ToolGroup>,
}
// impl IntoAnyElement<Workspace> for StatusBar {
// fn into_any(self) -> gpui2::AnyElement<Workspace> {
// (move |workspace: &mut Workspace, cx: &mut ViewContext<'_, '_, Workspace>| {
// self.render(workspace, cx)
// })
// .into_any()
// }
// }
impl StatusBar {
pub fn new() -> Self {
Self {
@ -83,7 +92,7 @@ impl StatusBar {
}
fn render(
&mut self,
self,
view: &mut Workspace,
cx: &mut ViewContext<Workspace>,
) -> impl IntoAnyElement<Workspace> {