makepad_draw/
overlay.rs

1use {
2    /*std::{
3        rc::Rc,
4        cell::{RefCell},        
5    },*/
6    crate::{
7        makepad_platform::*,
8        cx_2d::Cx2d,
9    }
10};
11
12#[derive(Debug)]
13pub struct Overlay { // draw info per UI element
14    pub (crate) draw_list: DrawList,
15    //pub (crate) sweep_lock: Rc<RefCell<Area>>, 
16}
17
18impl LiveHook for Overlay {}
19impl LiveNew for Overlay {
20    fn live_design_with(_cx:&mut Cx){}
21    fn new(cx: &mut Cx) -> Self {
22        let draw_list = cx.draw_lists.alloc();
23        //cx.draw_lists[draw_list.id()].unclipped = true;
24        Self {
25            //sweep_lock: Rc::new(RefCell::new(Area::Empty)),
26            draw_list,
27        }
28    }
29    
30    fn live_type_info(_cx: &mut Cx) -> LiveTypeInfo {
31        LiveTypeInfo {
32            module_id: LiveModuleId::from_str(&module_path!()).unwrap(),
33            live_type: LiveType::of::<Self>(),
34            live_ignore: true,
35            fields: Vec::new(),
36            type_name: id_lut!(Overlay)
37        }
38    }
39}
40
41impl LiveApply for Overlay {
42    fn apply(&mut self, _cx: &mut Cx, _from: ApplyFrom, index: usize, nodes: &[LiveNode]) -> usize {
43        nodes.skip_node(index)
44    }
45}
46
47impl Overlay {
48    pub fn handle_event(&self, _cx:&Cx, _event:&Event){
49        /*let area = self.sweep_lock.borrow().clone();
50        if !area.is_empty(){
51            match event{
52                Event::MouseMove(e)=>e.sweep_lock.set(area),
53                Event::MouseDown(e)=>e.sweep_lock.set(area),
54                Event::Scroll(e)=>e.sweep_lock.set(area),
55                _=>()
56            }
57        }*/
58    }
59    
60    pub fn begin(&self, cx:&mut Cx2d){
61        // mark our overlay_id on cx
62        cx.overlay_id = Some(self.draw_list.id());
63       // cx.overlay_sweep_lock = Some(self.sweep_lock.clone());
64    }
65    
66    pub fn end(&self, cx:&mut Cx2d){
67        cx.overlay_id = None;
68        let parent_id = cx.draw_list_stack.last().cloned().unwrap();
69        let redraw_id = cx.redraw_id;
70        cx.draw_lists[parent_id].append_sub_list(redraw_id, self.draw_list.id());
71        
72        // flush out all overlays that have a different redraw id than their parent
73        // this means it didn't 
74        for i in 0..cx.draw_lists[self.draw_list.id()].draw_items.len(){
75            if let Some(sub_id) = cx.draw_lists[self.draw_list.id()].draw_items[i].sub_list(){
76                let cfp = cx.draw_lists[sub_id].codeflow_parent_id.unwrap();
77                if cx.draw_lists[cfp].redraw_id != cx.draw_lists[sub_id].redraw_id{
78                    
79                    cx.draw_lists[self.draw_list.id()].clear_sub_list(sub_id);
80                }
81            }
82        }
83    }
84}
85