widget/material: add Switch widget

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-04 14:39:21 +02:00
parent 6b4eb710b3
commit 26da49e145
2 changed files with 142 additions and 3 deletions
+10 -3
View File
@@ -8,19 +8,26 @@ import (
type Bool struct {
Value bool
click gesture.Click
// 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.click.Events(gtx) {
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.click.Add(gtx.Ops)
b.gesture.Add(gtx.Ops)
}