summaryrefslogtreecommitdiff
path: root/toolkit/nocui/action.go
blob: 2e5f20b4105c7782511afe677bdf8ac09b1ebed3 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main

import (
	"git.wit.org/wit/gui/toolkit"
)

func (n *node) show(b bool) {
}

func (n *node) enable(b bool) {
}

func (n *node) pad(at toolkit.ActionType) {
	switch n.WidgetType {
	case toolkit.Group:
		switch at {
		case toolkit.Margin:
			// SetMargined(true)
		case toolkit.Unmargin:
			// SetMargined(false)
		case toolkit.Pad:
			// SetMargined(true)
		case toolkit.Unpad:
			// SetMargined(false)
		}
	case toolkit.Tab:
	case toolkit.Window:
	case toolkit.Grid:
	case toolkit.Box:
	case toolkit.Textbox:
		log(logError, "TODO: implement ActionType =", at)
	default:
		log(logError, "TODO: implement pad() for", at)
	}
}

func (n *node) move(newParent *node) {
	p := n.parent

	switch p.WidgetType {
	case toolkit.Group:
	case toolkit.Tab:
		// tabSetMargined(tParent.uiTab, true)
	case toolkit.Window:
		// t.uiWindow.SetBorderless(false)
	case toolkit.Grid:
		// t.uiGrid.SetPadded(true)
	case toolkit.Box:
		log(logInfo, "TODO: move() where =", p.ParentId)
		log(logInfo, "TODO: move() for widget =", n.WidgetId)
	default:
		log(logError, "TODO: need to implement move() for type =", n.WidgetType)
		log(logError, "TODO: need to implement move() for where =", p.ParentId)
		log(logError, "TODO: need to implement move() for widget =", n.WidgetId)
	}
}

func (n *node) Delete() {
	p := n.parent
	log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)

	switch p.WidgetType {
	case toolkit.Group:
		// tParent.uiGroup.SetMargined(true)
	case toolkit.Tab:
		// tabSetMargined(tParent.uiTab, true)
	case toolkit.Window:
		// t.uiWindow.SetBorderless(false)
	case toolkit.Grid:
		// t.uiGrid.SetPadded(true)
	case toolkit.Box:
		log(logNow, "tWidget.boxC =", p.Name)
		log(logNow, "is there a tParent parent? =", p.parent)
		// this didn't work:
		// tWidget.uiControl.Disable()
		// sleep(.8)
		// tParent.uiBox.Append(tWidget.uiControl, stretchy)
	default:
		log(logError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
		log(logError, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
	}
}

func doAction(a *toolkit.Action) {
	log(logNow, "doAction() START a.ActionType =", a.ActionType)
	log(logNow, "doAction() START a.S =", a.S)

	if (a.ActionType == toolkit.InitToolkit) {
		// TODO: make sure to only do this once
		// go uiMain.Do(func() {
		// 	ui.Main(demoUI)
			// go catchActionChannel()
		// })
		// try doing this on toolkit load in init()
		return
	}

	log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
	switch a.WidgetType {
	case toolkit.Root:
		me.rootNode = addNode(a)
		log(logNow, "doAction() found rootNode")
		return
	case toolkit.Flag:
		// flag(&a)
		return
	}

	n := me.rootNode.findWidgetId(a.WidgetId)

	switch a.ActionType {
	case toolkit.Add:
		addNode(a)
	case toolkit.Show:
		n.show(true)
	case toolkit.Hide:
		n.show(false)
	case toolkit.Enable:
		n.enable(true)
	case toolkit.Disable:
		n.enable(false)
	case toolkit.Get:
		// n.setText(a.S)
	case toolkit.GetText:
		switch a.WidgetType {
		case toolkit.Textbox:
			a.S = n.S
		}
	case toolkit.Set:
		// n.setText(a.S)
	case toolkit.SetText:
		// n.setText(a.S)
	case toolkit.AddText:
		// n.setText(a.S)
	case toolkit.Margin:
		n.pad(toolkit.Unmargin)
	case toolkit.Unmargin:
		n.pad(toolkit.Margin)
	case toolkit.Pad:
		n.pad(toolkit.Pad)
	case toolkit.Unpad:
		n.pad(toolkit.Unpad)
	case toolkit.Delete:
		n.Delete()
	case toolkit.Move:
		log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
		newParent := me.rootNode.findWidgetId(a.ParentId)
		n.move(newParent)
	default:
		log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
	}
	log(logInfo, "doAction() END =", a.ActionType, a.WidgetType)
}