From 52d8a8867d7208e8cb57cd1540fe470777eac132 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 3 May 2020 21:25:49 +0200 Subject: [PATCH] widget,widget/material: export CheckBox.Checked Similar to the previous change to Enum, expose the current state of the CheckBox. Rename the Checked method to just Update and get rid of the SetChecked method. Fixes gio#100 Signed-off-by: Elias Naur --- widget/checkbox.go | 15 ++++++--------- widget/material/checkbox.go | 4 +++- 2 files changed, 9 insertions(+), 10 deletions(-) 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) }