1use std::path::PathBuf;
2
3use crate::prelude::*;
4use crate::{v_stack, Breadcrumb, Buffer, Icon, IconButton, Symbol, Tab, TabBar, Toolbar};
5
6pub struct Editor<S: 'static + Send + Sync + Clone> {
7 pub tabs: Vec<Tab<S>>,
8 pub path: PathBuf,
9 pub symbols: Vec<Symbol>,
10 pub buffer: Buffer<S>,
11}
12
13#[derive(Element)]
14pub struct EditorPane<S: 'static + Send + Sync + Clone> {
15 editor: Editor<S>,
16}
17
18impl<S: 'static + Send + Sync + Clone> EditorPane<S> {
19 pub fn new(editor: Editor<S>) -> Self {
20 Self { editor }
21 }
22
23 fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
24 struct LeftItemsPayload {
25 path: PathBuf,
26 symbols: Vec<Symbol>,
27 }
28
29 v_stack()
30 .w_full()
31 .h_full()
32 .flex_1()
33 .child(TabBar::new(self.editor.tabs.clone()))
34 .child(Toolbar::new(
35 |_, payload| {
36 let payload = payload.downcast_ref::<LeftItemsPayload>().unwrap();
37
38 vec![Breadcrumb::new(payload.path.clone(), payload.symbols.clone()).into_any()]
39 },
40 Box::new(LeftItemsPayload {
41 path: self.editor.path.clone(),
42 symbols: self.editor.symbols.clone(),
43 }),
44 |_, _| {
45 vec![
46 IconButton::new(Icon::InlayHint).into_any(),
47 IconButton::new(Icon::MagnifyingGlass).into_any(),
48 IconButton::new(Icon::MagicWand).into_any(),
49 ]
50 },
51 Box::new(()),
52 ))
53 .child(self.editor.buffer.clone())
54 }
55}