Detailed changes
@@ -1,5 +1,4 @@
-use super::{Handle, Layout, LayoutId, Pixels, Point, ViewContext, WindowContext};
-use anyhow::Result;
+use super::{Handle, Layout, LayoutId, Pixels, Point, Result, ViewContext, WindowContext};
use std::{any::Any, cell::RefCell, marker::PhantomData, rc::Rc};
pub trait Element: 'static {
@@ -1,40 +1,8 @@
-use std::marker::PhantomData;
-
-use anyhow::Result;
-
-use super::{Element, IntoAnyElement, Layout, LayoutId, ParentElement, ViewContext};
-
-pub struct Div<S>(PhantomData<S>);
+pub mod div;
+pub mod editor;
-impl<S: 'static> Element for Div<S> {
- type State = S;
- type FrameState = ();
-
- fn layout(
- &mut self,
- state: &mut Self::State,
- cx: &mut ViewContext<Self::State>,
- ) -> Result<(LayoutId, Self::FrameState)> {
- todo!()
- }
-
- fn paint(
- &mut self,
- layout: Layout,
- state: &mut Self::State,
- frame_state: &mut Self::FrameState,
- cx: &mut ViewContext<Self::State>,
- ) -> Result<()> {
- todo!()
- }
-}
-
-impl<S> ParentElement<S> for Div<S> {
- fn child(self, child: impl IntoAnyElement<S>) -> Self {
- todo!()
- }
-}
+use super::*;
+use std::marker::PhantomData;
-pub fn div<S>() -> Div<S> {
- todo!()
-}
+pub use div::div;
+pub use editor::field;
@@ -0,0 +1,38 @@
+use super::{
+ Element, IntoAnyElement, Layout, LayoutId, ParentElement, PhantomData, Result, ViewContext,
+};
+
+pub struct Div<S>(PhantomData<S>);
+
+impl<S: 'static> Element for Div<S> {
+ type State = S;
+ type FrameState = ();
+
+ fn layout(
+ &mut self,
+ state: &mut Self::State,
+ cx: &mut ViewContext<Self::State>,
+ ) -> Result<(LayoutId, Self::FrameState)> {
+ todo!()
+ }
+
+ fn paint(
+ &mut self,
+ layout: Layout,
+ state: &mut Self::State,
+ frame_state: &mut Self::FrameState,
+ cx: &mut ViewContext<Self::State>,
+ ) -> Result<()> {
+ todo!()
+ }
+}
+
+impl<S> ParentElement<S> for Div<S> {
+ fn child(self, child: impl IntoAnyElement<S>) -> Self {
+ todo!()
+ }
+}
+
+pub fn div<S>() -> Div<S> {
+ todo!()
+}
@@ -0,0 +1,61 @@
+use super::{Element, Handle, Layout, LayoutId, Result, SharedString, ViewContext};
+use std::marker::PhantomData;
+
+pub fn field<S>(editor: Handle<Editor>) -> EditorElement<S> {
+ EditorElement {
+ editor,
+ field: true,
+ placeholder_text: None,
+ parent_state: PhantomData,
+ }
+}
+
+pub struct EditorElement<S> {
+ editor: Handle<Editor>,
+ field: bool,
+ placeholder_text: Option<SharedString>,
+ parent_state: PhantomData<S>,
+}
+
+impl<S> EditorElement<S> {
+ pub fn field(mut self) -> Self {
+ self.field = true;
+ self
+ }
+
+ pub fn placeholder_text(mut self, text: impl Into<SharedString>) -> Self {
+ self.placeholder_text = Some(text.into());
+ self
+ }
+}
+
+impl<S: 'static> Element for EditorElement<S> {
+ type State = S;
+ type FrameState = ();
+
+ fn layout(
+ &mut self,
+ _: &mut Self::State,
+ cx: &mut ViewContext<Self::State>,
+ ) -> Result<(LayoutId, Self::FrameState)> {
+ self.editor.update(cx, |editor, cx| todo!())
+ }
+
+ fn paint(
+ &mut self,
+ layout: Layout,
+ state: &mut Self::State,
+ frame_state: &mut Self::FrameState,
+ cx: &mut ViewContext<Self::State>,
+ ) -> Result<()> {
+ self.editor.update(cx, |editor, cx| todo!())
+ }
+}
+
+pub struct Editor {}
+
+impl Editor {
+ pub fn new(_: &mut ViewContext<Self>) -> Self {
+ Editor {}
+ }
+}
@@ -9,7 +9,6 @@ mod window;
use anyhow::Result;
pub use gpui2::ArcCow;
use gpui2::Reference;
-use std::marker::PhantomData;
pub use app::*;
pub use element::*;
@@ -19,6 +18,8 @@ pub use style::*;
use taffy::TaffyLayoutEngine;
pub use window::*;
+use self::editor::Editor;
+
pub trait Context {
type EntityContext<'a, 'w, T: 'static>;
@@ -56,7 +57,7 @@ fn workspace(cx: &mut WindowContext) -> View<Workspace> {
}
struct CollabPanel {
- filter_editor: Handle<Editor>,
+ filter_editor: Handle<editor::Editor>,
}
fn collab_panel(cx: &mut WindowContext) -> View<CollabPanel> {
@@ -76,65 +77,6 @@ impl CollabPanel {
}
}
-fn field<S>(editor: Handle<Editor>) -> EditorElement<S> {
- EditorElement {
- editor,
- field: true,
- placeholder_text: None,
- parent_state: PhantomData,
- }
-}
-
-struct EditorElement<S> {
- editor: Handle<Editor>,
- field: bool,
- placeholder_text: Option<SharedString>,
- parent_state: PhantomData<S>,
-}
-
-impl<S> EditorElement<S> {
- pub fn field(mut self) -> Self {
- self.field = true;
- self
- }
-
- pub fn placeholder_text(mut self, text: impl Into<SharedString>) -> Self {
- self.placeholder_text = Some(text.into());
- self
- }
-}
-
-impl<S: 'static> Element for EditorElement<S> {
- type State = S;
- type FrameState = ();
-
- fn layout(
- &mut self,
- _: &mut Self::State,
- cx: &mut ViewContext<Self::State>,
- ) -> Result<(LayoutId, Self::FrameState)> {
- self.editor.update(cx, |editor, cx| todo!())
- }
-
- fn paint(
- &mut self,
- layout: Layout,
- state: &mut Self::State,
- frame_state: &mut Self::FrameState,
- cx: &mut ViewContext<Self::State>,
- ) -> Result<()> {
- self.editor.update(cx, |editor, cx| todo!())
- }
-}
-
-struct Editor {}
-
-impl Editor {
- pub fn new(_: &mut ViewContext<Self>) -> Self {
- Editor {}
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
@@ -1,8 +1,7 @@
use super::{
AbsoluteLength, Bounds, DefiniteLength, Edges, Layout, LayoutEngine, LayoutId, Length, Pixels,
- Point, Size, Style,
+ Point, Result, Size, Style,
};
-use anyhow::Result;
use gpui2::taffy::{self, Taffy};
use std::fmt::Debug;