serialise.go 567 B

1234567891011121314151617181920212223242526
  1. package fyne
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // GoString converts a Resource object to Go code.
  7. // This is useful if serialising to a Go file for compilation into a binary.
  8. func (r *StaticResource) GoString() string {
  9. buffer := strings.Builder{}
  10. buffer.WriteString("&fyne.StaticResource{\n\tStaticName: \"")
  11. buffer.WriteString(r.StaticName)
  12. buffer.WriteString("\",\n\tStaticContent: []byte{\n\t\t")
  13. for i, v := range r.StaticContent {
  14. if i > 0 {
  15. buffer.WriteString(", ")
  16. }
  17. fmt.Fprint(&buffer, v)
  18. }
  19. buffer.WriteString("}}")
  20. return buffer.String()
  21. }