59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package components
|
|
|
|
import (
|
|
"image/color"
|
|
|
|
"git.patanix.de/git/kettlebell-app/internal/ui/theme"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/canvas"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/widget"
|
|
)
|
|
|
|
type NavButton struct {
|
|
widget.BaseWidget
|
|
icon *canvas.Image
|
|
label *canvas.Text
|
|
onTapped func()
|
|
isActive bool
|
|
container *fyne.Container
|
|
}
|
|
|
|
func NewNavButton(label string, iconRes fyne.Resource, active bool, tapped func()) *NavButton {
|
|
icon := canvas.NewImageFromResource(iconRes)
|
|
icon.FillMode = canvas.ImageFillContain
|
|
icon.SetMinSize(fyne.NewSize(28, 28))
|
|
|
|
text := canvas.NewText(label, color.White)
|
|
text.TextSize = 12
|
|
text.Alignment = fyne.TextAlignCenter
|
|
|
|
button := &NavButton{
|
|
icon: icon,
|
|
label: text,
|
|
onTapped: tapped,
|
|
}
|
|
button.ExtendBaseWidget(button)
|
|
button.container = container.NewVBox(icon, text)
|
|
button.SetActive(active)
|
|
return button
|
|
}
|
|
|
|
func (b *NavButton) CreateRenderer() fyne.WidgetRenderer {
|
|
return widget.NewSimpleRenderer(b.container)
|
|
}
|
|
|
|
func (b *NavButton) Tapped(*fyne.PointEvent) {
|
|
b.onTapped()
|
|
}
|
|
|
|
func (b *NavButton) SetActive(active bool) {
|
|
b.isActive = active
|
|
if b.isActive {
|
|
b.label.Color = theme.OneDarkGreen
|
|
} else {
|
|
b.label.Color = theme.OneDarkText
|
|
}
|
|
b.Refresh()
|
|
}
|