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
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)