component_web_container.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //go:build js && wasm
  2. package ultraviolet
  3. import (
  4. "syscall/js"
  5. )
  6. type ContainerComponentWeb struct {
  7. node js.Value
  8. view View
  9. value Value
  10. handler ClickHandler
  11. }
  12. func NewContainerComponentWeb(view View) *ContainerComponentWeb {
  13. return &ContainerComponentWeb{
  14. view: view,
  15. }
  16. }
  17. // Component
  18. func (this *ContainerComponentWeb) Build(parent Component) {
  19. this.node = WebBuildDiv(
  20. this.node,
  21. parent,
  22. this.view,
  23. "",
  24. "",
  25. AbstractHandlers{
  26. HANDLER_CLICK: func(args ...any) error {
  27. if this.handler == nil {
  28. return nil
  29. }
  30. this.handler()
  31. return nil
  32. },
  33. },
  34. )
  35. }
  36. func (this *ContainerComponentWeb) Invalidate() bool {
  37. if this.value == nil {
  38. return false
  39. }
  40. return this.value.Invalidate()
  41. }
  42. func (this *ContainerComponentWeb) Clean() {
  43. WebCleanChildren(this.node)
  44. }
  45. // JS
  46. func (this *ContainerComponentWeb) Node() js.Value {
  47. return this.node
  48. }
  49. // ComponentContainer
  50. func (this *ContainerComponentWeb) SetValue(value Value) {
  51. this.value = value
  52. }
  53. func (this *ContainerComponentWeb) SetHandler(handler ClickHandler) {
  54. this.handler = handler
  55. }