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
use crate::{Id, Rect};
/// Visual interaction state; pressing takes precedence over hovering.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum WidgetState {
Idle,
Hovered,
Pressed,
Disabled,
}
/// Widget geometry and interaction for the current UI pass.
#[derive(Clone, Copy, Debug)]
pub struct Response {
pub id: Id,
pub rect: Rect,
pub hovered: bool,
pub pressed: bool,
pub has_focus: bool,
/// Keyboard focus indication. Pointer focus alone does not show a ring.
pub focus_visible: bool,
pub enabled: bool,
pub(super) clicked: bool,
pub(super) changed: bool,
pub(super) submitted: bool,
pub(super) lost_focus: bool,
}
impl Response {
/// Enter confirmed the text during this pass; independent of value changes.
pub fn submitted(self) -> bool {
self.submitted
}
/// The widget lost focus during this pass, including focus changes between redraws.
pub fn lost_focus(self) -> bool {
self.lost_focus
}
pub fn state(self) -> WidgetState {
if !self.enabled {
WidgetState::Disabled
} else if self.pressed {
WidgetState::Pressed
} else if self.hovered {
WidgetState::Hovered
} else {
WidgetState::Idle
}
}
/// True on release inside the control, or on Enter/Space release when focused.
pub fn clicked(self) -> bool {
self.clicked
}
/// True when this widget changed its bound value during the current UI pass.
pub fn changed(self) -> bool {
self.changed
}
}