forked from joejulian/gio
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:
+8
-11
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user