refactor: first step to refactor the ui

This commit is contained in:
Patryk Hegenberg 2025-06-27 19:37:15 +02:00
parent a8ed9c9ed1
commit 9cae00d2a5
7 changed files with 330 additions and 158 deletions

View file

@ -0,0 +1,62 @@
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"
)
// NavButton ist unser benutzerdefinierter Navigationsbutton
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.icon.Resource.Color = theme.ColorSky400
b.label.Color = theme.ColorSky400
} else {
// b.icon.Resource.Color = theme.ColorSlate400
b.label.Color = theme.ColorSlate400
}
b.Refresh()
}