(&self, cx: &mut DrawContext)
| 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(®ion); |
| 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(®ion); |
| 118 | } |
| 119 | |
| 120 | (self.draw_contents)(cx); |
| 121 | } |
| 122 | } |
nothing calls this directly
no test coverage detected