Add EditorPane
component and wire up in the workspace
This commit is contained in:
parent
63e834ce73
commit
ff066ef177
4 changed files with 215 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
mod assistant_panel;
|
mod assistant_panel;
|
||||||
mod breadcrumb;
|
mod breadcrumb;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
|
mod editor_pane;
|
||||||
mod icon_button;
|
mod icon_button;
|
||||||
mod list;
|
mod list;
|
||||||
mod panel;
|
mod panel;
|
||||||
|
@ -16,6 +17,7 @@ mod workspace;
|
||||||
pub use assistant_panel::*;
|
pub use assistant_panel::*;
|
||||||
pub use breadcrumb::*;
|
pub use breadcrumb::*;
|
||||||
pub use buffer::*;
|
pub use buffer::*;
|
||||||
|
pub use editor_pane::*;
|
||||||
pub use icon_button::*;
|
pub use icon_button::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
pub use panel::*;
|
pub use panel::*;
|
||||||
|
|
55
crates/ui2/src/components/editor_pane.rs
Normal file
55
crates/ui2/src/components/editor_pane.rs
Normal file
|
@ -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<S: 'static + Send + Sync + Clone> {
|
||||||
|
pub tabs: Vec<Tab<S>>,
|
||||||
|
pub path: PathBuf,
|
||||||
|
pub symbols: Vec<Symbol>,
|
||||||
|
pub buffer: Buffer<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Element)]
|
||||||
|
pub struct EditorPane<S: 'static + Send + Sync + Clone> {
|
||||||
|
editor: Editor<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync + Clone> EditorPane<S> {
|
||||||
|
pub fn new(editor: Editor<S>) -> Self {
|
||||||
|
Self { editor }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||||
|
struct LeftItemsPayload {
|
||||||
|
path: PathBuf,
|
||||||
|
symbols: Vec<Symbol>,
|
||||||
|
}
|
||||||
|
|
||||||
|
v_stack()
|
||||||
|
.w_full()
|
||||||
|
.h_full()
|
||||||
|
.flex_1()
|
||||||
|
.child(TabBar::new(self.editor.tabs.clone()))
|
||||||
|
.child(Toolbar::new(
|
||||||
|
|_, payload| {
|
||||||
|
let payload = payload.downcast_ref::<LeftItemsPayload>().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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,8 +6,8 @@ use gpui3::{relative, rems, Size};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
theme, v_stack, Pane, PaneGroup, Panel, PanelAllowedSides, PanelSide, ProjectPanel,
|
hello_world_rust_editor_with_status_example, theme, v_stack, EditorPane, Pane, PaneGroup,
|
||||||
SplitDirection, StatusBar, Terminal,
|
Panel, PanelAllowedSides, PanelSide, ProjectPanel, SplitDirection, StatusBar, Terminal,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Element)]
|
#[derive(Element)]
|
||||||
|
@ -48,12 +48,10 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
|
||||||
|_, payload| {
|
|_, payload| {
|
||||||
let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
|
let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
|
||||||
|
|
||||||
vec![
|
vec![EditorPane::new(hello_world_rust_editor_with_status_example(
|
||||||
Terminal::new().into_any(), // EditorPane::new(hello_world_rust_editor_with_status_example(
|
&theme,
|
||||||
// &theme,
|
))
|
||||||
// ))
|
.into_any()]
|
||||||
// .into_any()
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
Box::new(theme.clone()),
|
Box::new(theme.clone()),
|
||||||
),
|
),
|
||||||
|
@ -79,13 +77,10 @@ impl<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
|
||||||
|_, payload| {
|
|_, payload| {
|
||||||
let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
|
let theme = payload.downcast_ref::<Arc<Theme>>().unwrap();
|
||||||
|
|
||||||
vec![
|
vec![EditorPane::new(hello_world_rust_editor_with_status_example(
|
||||||
Terminal::new().into_any(),
|
&theme,
|
||||||
// EditorPane::new(hello_world_rust_editor_with_status_example(
|
))
|
||||||
// &theme,
|
.into_any()]
|
||||||
// ))
|
|
||||||
// .into_any()
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
Box::new(theme.clone()),
|
Box::new(theme.clone()),
|
||||||
)],
|
)],
|
||||||
|
|
|
@ -1,8 +1,105 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Buffer, BufferRow, BufferRows, GitStatus, HighlightColor, HighlightedLine, HighlightedText,
|
Buffer, BufferRow, BufferRows, Editor, FileSystemStatus, GitStatus, HighlightColor,
|
||||||
Icon, Label, LabelColor, ListEntry, ListItem, Theme, ToggleState,
|
HighlightedLine, HighlightedText, Icon, Label, LabelColor, ListEntry, ListItem, Symbol, Tab,
|
||||||
|
Theme, ToggleState,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub fn static_tabs_example<S: 'static + Send + Sync + Clone>() -> Vec<Tab<S>> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>() -> Vec<Tab<S>> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>() -> Vec<Tab<S>> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>() -> Vec<Tab<S>> {
|
||||||
|
vec![Tab::new().git_status(GitStatus::Created).current(true)]
|
||||||
|
}
|
||||||
|
|
||||||
pub fn static_project_panel_project_items<S: 'static + Send + Sync + Clone>() -> Vec<ListItem<S>> {
|
pub fn static_project_panel_project_items<S: 'static + Send + Sync + Clone>() -> Vec<ListItem<S>> {
|
||||||
vec![
|
vec![
|
||||||
ListEntry::new(Label::new("zed"))
|
ListEntry::new(Label::new("zed"))
|
||||||
|
@ -147,10 +244,39 @@ pub fn static_project_panel_single_items<S: 'static + Send + Sync + Clone>() ->
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn empty_editor_example<S: 'static + Send + Sync + Clone>() -> Editor<S> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>() -> Buffer<S> {
|
pub fn empty_buffer_example<S: 'static + Send + Sync + Clone>() -> Buffer<S> {
|
||||||
Buffer::new().set_rows(Some(BufferRows::default()))
|
Buffer::new().set_rows(Some(BufferRows::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hello_world_rust_editor_example<S: 'static + Send + Sync + Clone>(
|
||||||
|
theme: &Theme,
|
||||||
|
) -> Editor<S> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_buffer_example<S: 'static + Send + Sync + Clone>(
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) -> Buffer<S> {
|
) -> Buffer<S> {
|
||||||
|
@ -271,6 +397,26 @@ pub fn hello_world_rust_buffer_rows(theme: &Theme) -> Vec<BufferRow> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hello_world_rust_editor_with_status_example<S: 'static + Send + Sync + Clone>(
|
||||||
|
theme: &Theme,
|
||||||
|
) -> Editor<S> {
|
||||||
|
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<S: 'static + Send + Sync + Clone>(
|
pub fn hello_world_rust_buffer_with_status_example<S: 'static + Send + Sync + Clone>(
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) -> Buffer<S> {
|
) -> Buffer<S> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue