mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget/material: add Switch widget
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+10
-3
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user