diff --git a/widget/checkbox.go b/widget/checkbox.go index 3dd6c674..f071df93 100644 --- a/widget/checkbox.go +++ b/widget/checkbox.go @@ -6,22 +6,19 @@ import ( ) type CheckBox struct { - click gesture.Click - checked bool + Checked bool + + click gesture.Click } -func (c *CheckBox) SetChecked(value bool) { - c.checked = value -} - -func (c *CheckBox) Checked(gtx *layout.Context) bool { +// Update the checked state according to incoming events. +func (c *CheckBox) Update(gtx *layout.Context) { for _, e := range c.click.Events(gtx) { switch e.Type { case gesture.TypeClick: - c.checked = !c.checked + c.Checked = !c.Checked } } - return c.checked } func (c *CheckBox) Layout(gtx *layout.Context) { diff --git a/widget/material/checkbox.go b/widget/material/checkbox.go index 3fea13a7..77f0ef6d 100644 --- a/widget/material/checkbox.go +++ b/widget/material/checkbox.go @@ -27,7 +27,9 @@ func CheckBox(th *Theme, label string) CheckBoxStyle { } } +// Layout updates the checkBox and displays it. func (c CheckBoxStyle) Layout(gtx *layout.Context, checkBox *widget.CheckBox) { - c.layout(gtx, checkBox.Checked(gtx)) + checkBox.Update(gtx) + c.layout(gtx, checkBox.Checked) checkBox.Layout(gtx) }