diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rs index af7dff8390..c4eba3fb65 100644 --- a/crates/ui2/src/components.rs +++ b/crates/ui2/src/components.rs @@ -1,6 +1,7 @@ mod assistant_panel; mod breadcrumb; mod buffer; +mod editor_pane; mod icon_button; mod list; mod panel; @@ -16,6 +17,7 @@ mod workspace; pub use assistant_panel::*; pub use breadcrumb::*; pub use buffer::*; +pub use editor_pane::*; pub use icon_button::*; pub use list::*; pub use panel::*; diff --git a/crates/ui2/src/components/editor_pane.rs b/crates/ui2/src/components/editor_pane.rs new file mode 100644 index 0000000000..4460a6f7cd --- /dev/null +++ b/crates/ui2/src/components/editor_pane.rs @@ -0,0 +1,55 @@ +use std::path::PathBuf; + +use crate::prelude::*; +use crate::{v_stack, Breadcrumb, Buffer, Icon, IconButton, Symbol, Tab, TabBar, Toolbar}; + +pub struct Editor { + pub tabs: Vec>, + pub path: PathBuf, + pub symbols: Vec, + pub buffer: Buffer, +} + +#[derive(Element)] +pub struct EditorPane { + editor: Editor, +} + +impl EditorPane { + pub fn new(editor: Editor) -> Self { + Self { editor } + } + + fn render(&mut self, cx: &mut ViewContext) -> impl Element { + struct LeftItemsPayload { + path: PathBuf, + symbols: Vec, + } + + v_stack() + .w_full() + .h_full() + .flex_1() + .child(TabBar::new(self.editor.tabs.clone())) + .child(Toolbar::new( + |_, payload| { + let payload = payload.downcast_ref::().unwrap(); + + vec![Breadcrumb::new(payload.path.clone(), payload.symbols.clone()).into_any()] + }, + Box::new(LeftItemsPayload { + path: self.editor.path.clone(), + symbols: self.editor.symbols.clone(), + }), + |_, _| { + vec![ + IconButton::new(Icon::InlayHint).into_any(), + IconButton::new(Icon::MagnifyingGlass).into_any(), + IconButton::new(Icon::MagicWand).into_any(), + ] + }, + Box::new(()), + )) + .child(self.editor.buffer.clone()) + } +} diff --git a/crates/ui2/src/components/workspace.rs b/crates/ui2/src/components/workspace.rs index 758d6002c1..abeb3fc1aa 100644 --- a/crates/ui2/src/components/workspace.rs +++ b/crates/ui2/src/components/workspace.rs @@ -6,8 +6,8 @@ use gpui3::{relative, rems, Size}; use crate::prelude::*; use crate::{ - theme, v_stack, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel, - SplitDirection, StatusBar, Terminal, + hello_world_rust_editor_with_status_example, theme, v_stack, EditorPane, Pane, PaneGroup, + Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal, }; #[derive(Element)] @@ -48,12 +48,10 @@ impl WorkspaceElement { |_, payload| { let theme = payload.downcast_ref::>().unwrap(); - vec![ - Terminal::new().into_any(), // EditorPane::new(hello_world_rust_editor_with_status_example( - // &theme, - // )) - // .into_any() - ] + vec![EditorPane::new(hello_world_rust_editor_with_status_example( + &theme, + )) + .into_any()] }, Box::new(theme.clone()), ), @@ -79,13 +77,10 @@ impl WorkspaceElement { |_, payload| { let theme = payload.downcast_ref::>().unwrap(); - vec![ - Terminal::new().into_any(), - // EditorPane::new(hello_world_rust_editor_with_status_example( - // &theme, - // )) - // .into_any() - ] + vec![EditorPane::new(hello_world_rust_editor_with_status_example( + &theme, + )) + .into_any()] }, Box::new(theme.clone()), )], diff --git a/crates/ui2/src/static_data.rs b/crates/ui2/src/static_data.rs index 409fce768f..0ce67b8a76 100644 --- a/crates/ui2/src/static_data.rs +++ b/crates/ui2/src/static_data.rs @@ -1,8 +1,105 @@ +use std::path::PathBuf; +use std::str::FromStr; + use crate::{ - Buffer, BufferRow, BufferRows, GitStatus, HighlightColor, HighlightedLine, HighlightedText, - Icon, Label, LabelColor, ListEntry, ListItem, Theme, ToggleState, + Buffer, BufferRow, BufferRows, Editor, FileSystemStatus, GitStatus, HighlightColor, + HighlightedLine, HighlightedText, Icon, Label, LabelColor, ListEntry, ListItem, Symbol, Tab, + Theme, ToggleState, }; +pub fn static_tabs_example() -> Vec> { + vec![ + Tab::new() + .title("wip.rs".to_string()) + .icon(Icon::FileRust) + .current(false) + .fs_status(FileSystemStatus::Deleted), + Tab::new() + .title("Cargo.toml".to_string()) + .icon(Icon::FileToml) + .current(false) + .git_status(GitStatus::Modified), + Tab::new() + .title("Channels Panel".to_string()) + .icon(Icon::Hash) + .current(false), + Tab::new() + .title("channels_panel.rs".to_string()) + .icon(Icon::FileRust) + .current(true) + .git_status(GitStatus::Modified), + Tab::new() + .title("workspace.rs".to_string()) + .current(false) + .icon(Icon::FileRust) + .git_status(GitStatus::Modified), + Tab::new() + .title("icon_button.rs".to_string()) + .icon(Icon::FileRust) + .current(false), + Tab::new() + .title("storybook.rs".to_string()) + .icon(Icon::FileRust) + .current(false) + .git_status(GitStatus::Created), + Tab::new() + .title("theme.rs".to_string()) + .icon(Icon::FileRust) + .current(false), + Tab::new() + .title("theme_registry.rs".to_string()) + .icon(Icon::FileRust) + .current(false), + Tab::new() + .title("styleable_helpers.rs".to_string()) + .icon(Icon::FileRust) + .current(false), + ] +} + +pub fn static_tabs_1() -> Vec> { + vec![ + Tab::new() + .title("project_panel.rs".to_string()) + .icon(Icon::FileRust) + .current(false) + .fs_status(FileSystemStatus::Deleted), + Tab::new() + .title("tab_bar.rs".to_string()) + .icon(Icon::FileRust) + .current(false) + .git_status(GitStatus::Modified), + Tab::new() + .title("workspace.rs".to_string()) + .icon(Icon::FileRust) + .current(false), + Tab::new() + .title("tab.rs".to_string()) + .icon(Icon::FileRust) + .current(true) + .git_status(GitStatus::Modified), + ] +} + +pub fn static_tabs_2() -> Vec> { + vec![ + Tab::new() + .title("tab_bar.rs".to_string()) + .icon(Icon::FileRust) + .current(false) + .fs_status(FileSystemStatus::Deleted), + Tab::new() + .title("static_data.rs".to_string()) + .icon(Icon::FileRust) + .current(true) + .git_status(GitStatus::Modified), + ] +} + +pub fn static_tabs_3() -> Vec> { + vec![Tab::new().git_status(GitStatus::Created).current(true)] +} + pub fn static_project_panel_project_items() -> Vec> { vec![ ListEntry::new(Label::new("zed")) @@ -147,10 +244,39 @@ pub fn static_project_panel_single_items() -> .collect() } +pub fn empty_editor_example() -> Editor { + Editor { + tabs: static_tabs_example(), + path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + symbols: vec![], + buffer: empty_buffer_example(), + } +} + pub fn empty_buffer_example() -> Buffer { Buffer::new().set_rows(Some(BufferRows::default())) } +pub fn hello_world_rust_editor_example( + theme: &Theme, +) -> Editor { + Editor { + tabs: static_tabs_example(), + path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + symbols: vec![Symbol(vec![ + HighlightedText { + text: "fn ".to_string(), + color: HighlightColor::Keyword.hsla(&theme), + }, + HighlightedText { + text: "main".to_string(), + color: HighlightColor::Function.hsla(&theme), + }, + ])], + buffer: hello_world_rust_buffer_example(theme), + } +} + pub fn hello_world_rust_buffer_example( theme: &Theme, ) -> Buffer { @@ -271,6 +397,26 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec { ] } +pub fn hello_world_rust_editor_with_status_example( + theme: &Theme, +) -> Editor { + Editor { + tabs: static_tabs_example(), + path: PathBuf::from_str("crates/ui/src/static_data.rs").unwrap(), + symbols: vec![Symbol(vec![ + HighlightedText { + text: "fn ".to_string(), + color: HighlightColor::Keyword.hsla(&theme), + }, + HighlightedText { + text: "main".to_string(), + color: HighlightColor::Function.hsla(&theme), + }, + ])], + buffer: hello_world_rust_buffer_with_status_example(theme), + } +} + pub fn hello_world_rust_buffer_with_status_example( theme: &Theme, ) -> Buffer {