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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-10-02 16:58:11 -05:00
parent 4a4fe5a69b
commit dc97871122
+8 -11
View File
@@ -11,15 +11,15 @@ type Bool struct {
Value bool Value bool
clk Clickable clk Clickable
changed bool
} }
// Changed reports whether Value has changed since the last // Update the widget state and report whether Value was changed.
// call to Changed. func (b *Bool) Update(gtx layout.Context) bool {
func (b *Bool) Changed() bool { changed := false
changed := b.changed for b.clk.Clicked(gtx) {
b.changed = false b.Value = !b.Value
changed = true
}
return changed return changed
} }
@@ -43,10 +43,7 @@ func (b *Bool) History() []Press {
} }
func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions { func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions {
for b.clk.Clicked(gtx) { b.Update(gtx)
b.Value = !b.Value
b.changed = true
}
dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions { dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
semantic.SelectedOp(b.Value).Add(gtx.Ops) semantic.SelectedOp(b.Value).Add(gtx.Ops)
semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops) semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops)