Files
AynaLivePlayer/gui/component/button.go
2025-07-17 00:28:12 +08:00

49 lines
851 B
Go

package component
import (
"AynaLivePlayer/gui/gutil"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
)
type AsyncButton struct {
widget.Button
}
func NewAsyncButton(label string, tapped func()) *AsyncButton {
b := &AsyncButton{
Button: widget.Button{
Text: label,
},
}
b.ExtendBaseWidget(b)
b.SetOnTapped(tapped)
return b
}
func NewAsyncButtonWithIcon(label string, icon fyne.Resource, tapped func()) *AsyncButton {
b := &AsyncButton{
Button: widget.Button{
Text: label,
Icon: icon,
},
}
b.ExtendBaseWidget(b)
b.SetOnTapped(tapped)
return b
}
func (b *AsyncButton) SetOnTapped(f func()) {
b.Button.OnTapped = func() {
b.Disable()
go func() {
f()
//time.Sleep(3 * time.Second)
// todo use fyne.Do after upgrade to v2.6.x
gutil.RunInFyneThread(b.Enable)
//b.Enable()
//fyne.Do(b.Enable)
}()
}
}