| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //go:build js && wasm
- package ultraviolet
- import (
- "fmt"
- "syscall/js"
- )
- type ButtonComponentWeb struct {
- node js.Value
- view View
- format string
- values []Value
- handler ClickHandler
- }
- func NewButtonComponentWeb(view View) *ButtonComponentWeb {
- return &ButtonComponentWeb{
- view: view,
- values: []Value{},
- }
- }
- // Component
- func (this *ButtonComponentWeb) 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{
- HANDLER_CLICK: func(args ...any) error {
- if this.handler == nil {
- return nil
- }
- this.handler()
- return nil
- },
- },
- )
- }
- func (this *ButtonComponentWeb) Invalidate() bool {
- for _, value := range this.values {
- if !value.Invalidate() {
- continue
- }
- return true
- }
- return false
- }
- func (this *ButtonComponentWeb) Clean() {
- WebCleanChildren(this.node)
- }
- // JS
- func (this *ButtonComponentWeb) Node() js.Value {
- return this.node
- }
- // ComponentButton
- func (this *ButtonComponentWeb) SetValue(format string, values []Value) {
- this.format = format
- this.values = values
- }
- func (this *ButtonComponentWeb) SetHandler(handler ClickHandler) {
- this.handler = handler
- }
|