1use {
2 std::{
3 ops::Deref,
4 ops::DerefMut,
5 },
6 crate::{
7 cx_draw::CxDraw,
8 makepad_math::{DVec2,Vec2Index},
9 makepad_platform::{
10 DrawListId,
11 },
12 draw_list_2d::DrawList2d,
13 turtle::{Turtle, TurtleWalk, Walk, AlignEntry},
14 },
15};
16
17pub struct Cx2d<'a, 'b> {
18 pub cx: &'b mut CxDraw<'a>,
19 pub (crate) overlay_id: Option<DrawListId>,
20
21 pub (crate) turtles: Vec<Turtle>,
23 pub (crate) turtle_walks: Vec<TurtleWalk>,
24 pub (crate) turtle_clips: Vec<(DVec2, DVec2)>,
25 pub (crate) align_list: Vec<AlignEntry>,
26}
27
28impl<'a, 'b> Deref for Cx2d<'a,'b> {type Target = CxDraw<'a>; fn deref(&self) -> &Self::Target {self.cx}}
29impl<'a, 'b> DerefMut for Cx2d<'a,'b> {fn deref_mut(&mut self) -> &mut Self::Target {self.cx}}
30
31impl<'a, 'b> Cx2d<'a, 'b> {
32 pub fn new(cx: &'b mut CxDraw<'a>)->Self{
33 Self {
34 overlay_id: None,
35 cx: cx,
36 turtle_clips: Vec::with_capacity(1024),
37 turtle_walks: Vec::with_capacity(1024),
38 turtles: Vec::with_capacity(64),
39 align_list: Vec::with_capacity(4096),
40 }
41 }
42
43 pub fn will_redraw(&self, draw_list_2d: &mut DrawList2d, walk: Walk) -> bool {
44 let rect = self.peek_walk_turtle(walk);
47 if draw_list_2d.dirty_check_rect != rect {
48 draw_list_2d.dirty_check_rect = rect;
49 return true;
50 }
51 self.draw_event.draw_list_will_redraw(self, draw_list_2d.draw_list.id())
52 }
53
54 pub fn will_redraw_check_axis(&self, draw_list_2d: &mut DrawList2d, size:f64, axis:Vec2Index) -> bool {
55 if draw_list_2d.dirty_check_rect.size.index(axis) != size {
58 draw_list_2d.dirty_check_rect.size.set_index(axis, size);
59 return true;
60 }
61 self.draw_event.draw_list_will_redraw(self, draw_list_2d.draw_list.id())
62 }
63}