mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
6b4eb710b3
We're about to introduce the Switch widget that re-uses the same state type as CheckBox. The Bool name covers both uses. Signed-off-by: Elias Naur <mail@eliasnaur.com>
27 lines
414 B
Go
27 lines
414 B
Go
package widget
|
|
|
|
import (
|
|
"gioui.org/gesture"
|
|
"gioui.org/layout"
|
|
)
|
|
|
|
type Bool struct {
|
|
Value bool
|
|
|
|
click gesture.Click
|
|
}
|
|
|
|
// Update the checked state according to incoming events.
|
|
func (b *Bool) Update(gtx *layout.Context) {
|
|
for _, e := range b.click.Events(gtx) {
|
|
switch e.Type {
|
|
case gesture.TypeClick:
|
|
b.Value = !b.Value
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *Bool) Layout(gtx *layout.Context) {
|
|
b.click.Add(gtx.Ops)
|
|
}
|