From 403f01655a367543e25142a32f3ec18c22ad4fd2 Mon Sep 17 00:00:00 2001 From: Paulo Melo Date: Thu, 4 Feb 2021 08:09:24 +0000 Subject: [PATCH] Programmatic Click function Signed-off-by: Paulo Melo --- widget/button.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/widget/button.go b/widget/button.go index 9e081d3c..53ade08b 100644 --- a/widget/button.go +++ b/widget/button.go @@ -44,6 +44,14 @@ type Press struct { Cancelled bool } +// Click executes a simple programmatic click +func (b *Clickable) Click() { + b.clicks = append(b.clicks, Click{ + Modifiers: 0, + NumClicks: 1, + }) +} + // Clicked reports whether there are pending clicks as would be // reported by Clicks. If so, Clicked removes the earliest click. func (b *Clickable) Clicked() bool { @@ -82,6 +90,7 @@ func (b *Clickable) History() []Press { return b.history } +// Layout and update the button state func (b *Clickable) Layout(gtx layout.Context) layout.Dimensions { b.update(gtx) stack := op.Save(gtx.Ops)