| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //go:build js && wasm
- package ultraviolet
- import (
- "fmt"
- "syscall/js"
- )
- type TextComponentWeb struct {
- node js.Value
- view View
- format string
- values []Value
- }
- func NewTextComponentWeb(view View) *TextComponentWeb {
- return &TextComponentWeb{
- view: view,
- values: []Value{},
- }
- }
- // Component
- func (this *TextComponentWeb) Build(parent Component) {
- values := []any{}
- for _, text := range this.values {
- if text.Value() == nil {
- values = append(values, "")
- } else {
- values = append(values, text.Value().(string))
- }
- }
- this.node = WebBuildDiv(
- this.node,
- parent,
- this.view,
- "",
- fmt.Sprintf(
- this.format,
- values...,
- ),
- AbstractHandlers{},
- )
- }
- func (this *TextComponentWeb) Invalidate() bool {
- for _, value := range this.values {
- if !value.Invalidate() {
- continue
- }
- return true
- }
- return false
- }
- func (this *TextComponentWeb) Clean() {
- WebCleanChildren(this.node)
- }
- // JS
- func (this *TextComponentWeb) Node() js.Value {
- return this.node
- }
- // ComponentText
- func (this *TextComponentWeb) SetValue(format string, values []Value) {
- this.format = format
- this.values = values
- }
|