icons.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package data
  2. import (
  3. "fyne.io/fyne"
  4. )
  5. // ThemedResource is a resource wrapper that will return an appropriate resource
  6. // for the currently selected theme.
  7. type ThemedResource struct {
  8. dark, light fyne.Resource
  9. }
  10. func isLight() bool {
  11. r, g, b, _ := fyne.CurrentApp().Settings().Theme().TextColor().RGBA()
  12. return r < 0xaaaa && g < 0xaaaa && b < 0xaaaa
  13. }
  14. // Name returns the underlying resource name (used for caching)
  15. func (res *ThemedResource) Name() string {
  16. if isLight() {
  17. return res.light.Name()
  18. }
  19. return res.dark.Name()
  20. }
  21. // Content returns the underlying content of the correct resource for the current theme
  22. func (res *ThemedResource) Content() []byte {
  23. if isLight() {
  24. return res.light.Content()
  25. }
  26. return res.dark.Content()
  27. }
  28. // NewThemedResource creates a resource that adapts to the current theme setting.
  29. func NewThemedResource(dark, light fyne.Resource) *ThemedResource {
  30. return &ThemedResource{dark, light}
  31. }
  32. // FyneScene contains the full fyne logo with background design
  33. var FyneScene = NewThemedResource(fynescenedark, fynescenelight)