io/router,app: scroll a bit when reaching the end in a focus direction

List was recently changed to include an extra child at each end, to
automatically scroll when reaching the end of a focus direction. However,
if List includes unfocusable children that strategy may fail. This change
adds another fallback where app.Window will scroll a constant amount in
the focus direction, to reveal more children.

For https://github.com/tailscale/tailscale/issues/4278.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-03-31 12:58:29 +02:00
parent cd0c9dab9f
commit a1b5ff059c
4 changed files with 45 additions and 10 deletions
+14 -5
View File
@@ -149,13 +149,13 @@ func (q *Router) Queue(events ...event.Event) bool {
return q.handlers.HadEvents()
}
func (q *Router) MoveFocus(dir FocusDirection) {
q.key.queue.MoveFocus(dir, &q.handlers)
func (q *Router) MoveFocus(dir FocusDirection) bool {
return q.key.queue.MoveFocus(dir, &q.handlers)
}
// ScrollFocus scrolls the current focus (if any) into viewport
// RevealFocus scrolls the current focus (if any) into viewport
// if there are scrollable parent handlers.
func (q *Router) ScrollFocus(viewport image.Rectangle) {
func (q *Router) RevealFocus(viewport image.Rectangle) {
focus := q.key.queue.focus
if focus == nil {
return
@@ -175,11 +175,20 @@ func (q *Router) ScrollFocus(viewport image.Rectangle) {
if s.Y == 0 {
s.Y = bottomright.Y
}
q.ScrollFocus(s)
}
// ScrollFocus scrolls the focused widget, if any, by dist.
func (q *Router) ScrollFocus(dist image.Point) {
focus := q.key.queue.focus
if focus == nil {
return
}
area := q.key.queue.AreaFor(focus)
q.pointer.queue.Deliver(area, pointer.Event{
Type: pointer.Scroll,
Source: pointer.Touch,
Scroll: fpt(s),
Scroll: fpt(dist),
}, &q.handlers)
}