makepad_widgets/
designer_outline.rs1use crate::{
2 makepad_derive_widget::*,
3 makepad_draw::*,
4 designer_outline_tree::*,
5 designer_data::*,
6 view::View,
7 widget::*,
8};
9use std::collections::HashMap;
10
11live_design!{
12 pub DesignerOutlineBase = {{DesignerOutline}}{}
13 pub DesignerOutline = <DesignerOutlineBase>{ }
14}
15
16#[derive(Live, Widget, LiveHook)]
17pub struct DesignerOutline {
18 #[deref] view: View
19}
20
21impl Widget for DesignerOutline {
22 fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope){
23 self.view.handle_event(cx, event, scope);
24 }
25
26 fn draw_walk(&mut self, cx: &mut Cx2d, scope:&mut Scope, _walk: Walk) -> DrawStep {
27 let file_tree = self.view.designer_outline_tree(id!(outline_tree));
28 let data =if let Some(data) = scope.data.get::<DesignerData>(){
29 data
30 }
31 else{
32 return DrawStep::done()
33 };
34
35 while let Some(next) = self.view.draw(cx, &mut Scope::empty()).step() {
36 if let Some(mut file_tree) = file_tree.borrow_mut_if_eq(&next) {
37 if let OutlineNode::Virtual{children,..} = &data.node_map.get(&data.root).as_ref().unwrap(){
38 recur_nodes(cx, &mut *file_tree, &data.node_map, children);
39 }
40 }
41 }
42
43 fn recur_nodes(cx: &mut Cx2d, outline_tree: &mut DesignerOutlineTree,map:&HashMap<LiveId,OutlineNode>, children:&[LiveId]) {
44 for child in children{
45 match map.get(&child).unwrap(){
46 OutlineNode::Folder{name, children}=> {
47 if outline_tree.begin_node(cx, *child, &name, live_id!(Folder)).is_ok(){
48 recur_nodes(cx, outline_tree, map, children);
49 outline_tree.end_node();
50 }
51 }
52 OutlineNode::File{name, file_id:_, children}=>{
53 if children.len() > 0{
54 if outline_tree.begin_node(cx, *child, &name, live_id!(File)).is_ok(){
55 recur_nodes(cx, outline_tree, map, children);
56 outline_tree.end_node();
57 }
58 }
59 }
60 OutlineNode::Virtual{name, children}=>{
61 if outline_tree.begin_node(cx, *child, &name, live_id!(Folder)).is_ok(){
62 recur_nodes(cx, outline_tree, map, children);
63 outline_tree.end_node();
64 }
65 }
66 OutlineNode::Component{children, name, ..}=>{
67
68 if children.len() > 0{
69 if outline_tree.begin_node(cx, *child, &name, live_id!(Layout)).is_ok() {
70 recur_nodes(cx, outline_tree, map, children);
71 outline_tree.end_node();
72 }
73 }
74 else{
75 outline_tree.node(cx, *child, name, live_id!(Widget))
76 }
77 }
78 }
79 }
80 }
81 DrawStep::done()
82 }
83}