editor_pane.rs

 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, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
24        v_stack()
25            .w_full()
26            .h_full()
27            .flex_1()
28            .child(TabBar::new(self.editor.tabs.clone()))
29            .child(
30                Toolbar::new()
31                    .left_item(Breadcrumb::new(
32                        self.editor.path.clone(),
33                        self.editor.symbols.clone(),
34                    ))
35                    .right_items(vec![
36                        IconButton::new(Icon::InlayHint).into_any(),
37                        IconButton::new(Icon::MagnifyingGlass).into_any(),
38                        IconButton::new(Icon::MagicWand).into_any(),
39                    ]),
40            )
41            .child(self.editor.buffer.clone())
42    }
43}