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