component_web_image.go 911 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //go:build js && wasm
  2. package ultraviolet
  3. import (
  4. "syscall/js"
  5. )
  6. type ImageComponentWeb struct {
  7. node js.Value
  8. view View
  9. change bool
  10. path string
  11. width int
  12. }
  13. func NewImageComponentWeb(view View) *ImageComponentWeb {
  14. return &ImageComponentWeb{
  15. view: view,
  16. change: true,
  17. path: "",
  18. }
  19. }
  20. // Component
  21. func (this *ImageComponentWeb) Build(parent Component) {
  22. this.node = WebBuildImg(
  23. this.node,
  24. parent,
  25. this.view,
  26. this.path,
  27. this.width,
  28. )
  29. }
  30. func (this *ImageComponentWeb) Invalidate() bool {
  31. result := this.change
  32. this.change = false
  33. return result
  34. }
  35. func (this *ImageComponentWeb) Clean() {
  36. WebCleanChildren(this.node)
  37. }
  38. // JS
  39. func (this *ImageComponentWeb) Node() js.Value {
  40. return this.node
  41. }
  42. // ComponentImage
  43. func (this *ImageComponentWeb) SetPath(path string) {
  44. this.path = path
  45. }
  46. func (this *ImageComponentWeb) SetWidth(width int) {
  47. this.width = width
  48. }