gio/widget/checkbox.go -rw-r--r-- 465 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package widget

import (
	"gioui.org/gesture"
	"gioui.org/layout"
)

type CheckBox struct {
	click   gesture.Click
	checked bool
}

func (c *CheckBox) SetChecked(value bool) {
	c.checked = value
}

func (c *CheckBox) Checked(gtx *layout.Context) bool {
	for _, e := range c.click.Events(gtx) {
		switch e.Type {
		case gesture.TypeClick:
			c.checked = !c.checked
		}
	}
	return c.checked
}

func (c *CheckBox) Layout(gtx *layout.Context) {
	c.click.Add(gtx.Ops)
}