1use {
2 crate::{
7 makepad_platform::*,
8 cx_2d::Cx2d,
9 }
10};
11
12#[derive(Debug)]
13pub struct Overlay { pub (crate) draw_list: DrawList,
15 }
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 Self {
25 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 }
59
60 pub fn begin(&self, cx:&mut Cx2d){
61 cx.overlay_id = Some(self.draw_list.id());
63 }
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 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