Files
AynaLivePlayer/gui/helper_async_button.go
2022-07-13 18:59:04 -07:00

53 lines
895 B
Go

package gui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
// AsyncButton is a Button that handle OnTapped handler asynchronously.
type AsyncButton struct {
widget.Button
anim *fyne.Animation
}
func NewAsyncButton(label string, tapped func()) *AsyncButton {
button := &AsyncButton{
Button: widget.Button{
Text: label,
OnTapped: tapped,
},
}
button.ExtendBaseWidget(button)
return button
}
func NewAsyncButtonWithIcon(label string, icon fyne.Resource, tapped func()) *AsyncButton {
button := &AsyncButton{
Button: widget.Button{
Text: label,
Icon: icon,
OnTapped: tapped,
},
}
button.ExtendBaseWidget(button)
return button
}
func (b *AsyncButton) Tapped(e *fyne.PointEvent) {
if b.Disabled() {
return
}
// missing animation
b.Refresh()
if b.OnTapped != nil {
b.Disable()
go func() {
b.OnTapped()
b.Enable()
}()
}
}