buttons.go 794 B

123456789101112131415161718192021222324252627282930313233
  1. package components
  2. import (
  3. "image/color"
  4. "fyne.io/fyne/v2"
  5. "fyne.io/fyne/v2/canvas"
  6. "fyne.io/fyne/v2/container"
  7. "fyne.io/fyne/v2/layout"
  8. "fyne.io/fyne/v2/widget"
  9. )
  10. // ColoredButton - renders a colored button with text
  11. func ColoredButton(text string, tapped func(), color color.Color) *fyne.Container {
  12. btn := widget.NewButton(text, tapped)
  13. bgColor := canvas.NewRectangle(color)
  14. return container.New(
  15. layout.NewMaxLayout(),
  16. bgColor,
  17. btn,
  18. )
  19. }
  20. // ColoredIconButton - renders a colored button with an icon
  21. func ColoredIconButton(text string, icon fyne.Resource, tapped func(), color color.Color) *fyne.Container {
  22. btn := widget.NewButtonWithIcon(text, icon, tapped)
  23. bgColor := canvas.NewRectangle(color)
  24. return container.New(
  25. layout.NewMaxLayout(),
  26. btn,
  27. bgColor,
  28. )
  29. }