widget: [API] move Clickable state update from Layout to Clicks

Before this change, Clickable state updates would happen in Layout.
However, that is too late in cases where clicks affects layout that
contiains the Clickable.

This change removes state changes from Layout and moves them to Clicks,
to allow users pre-layout access. Note that Layout itself processes
events, which means users can no longer access clicks after Layout.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-09-29 17:07:43 -05:00
parent 1686874d07
commit 4a4fe5a69b
6 changed files with 64 additions and 72 deletions
+4 -4
View File
@@ -43,11 +43,11 @@ 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
}
dims := b.clk.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
for b.clk.Clicked() {
b.Value = !b.Value
b.changed = true
}
semantic.SelectedOp(b.Value).Add(gtx.Ops)
semantic.EnabledOp(gtx.Queue != nil).Add(gtx.Ops)
return w(gtx)