mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-22 23:14:59 -04:00
drafting
This commit is contained in:
parent
d276f52942
commit
6b92ec10cc
60
tracker/gioui/focus.go
Normal file
60
tracker/gioui/focus.go
Normal file
@ -0,0 +1,60 @@
|
||||
package gioui
|
||||
|
||||
import (
|
||||
"gioui.org/io/event"
|
||||
"gioui.org/io/key"
|
||||
)
|
||||
|
||||
type TagYieldFunc func(level int, tag event.Tag) bool
|
||||
|
||||
func (t *Tracker) FocusNext(gtx C, maxLevel int) {
|
||||
var focused, first, next event.Tag
|
||||
yield := func(level int, tag event.Tag) bool {
|
||||
if first == nil {
|
||||
first = tag // remember the first tag
|
||||
}
|
||||
if focused != nil && level <= maxLevel {
|
||||
next = tag
|
||||
return false // we're done
|
||||
}
|
||||
if gtx.Source.Focused(tag) {
|
||||
focused = tag
|
||||
}
|
||||
return true
|
||||
}
|
||||
if t.Tags(0, yield) {
|
||||
t.Tags(0, yield) // run it twice to ensure we find the next tag after the focused one
|
||||
}
|
||||
if next == nil {
|
||||
next = first // if we didn't find a next tag, use the first one
|
||||
}
|
||||
if next != nil {
|
||||
gtx.Execute(key.FocusCmd{Tag: next})
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracker) FocusPrev(gtx C, maxLevel int) {
|
||||
var prev, first event.Tag
|
||||
yield := func(level int, tag event.Tag) bool {
|
||||
if first == nil {
|
||||
first = tag // remember the first tag
|
||||
}
|
||||
if gtx.Source.Focused(tag) {
|
||||
if prev != nil {
|
||||
return false // we're done
|
||||
}
|
||||
} else if level <= maxLevel {
|
||||
prev = tag
|
||||
}
|
||||
return true
|
||||
}
|
||||
if t.Tags(0, yield) {
|
||||
t.Tags(0, yield) // run it twice to ensure we find the previous tag before the focused one
|
||||
}
|
||||
if prev == nil {
|
||||
prev = first // if we didn't find a next tag, use the first one
|
||||
}
|
||||
if prev != nil {
|
||||
gtx.Execute(key.FocusCmd{Tag: prev})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user