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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use super::*;
impl<'w,E,S> Widget<'w,E> for Button<'w,E,S> where
E: Env,
ERenderer<E>: RenderStdWidgets<E>,
EEvent<E>: StdVarSup<E>,
ESVariant<E>: StyleVariantSupport<StdVerb>,
E::Context: AsHandlerStateful<E>,
S: Caption<'w>+Statize,
S::Statur: Sized,
{
fn child_paths(&self, _: E::WidgetPath) -> Vec<E::WidgetPath> {
vec![]
}
fn style(&self, s: &mut ESVariant<E>) {
s.attach(&[StdVerb::ObjButton]);
s.attach(&self.style[..]);
}
fn border(&self, b: &mut Border) {
if let Some(senf) = &self.border {
*b = *senf;
}
}
fn id(&self) -> E::WidgetID {
self.id.clone()
}
fn render(&self, l: Link<E>, r: &mut RenderLink<E>) -> bool {
r.with(&[
StdVerb::ObjForeground,
StdVerb::Hovered(l.is_hovered()),
StdVerb::Focused(l.is_focused()),
StdVerb::Locked(self.locked),
StdVerb::Pressed(Self::pressed(&l).is_some())
])
.fill_rect();
r.with(&[
StdVerb::ObjBorder,
StdVerb::Hovered(l.is_hovered()),
StdVerb::Focused(l.is_focused()),
StdVerb::Locked(self.locked),
StdVerb::Pressed(Self::pressed(&l).is_some())
])
.border_rect(2);
r.with(&[
StdVerb::ObjForeground,
StdVerb::ObjText,
StdVerb::Hovered(l.is_hovered()),
StdVerb::Focused(l.is_focused()),
StdVerb::Locked(self.locked),
StdVerb::Pressed(Self::pressed(&l).is_some())
])
.render_text(self.text.caption().as_ref(),l.ctx);
true
}
fn event(&self, mut l: Link<E>, e: (EEvent<E>,&Bounds,u64)) {
if e.0.is_hover_update() || e.0.is_kbd_down().is_some() || e.0.is_kbd_up().is_some() {
l.enqueue_invalidate()
}
if let Some(ee) = e.0.is_mouse_up() {
if ee.key == EEKey::<E>::MOUSE_LEFT && ee.down_widget.tip().eq_id(self.id()) && l.is_hovered() && !self.locked {
(self.trigger)(l)
}
} else if let Some(ee) = e.0.is_kbd_press() {
if (ee.key == EEKey::<E>::ENTER || ee.key == EEKey::<E>::SPACE) && ee.down_widget.tip().eq_id(self.id()) {
(self.trigger)(l)
}
}
}
fn size(&self, _: Link<E>) -> ESize<E> {
self.size.clone()
}
fn childs(&self) -> usize {
0
}
fn childs_ref<'s>(&'s self) -> Vec<Resolvable<'s,E>> where 'w: 's {
vec![]
}
fn into_childs(self: Box<Self>) -> Vec<Resolvable<'w,E>> {
vec![]
}
fn _trace_bounds(&self, _: Link<E>, _: usize, _: &Bounds, _: bool) -> Result<Bounds,()> {
Err(())
}
fn focusable(&self) -> bool { true }
fn child<'a>(&'a self, _: usize) -> Result<Resolvable<'a,E>,()> where 'w: 'a {
Err(())
}
fn into_child(self: Box<Self>, _: usize) -> Result<Resolvable<'w,E>,()> {
Err(())
}
}
impl<'w,E,S> WidgetMut<'w,E> for Button<'w,E,S> where
E: Env,
ERenderer<E>: RenderStdWidgets<E>,
EEvent<E>: StdVarSup<E>,
ESVariant<E>: StyleVariantSupport<StdVerb>,
E::Context: AsHandlerStateful<E>,
S: Caption<'w>+Statize,
S::Statur: Sized,
{
fn childs_mut<'s>(&'s mut self) -> Vec<ResolvableMut<'s,E>> where 'w: 's {
vec![]
}
fn into_childs_mut(self: Box<Self>) -> Vec<ResolvableMut<'w,E>> {
vec![]
}
fn child_mut<'a>(&'a mut self, _: usize) -> Result<ResolvableMut<'a,E>,()> where 'w: 'a {
Err(())
}
fn into_child_mut(self: Box<Self>, _: usize) -> Result<ResolvableMut<'w,E>,()> {
Err(())
}
}
impl<'w,E,S> Button<'w,E,S> where
E: Env,
ERenderer<E>: RenderStdWidgets<E>,
EEvent<E>: StdVarSup<E>,
ESVariant<E>: StyleVariantSupport<StdVerb>,
E::Context: AsHandlerStateful<E>,
S: Caption<'w>+Statize,
S::Statur: Sized,
{
pub fn pressed<'l:'s,'s>(l: &'s Link<'l,E>) -> Option<&'s EPressedKey<E>> {
let id = l.id();
l.state().is_pressed_and_id(&[EEKey::<E>::MOUSE_LEFT],id.clone())
.or_else(||
l.state().is_pressed_and_id(&[EEKey::<E>::ENTER],id.clone())
)
.or_else(||
l.state().is_pressed_and_id(&[EEKey::<E>::SPACE],id)
)
}
}