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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-03 21:25:49 +02:00
parent f1e266a9e7
commit 52d8a8867d
2 changed files with 9 additions and 10 deletions
+6 -9
View File
@@ -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) {
+3 -1
View File
@@ -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)
}