makepad_studio/
studio_file_tree.rs

1
2use {
3    crate::{
4        app::{AppData},
5        makepad_widgets::*,
6        makepad_widgets::file_tree::FileTree,
7    },
8};
9
10live_design!{
11    use link::widgets::*;
12        
13    pub StudioFileTree = {{StudioFileTree}}{
14        file_tree: <FileTree>{}
15    }
16}
17 
18#[derive(Live, Widget)] 
19pub struct StudioFileTree{
20    #[wrap] #[live] pub file_tree: FileTree
21}
22impl LiveHook for StudioFileTree{
23    fn after_new_from_doc(&mut self, cx:&mut Cx){
24        self.file_tree.set_folder_is_open(cx, live_id!(makepad).into(), true, Animate::No);
25    }
26}
27
28impl Widget for StudioFileTree {
29    fn draw_walk(&mut self, cx: &mut Cx2d, scope:&mut Scope, walk:Walk)->DrawStep{
30        while self.file_tree.draw_walk(cx, scope, walk).is_step() {
31            scope.data.get_mut::<AppData>().unwrap().file_system.draw_file_node(
32                cx,
33                live_id!(root).into(),
34                0,
35                &mut self.file_tree
36            );
37        }
38        DrawStep::done()
39    }
40    
41    fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope){
42        self.file_tree.handle_event(cx, event, scope);
43    }
44}
45
46impl StudioFileTreeRef{
47    pub fn set_folder_is_open(
48        &self,
49        cx: &mut Cx,
50        node_id: LiveId,
51        is_open: bool,
52        animate: Animate,
53    ) {
54        if let Some(mut inner) = self.borrow_mut(){
55            inner.file_tree.set_folder_is_open(cx, node_id, is_open, animate);
56        }
57    }
58}