Add EditorPane component and wire up in the workspace
This commit is contained in:
@@ -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::{
|
||||
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<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
|
||||
|_, payload| {
|
||||
let theme = payload.downcast_ref::<Arc<Theme>>().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<S: 'static + Send + Sync + Clone> WorkspaceElement<S> {
|
||||
|_, payload| {
|
||||
let theme = payload.downcast_ref::<Arc<Theme>>().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()),
|
||||
)],
|
||||
|
||||
Reference in New Issue
Block a user