Files
AynaLivePlayer/gui/component/button.go
2025-06-15 00:04:13 +08:00

45 lines
723 B
Go

package component
import (
"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)
fyne.Do(b.Enable)
}()
}
}