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
use super::*;
pub trait AsHandlerStateful<E>: Context<E> + Sized where E: Env<Context=Self> {
type T: HandlerStateful<E>;
fn stateful_mut(&mut self) -> &mut Self::T;
fn stateful(&self) -> &Self::T;
}
pub trait HandlerStateful<E>: Handler<E> + 'static where E: Env {
type K: PressedKey<E>;
fn hovered(&self) -> Option<E::WidgetID>;
fn selected(&self) -> Option<E::WidgetID>;
#[inline]
fn is_hovered(&self, i: &E::WidgetID) -> bool {
self.hovered().map_or(false, |w| w == *i )
}
#[inline]
fn is_focused(&self, i: &E::WidgetID) -> bool {
self.selected().map_or(false, |w| w == *i )
}
fn pressed(&self) -> &[Self::K];
#[inline]
fn is_pressed<'a>(&'a self, c: &[EEKey<E>]) -> Option<&'a Self::K> {
self.pressed().iter()
.find(|p| p.key() == c[0] )
}
#[inline]
fn is_pressed_and_id<'a>(&'a self, c: &[EEKey<E>], id: E::WidgetID) -> Option<&'a Self::K> {
self.pressed().iter()
.find(|p| p.key() == c[0] && p.widget() == id )
}
}