From dc9787112231140361635546ea6c26f4f6dece2d Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 2 Oct 2023 16:58:11 -0500 Subject: [PATCH] widget: [API] rename Bool.Changed to Update and move state update to it Similar to a previous change for Clickable, this change separates Bool state changes to its renamed method Update. This allows access to the most recent state before calling Layout. Signed-off-by: Elias Naur --- widget/bool.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/widget/bool.go b/widget/bool.go index 740ce5b3..4ed8a6f3 100644 --- a/widget/bool.go +++ b/widget/bool.go @@ -11,15 +11,15 @@ type Bool struct { Value bool clk Clickable - - changed bool } -// Changed reports whether Value has changed since the last -// call to Changed. -func (b *Bool) Changed() bool { - changed := b.changed - b.changed = false +// Update the widget state and report whether Value was changed. +func (b *Bool) Update(gtx layout.Context) bool { + changed := false + for b.clk.Clicked(gtx) { + b.Value = !b.Value + changed = true + } return changed } @@ -43,10 +43,7 @@ func (b *Bool) History() []Press { } func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions { - for b.clk.Clicked(gtx) { - b.Value = !b.Value - b.changed = true - } + b.Update(gtx) dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions { semantic.SelectedOp(b.Value).Add(gtx.Ops) semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops)