mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-03-15 22:13:17 +08:00
53 lines
895 B
Go
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()
|
|
}()
|
|
}
|
|
}
|