MCPcopy Create free account
hub / github.com/GCWing/BitFun / handle_mouse_event

Method handle_mouse_event

src/apps/cli/src/ui/command_menu.rs:170–209  ·  view source on GitHub ↗

Handle mouse events. Returns `Some(command_name)` when a command is clicked.

(&mut self, mouse: &MouseEvent)

Source from the content-addressed store, hash-verified

168
169 /// Handle mouse events. Returns `Some(command_name)` when a command is clicked.
170 pub fn handle_mouse_event(&mut self, mouse: &MouseEvent) -> Option<String> {
171 if !self.visible {
172 return None;
173 }
174
175 let area = match self.last_area {
176 Some(area) => area,
177 None => return None,
178 };
179
180 let in_menu = mouse.column >= area.x
181 && mouse.column < area.x.saturating_add(area.width)
182 && mouse.row >= area.y
183 && mouse.row < area.y.saturating_add(area.height);
184
185 match mouse.kind {
186 MouseEventKind::ScrollUp if in_menu => {
187 self.move_up();
188 None
189 }
190 MouseEventKind::ScrollDown if in_menu => {
191 self.move_down();
192 None
193 }
194 MouseEventKind::Moved if in_menu => {
195 if let Some(index) = self.item_index_at(mouse.column, mouse.row, area) {
196 self.list_state.select(Some(index));
197 }
198 None
199 }
200 MouseEventKind::Down(MouseButton::Left) if in_menu => {
201 if let Some(index) = self.item_index_at(mouse.column, mouse.row, area) {
202 self.list_state.select(Some(index));
203 return self.apply_selection();
204 }
205 None
206 }
207 _ => None,
208 }
209 }
210
211 /// Whether the menu captures this mouse event (prevents passthrough)
212 pub fn captures_mouse(&self, mouse: &MouseEvent) -> bool {

Callers

nothing calls this directly

Calls 5

apply_selectionMethod · 0.80
move_upMethod · 0.45
move_downMethod · 0.45
item_index_atMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected