io/router,app: add support for directional focus moves

Implement support for up/down/right/left directional focus moves
and map Android directional pad keys to focus moves.

Fixes: https://todo.sr.ht/~eliasnaur/gio/195
References: https://github.com/tailscale/tailscale/issues/1611
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-27 10:33:22 +01:00
parent 2e9df04a7b
commit 73eabb352d
6 changed files with 205 additions and 20 deletions
+16 -4
View File
@@ -222,6 +222,14 @@ func (c *pointerCollector) currentArea() int {
return -1
}
func (c *pointerCollector) currentAreaBounds() f32.Rectangle {
a := c.currentArea()
if a == -1 {
panic("no root area")
}
return c.q.areas[a].bounds()
}
func (c *pointerCollector) addHitNode(n hitNode) {
n.next = c.state.nodePlusOne - 1
c.q.hitTree = append(c.q.hitTree, n)
@@ -382,10 +390,7 @@ func (q *pointerQueue) appendSemanticChildren(nodes []SemanticNode, areaIdx int)
nodes = append(nodes, SemanticNode{
ID: semID,
Desc: SemanticDesc{
Bounds: f32.Rectangle{
Min: a.trans.Transform(a.area.rect.Min),
Max: a.trans.Transform(a.area.rect.Max),
},
Bounds: a.bounds(),
Label: cnt.label,
Description: cnt.desc,
Class: cnt.class,
@@ -869,6 +874,13 @@ func (op *areaOp) Hit(pos f32.Point) bool {
}
}
func (a *areaNode) bounds() f32.Rectangle {
return f32.Rectangle{
Min: a.trans.Transform(a.area.rect.Min),
Max: a.trans.Transform(a.area.rect.Max),
}
}
func setScrollEvent(scroll float32, min, max int) (left, scrolled float32) {
if v := float32(max); scroll > v {
return scroll - v, v