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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use embedded_touch::{Tool, Touch};
use crate::{
event::{Event, EventResult},
focus::{FocusAction, FocusDirection, FocusGroup},
primitives::Point,
};
/// [`Harness`] provides a convenience interface for sending events
pub trait Harness {
/// Sends an event and returns the result.
fn send(&mut self, event: impl Into<Event>) -> EventResult;
/// Acquires focus, searching forward.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn focus_forward(&mut self) -> EventResult {
self.send(FocusAction::Focus(FocusDirection::Forward))
}
/// Acquires focus searching forward in the specified group.
fn focus_forward_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Focus(FocusDirection::Forward).into_event(group))
}
/// Acquires focus, searching backward.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn focus_backward(&mut self) -> EventResult {
self.send(FocusAction::Focus(FocusDirection::Backward))
}
/// Acquires focus searching backward in the specified group.
fn focus_backward_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Focus(FocusDirection::Backward).into_event(group))
}
/// Moves focus to the next element.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn next(&mut self) -> EventResult {
self.send(FocusAction::Next)
}
/// Moves focus to the next element in the specified group.
fn next_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Next.into_event(group))
}
/// Moves focus to the previous element.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn previous(&mut self) -> EventResult {
self.send(FocusAction::Previous)
}
/// Moves focus to the previous element in the specified group.
fn previous_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Previous.into_event(group))
}
/// Activates the currently focused element.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn select(&mut self) -> EventResult {
self.send(FocusAction::Select)
}
/// Activates the currently focused element in the specified group.
fn select_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Select.into_event(group))
}
/// Blurs (exits) the current focus.
///
/// The event is sent with [`CommonGroup`](FocusGroup::common_group())
fn blur(&mut self) -> EventResult {
self.send(FocusAction::Blur)
}
/// Blurs (exits) the current focus in the specified group.
fn blur_group(&mut self, group: FocusGroup) -> EventResult {
self.send(FocusAction::Blur.into_event(group))
}
/// Sends a tap (touch down + touch up) at the given point.
///
/// The result of the touch up event is returned.
fn tap(&mut self, point: Point) -> EventResult {
self.send(Event::Touch(Touch::new(
0,
point.into(),
embedded_touch::Phase::Started,
Tool::Finger,
)));
self.send(Event::Touch(Touch::new(
0,
point.into(),
embedded_touch::Phase::Ended,
Tool::Finger,
)))
}
/// Sends a drag (down + move + up) from the start point to the end point.
///
/// The result of the touch up event is returned.
fn drag(&mut self, start: Point, end: Point) -> EventResult {
self.send(Event::Touch(Touch::new(
0,
start.into(),
embedded_touch::Phase::Started,
Tool::Finger,
)));
self.send(Event::Touch(Touch::new(
0,
end.into(),
embedded_touch::Phase::Moved,
Tool::Finger,
)));
self.send(Event::Touch(Touch::new(
0,
end.into(),
embedded_touch::Phase::Ended,
Tool::Finger,
)))
}
/// Sends a touch down event at the given point.
///
/// Prefer [`Self::tap()`] or [`Self::drag()`] when possible to avoid leaving
/// the view in an inconsistent state.
fn touch_down(&mut self, point: Point) -> EventResult {
self.send(Event::Touch(Touch::new(
0,
point.into(),
embedded_touch::Phase::Started,
Tool::Finger,
)))
}
/// Sends a touch move event at the given point.
///
/// Prefer [`Self::drag()`] when possible to avoid leaving the view in an
/// inconsistent state.
fn touch_move(&mut self, point: Point) -> EventResult {
self.send(Event::Touch(Touch::new(
0,
point.into(),
embedded_touch::Phase::Moved,
Tool::Finger,
)))
}
/// Sends a touch up event at the given point.
///
/// Prefer [`Self::tap()`] or [`Self::drag()`] when possible to avoid leaving
/// the view in an inconsistent state.
fn touch_up(&mut self, point: Point) -> EventResult {
self.send(Event::Touch(Touch::new(
0,
point.into(),
embedded_touch::Phase::Ended,
Tool::Finger,
)))
}
}