summaryrefslogtreecommitdiff
path: root/toolkit/andlabs/textbox.go
blob: 9f7c3b4d8d570fdf4ed81fed42d65ccb7189f8b3 (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
package main

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

	"github.com/andlabs/ui"
	_ "github.com/andlabs/ui/winmanifest"
)

func newTextbox(parentW *toolkit.Widget, w *toolkit.Widget) {
	log(debugToolkit, "NewTexbox()", w.Name)

	t := mapToolkits[parentW]
	if (t == nil) {
		listMap(debugError)
		log(debugError, "newTextbox() listMap()")
		log(debugError, "FFFFFFFFFFFF listMap()")
		log(debugError, "FFFFFFFFFFFF listMap()")
	}

	// t.NewTextbox(w)
// func (t *andlabsT) NewTextbox(w *toolkit.Widget) *andlabsT {
	var newt *andlabsT
	newt = new(andlabsT)

	log(debugToolkit, "gui.Toolkit.NewTextbox()", w.Name)
	if t.broken() {
		return
	}

	c := ui.NewNonWrappingMultilineEntry()
	newt.uiMultilineEntry = c

	newt.uiBox = t.uiBox
	newt.Name = w.Name
	newt.tw = w
	if (defaultBehavior) {
		t.uiBox.Append(c, true)
	} else {
		t.uiBox.Append(c, stretchy)
	}

	/*
	// don't bother with "images" on andlabs/ui
	"image"
	"bytes"
	_ "image/png"
	"image/draw"

	if (w.Name == "image") {
		log(true, "NewTextbox() trying to add a new image")
		i := ui.NewImage(16, 16)
		img, _, err := image.Decode(bytes.NewReader(rawImage))
		if err != nil {
			panic(err)
		}
		nr, ok := img.(*image.RGBA)
		if !ok {
			i2 := image.NewRGBA(img.Bounds())
			draw.Draw(i2, i2.Bounds(), img, img.Bounds().Min, draw.Src)
			nr = i2
		}
		i.Append(nr)
		t.uiBox.Append(i, true)

		var img *ui.Image
		var icon []byte
		var imgA image.Image

		icon, _ = res.ReadFile("resources/ping6.working.png")
		// imgA, _, err := image.Decode(bytes.NewReader(b))
		imgA, _, _ = image.Decode(icon)
		img.Append(imgA)
		img.Append(icon)
	}
	*/

	c.OnChanged(func(spin *ui.MultilineEntry) {
		w.S = newt.uiMultilineEntry.Text()
		// this is still dangerous
		// newt.commonChange(newt.tw)
		log(debugChange, "Not yet safe to trigger on change for ui.MultilineEntry")
	})
	mapWidgetsToolkits(w, newt)
}


func doTextbox(p *toolkit.Widget, c *toolkit.Widget) {
	if broken(c) {
		return
	}
	if (c.Action == "New") {
		newTextbox(p, c)
		return
	}
	ct := mapToolkits[c]
	if (ct == nil) {
		log(debugError, "Trying to do something on a widget that doesn't work or doesn't exist or something", c)
		return
	}
	if ct.broken() {
		log(debugError, "Textbox() ct.broken", ct)
		return
	}
	if (ct.uiMultilineEntry == nil) {
		log(debugError, "Textbox() uiMultilineEntry == nil", ct)
		return
	}
	// the dns control panel isn't crashing anymore (?)
	Queue(ct.doSimpleAction)
}

func (t *andlabsT) doSimpleAction() {
	if (t.tw == nil) {
		log(true, "doSimpleAction() got an empty widget")
		log(true, "THIS SHOULD NEVER HAPPEN")
		panic("crap. panic. widget == nil")
	}
	log(debugChange, "Going to attempt:", t.tw.Action)
	switch  t.tw.Action {
	case "Enable":
		if (t.uiEntry != nil) {
			t.uiEntry.Enable()
		} else if (t.uiMultilineEntry != nil) {
			t.uiMultilineEntry.Enable()
		} else {
			log(debugError, "don't know what to enable", t.Name)
		}
	case "Disable":
		if (t.uiEntry != nil) {
			t.uiEntry.Disable()
		} else if (t.uiMultilineEntry != nil) {
			t.uiMultilineEntry.Disable()
		} else {
			log(debugError, "don't know what to disable", t.Name)
		}
	case "Show":
		t.uiMultilineEntry.Show()
	case "Hide":
		t.uiMultilineEntry.Hide()
	case "SetText":
		t.uiMultilineEntry.SetText(t.tw.S)
	case "Set":
		t.uiMultilineEntry.SetText(t.tw.S)
	default:
		log(debugError, "Can't do", t.tw.Action, "to a Textbox")
	}
}