Files
gio-patched/widget/bool.go
T
Elias Naur 8d838e89f5 widget,widget/material: rename widget.Click to widget.Press
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>
2020-05-24 13:19:34 +02:00

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)
}