summaryrefslogtreecommitdiff
path: root/toolkit/gocui/plugin.go
blob: 396042bc3f4c702be38ac75f01d8eeaa28e55873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

import (
	// if you include more than just this import
	// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
	"git.wit.org/wit/gui/toolkit"
)

func Quit() {
	me.baseGui.Close()
}

func Action(a *toolkit.Action) {
	log(logInfo, "Action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
	w := findWidget(a.WidgetId, me.rootNode)
	switch a.ActionType {
	case toolkit.Add:
		w = makeWidget(a)
		w.addWidget()
	case toolkit.Show:
		if (a.B) {
			w.drawView()
		} else {
			w.hideWidgets()
		}
	case toolkit.Set:
		w.Set(a.A)
	case toolkit.SetText:
		w.SetText(a.S)
	case toolkit.AddText:
		w.AddText(a.S)
	case toolkit.Move:
		log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
	default:
		log(logError, "Action() Unknown =", a.ActionType, a.WidgetType, a.Name)
	}
	log(logInfo, "Action() END")
}

func (w *cuiWidget) AddText(text string) {
	if (w == nil) {
		log(logNow, "widget is nil")
		return
	}
	w.vals = append(w.vals, text)
	for i, s := range w.vals {
		log(logNow, "AddText()", w.name, i, s)
	}
	w.SetText(text)
}

func (w *cuiWidget) SetText(text string) {
	if (w == nil) {
		log(logNow, "widget is nil")
		return
	}
	w.text = text
	w.s = text
	w.textResize()
	w.deleteView()
	w.drawView()
}

func (w *cuiWidget) Set(val any) {
	log(logInfo, "Set() value =", val)
	var a toolkit.Action
	a.ActionType = toolkit.Set

	switch v := val.(type) {
	case bool:
		w.b = val.(bool)
	case string:
		w.SetText(val.(string))
	case int:
		w.i = val.(int)
	default:
		log(logError, "Set() unknown type =", v, "a =", a)
	}
}