MCPcopy Create free account
hub / github.com/Kethku/Pando / draw

Method draw

aspen/src/components/button.rs:70–121  ·  view source on GitHub ↗
(&self, cx: &mut DrawContext)

Source from the content-addressed store, hash-verified

68 }
69
70 fn draw(&self, cx: &mut DrawContext) {
71 let region = cx.region();
72 cx.mouse_region(region)
73 .on_hover({
74 let state = self.state.clone();
75 move |_cx| {
76 let mut state = state.borrow_mut();
77 if !state.hovered {
78 state.hovered = true;
79 state.hover_start = Instant::now();
80 }
81 }
82 })
83 .on_leave({
84 let state = self.state.clone();
85 move |_cx| {
86 let mut state = state.borrow_mut();
87 if state.hovered {
88 state.hovered = false;
89 state.hover_start = Instant::now();
90 }
91 }
92 })
93 .on_click({
94 let state = self.state.clone();
95 move |cx| {
96 let state = state.borrow();
97 (state.on_clicked)(cx);
98 }
99 });
100
101 let state = self.state.borrow();
102 if cx
103 .mouse_position()
104 .map_or(false, |pos| region.contains(pos))
105 {
106 cx.set_fill_brush(Brush::Solid(
107 self.idle_background
108 .mix(&self.hover_background, state.hover_t),
109 ));
110
111 cx.fill(&region);
112 } else {
113 cx.set_fill_brush(Brush::Solid(
114 self.hover_background
115 .mix(&self.idle_background, state.hover_t),
116 ));
117 cx.fill(&region);
118 }
119
120 (self.draw_contents)(cx);
121 }
122}

Callers

nothing calls this directly

Calls 9

regionMethod · 0.80
on_clickMethod · 0.80
on_leaveMethod · 0.80
on_hoverMethod · 0.80
mouse_regionMethod · 0.80
set_fill_brushMethod · 0.80
fillMethod · 0.80
mouse_positionMethod · 0.45
mixMethod · 0.45

Tested by

no test coverage detected