1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Unified keyboard + mouse input for menus.
//!
//! `MenuEvent` wraps both [`KeyEvent`] and [`MouseEvent`] so a single
//! dispatch loop can drive a menu regardless of where events came from.
//! Use [`MenuEvent::dispatch`] (or the inherent [`Menu::dispatch`]
//! method) to send an event to any menu widget.
//!
//! [`KeyEvent`]: crate::ports::KeyEvent
//! [`MouseEvent`]: crate::ports::MouseEvent
use crateMenuAction;
use crate;
/// A menu input event — either a key press or a mouse event.
///
/// Construct via [`From<KeyEvent>`] or [`From<MouseEvent>`]. The
/// conversion is infallible and zero-cost.
/// Dispatch a [`MenuEvent`] to a menu widget built with a standard
/// `update(&mut self, KeyEvent) -> MenuAction` API.
///
/// This is a small convention rather than a formal trait. Each
/// menu widget implements a `dispatch(&mut self, event)` inherent
/// method that delegates mouse events to a hook (`on_mouse`). This
/// free function is provided for callers who'd rather not import
/// the inherent method — e.g., generic event loops.
///
/// ```rust,ignore
/// use cornichon::prelude::*;
///
/// let action = match event {
/// MouseOrKeyboard::Key(k) => menu.update(k),
/// MouseOrKeyboard::Mouse(m) => MenuDispatch::dispatch(&mut menu, m),
/// };
/// ```
/// Dispatch a unified event to a menu implementing [`MenuDispatch`].
///
/// Returns the same [`MenuAction`] the menu would have returned for
/// the corresponding keyboard-only event. Mouse events that the menu
/// doesn't recognize (the default for `on_mouse`) yield `MenuAction::None`.
Sized>