From 6b4eb710b328b66e7165fb9d41990d6f81d447af Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 4 May 2020 14:28:33 +0200 Subject: [PATCH] widget: rename CheckBox to Bool We're about to introduce the Switch widget that re-uses the same state type as CheckBox. The Bool name covers both uses. Signed-off-by: Elias Naur --- widget/bool.go | 26 ++++++++++++++++++++++++++ widget/checkbox.go | 26 -------------------------- widget/material/checkbox.go | 4 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 widget/bool.go delete mode 100644 widget/checkbox.go diff --git a/widget/bool.go b/widget/bool.go new file mode 100644 index 00000000..75f7161f --- /dev/null +++ b/widget/bool.go @@ -0,0 +1,26 @@ +package widget + +import ( + "gioui.org/gesture" + "gioui.org/layout" +) + +type Bool struct { + Value bool + + click gesture.Click +} + +// Update the checked state according to incoming events. +func (b *Bool) Update(gtx *layout.Context) { + for _, e := range b.click.Events(gtx) { + switch e.Type { + case gesture.TypeClick: + b.Value = !b.Value + } + } +} + +func (b *Bool) Layout(gtx *layout.Context) { + b.click.Add(gtx.Ops) +} diff --git a/widget/checkbox.go b/widget/checkbox.go deleted file mode 100644 index f071df93..00000000 --- a/widget/checkbox.go +++ /dev/null @@ -1,26 +0,0 @@ -package widget - -import ( - "gioui.org/gesture" - "gioui.org/layout" -) - -type CheckBox struct { - Checked bool - - click gesture.Click -} - -// 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 - } - } -} - -func (c *CheckBox) Layout(gtx *layout.Context) { - c.click.Add(gtx.Ops) -} diff --git a/widget/material/checkbox.go b/widget/material/checkbox.go index 77f0ef6d..552f06cf 100644 --- a/widget/material/checkbox.go +++ b/widget/material/checkbox.go @@ -28,8 +28,8 @@ func CheckBox(th *Theme, label string) CheckBoxStyle { } // Layout updates the checkBox and displays it. -func (c CheckBoxStyle) Layout(gtx *layout.Context, checkBox *widget.CheckBox) { +func (c CheckBoxStyle) Layout(gtx *layout.Context, checkBox *widget.Bool) { checkBox.Update(gtx) - c.layout(gtx, checkBox.Checked) + c.layout(gtx, checkBox.Value) checkBox.Layout(gtx) }