forked from joejulian/gio
8d838e89f5
Press tracks pointer presses, not clicks, and we're about to add a Click type that does. Signed-off-by: Elias Naur <mail@eliasnaur.com>
40 lines
710 B
Go
40 lines
710 B
Go
package widget
|
|
|
|
import (
|
|
"gioui.org/gesture"
|
|
"gioui.org/layout"
|
|
)
|
|
|
|
type Bool struct {
|
|
Value bool
|
|
// Last is the last registered click.
|
|
Last Press
|
|
|
|
// changeVal tracks Value from the most recent call to Changed.
|
|
changeVal bool
|
|
|
|
gesture gesture.Click
|
|
}
|
|
|
|
// Changed reports whether Value has changed since the last
|
|
// call to Changed.
|
|
func (b *Bool) Changed() bool {
|
|
changed := b.Value != b.changeVal
|
|
b.changeVal = b.Value
|
|
return changed
|
|
}
|
|
|
|
func (b *Bool) Layout(gtx layout.Context) {
|
|
for _, e := range b.gesture.Events(gtx) {
|
|
switch e.Type {
|
|
case gesture.TypeClick:
|
|
b.Last = Press{
|
|
Time: gtx.Now(),
|
|
Position: e.Position,
|
|
}
|
|
b.Value = !b.Value
|
|
}
|
|
}
|
|
b.gesture.Add(gtx.Ops)
|
|
}
|