Files
gio-patched/widget/bool.go
T
Elias Naur 26da49e145 widget/material: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-05-05 10:38:31 +02:00

34 lines
547 B
Go

package widget
import (
"gioui.org/gesture"
"gioui.org/layout"
)
type Bool struct {
Value bool
// Last is the last registered click.
Last Click
gesture gesture.Click
}
// Update the checked state according to incoming events.
func (b *Bool) Update(gtx *layout.Context) {
for _, e := range b.gesture.Events(gtx) {
switch e.Type {
case gesture.TypeClick:
b.Last = Click{
Time: gtx.Now(),
Position: e.Position,
}
b.Value = !b.Value
}
}
}
func (b *Bool) Layout(gtx *layout.Context) {
b.gesture.Add(gtx.Ops)
}