github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/widget/checkbox.go (about) 1 package widget 2 3 import ( 4 "github.com/gop9/olt/gio/gesture" 5 "github.com/gop9/olt/gio/layout" 6 ) 7 8 type CheckBox struct { 9 click gesture.Click 10 checked bool 11 } 12 13 func (c *CheckBox) SetChecked(value bool) { 14 c.checked = value 15 } 16 17 func (c *CheckBox) Checked(gtx *layout.Context) bool { 18 for _, e := range c.click.Events(gtx) { 19 switch e.Type { 20 case gesture.TypeClick: 21 c.checked = !c.checked 22 } 23 } 24 return c.checked 25 } 26 27 func (c *CheckBox) Layout(gtx *layout.Context) { 28 c.click.Add(gtx.Ops) 29 }