summaryrefslogtreecommitdiff
path: root/entry.go
blob: 539c2f796ce2f7ca1365338835a07d5b3a66cd41 (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
package gui

import "log"
import "errors"
// import "fmt"

import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
// import "github.com/davecgh/go-spew/spew"

// functions for handling text entry boxes

func (n *Node) NewLabel(text string) *Node {
	// make new node here
newNode := n.makeNode(text, 333, 334)
	newNode.Dump()

	n.Append(newNode)
	return newNode
}

func (n *Node) SetText(value string) error {
	log.Println("gui.SetText() value =", value)
	if (n.uiText != nil) {
		n.uiText.SetText(value)
		return nil
	}
	if (n.uiButton != nil) {
		n.uiButton.SetText(value)
		return nil
	}
	if (n.uiMultilineEntry != nil) {
		n.uiMultilineEntry.SetText(value)
		return nil
	}
	n.Dump()
	return errors.New("couldn't find something to set the text to")
}

func (n *Node) SetMargined(x bool) {
	if (n.uiGroup != nil) {
		n.uiGroup.SetMargined(x)
		return
	}
	log.Println("Couldn't find something that has a Margin setting")
}

func defaultEntryChange(e *ui.Entry) {
	for key, em := range Data.AllEntries {
		if (Config.Debug) {
			log.Println("\tdefaultEntryChange() Data.AllEntries =", key, em)
		}
		if Data.AllEntries[key].UiEntry == e {
			log.Println("defaultEntryChange() FOUND", 
				"Name =", Data.AllEntries[key].Name,
				"Last =", Data.AllEntries[key].Last,
				"e.Text() =", e.Text())
			Data.AllEntries[key].Last = e.Text()
			if Data.AllEntries[key].Normalize != nil {
				fixed := Data.AllEntries[key].Normalize(e.Text())
				e.SetText(fixed)
			}
			return
		}
	}
	log.Println("defaultEntryChange() ERROR. MISSING ENTRY MAP. e.Text() =", e.Text())
}

func defaultMakeEntry(startValue string, edit bool, action string) *GuiEntry {
	e := ui.NewEntry()
	e.SetText(startValue)
	if (edit == false) {
		e.SetReadOnly(true)
	}
	e.OnChanged(defaultEntryChange)

	// add the entry field to the global map
	var newEntry GuiEntry
	newEntry.UiEntry  = e
	newEntry.Edit     = edit
	newEntry.Name     = action
	if (action == "INT") {
		newEntry.Normalize = normalizeInt
	}
	Data.AllEntries = append(Data.AllEntries, &newEntry)

	return &newEntry
}