summaryrefslogtreecommitdiff
path: root/entry.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2019-06-02 13:40:44 -0700
committerJeff Carr <[email protected]>2019-06-02 13:40:44 -0700
commitc7402944c58285a3fd38b2b4678fdc97ada768a2 (patch)
treefdab4570083eb3e8cbdd76818528f00450e9be63 /entry.go
parent99792943c67cf580e066fe28c8b7f4796d304ce2 (diff)
finally cleaned out all protobuf references
this effort is almost done being 'cleaned' of the code I started with. This library is not perfect and lacks features from andlabs/ui but it will work for our purposes Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'entry.go')
-rw-r--r--entry.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/entry.go b/entry.go
new file mode 100644
index 0000000..423292f
--- /dev/null
+++ b/entry.go
@@ -0,0 +1,103 @@
+package gui
+
+import "log"
+import "fmt"
+
+import "github.com/andlabs/ui"
+import _ "github.com/andlabs/ui/winmanifest"
+import "github.com/davecgh/go-spew/spew"
+// import pb "git.wit.com/wit/witProtobuf"
+
+
+// THIS IS CLEAN
+
+func NewLabel(box *GuiBox, text string) {
+ box.UiBox.Append(ui.NewLabel(text), false)
+}
+
+func GetText(box *GuiBox, name string) string {
+ if (box == nil) {
+ log.Println("gui.GetText() ERROR box == nil")
+ return ""
+ }
+ if (box.Window.EntryMap == nil) {
+ log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil")
+ return ""
+ }
+ spew.Dump(box.Window.EntryMap)
+ if (box.Window.EntryMap[name] == nil) {
+ log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ")
+ return ""
+ }
+ e := box.Window.EntryMap[name]
+ log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
+ log.Println("gui.GetText() END")
+ return e.UiEntry.Text()
+}
+
+func SetText(box *GuiBox, name string, value string) error {
+ if (box == nil) {
+ return fmt.Errorf("gui.SetText() ERROR box == nil")
+ }
+ if (box.Window.EntryMap == nil) {
+ return fmt.Errorf("gui.SetText() ERROR b.Box.Window.EntryMap == nil")
+ }
+ spew.Dump(box.Window.EntryMap)
+ if (box.Window.EntryMap[name] == nil) {
+ return fmt.Errorf("gui.SetText() ERROR box.Window.EntryMap[", name, "] == nil ")
+ }
+ e := box.Window.EntryMap[name]
+ log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
+ e.UiEntry.SetText(value)
+ log.Println("gui.SetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text())
+ log.Println("gui.SetText() END")
+ return nil
+}
+
+// makeEntryBox(box, "hostname:", "blah.foo.org") {
+func MakeEntryVbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
+ // Start 'Nickname' vertical box
+ vboxN := ui.NewVerticalBox()
+ vboxN.SetPadded(true)
+ vboxN.Append(ui.NewLabel(a), false)
+
+ e := defaultMakeEntry(startValue, edit, action)
+
+ vboxN.Append(e.UiEntry, false)
+ box.UiBox.Append(vboxN, false)
+ // End 'Nickname' vertical box
+
+ return e
+}
+
+func MakeEntryHbox(box *GuiBox, a string, startValue string, edit bool, action string) *GuiEntry {
+ // Start 'Nickname' vertical box
+ hboxN := ui.NewHorizontalBox()
+ hboxN.SetPadded(true)
+ hboxN.Append(ui.NewLabel(a), false)
+
+ e := defaultMakeEntry(startValue, edit, action)
+ hboxN.Append(e.UiEntry, false)
+
+ box.UiBox.Append(hboxN, false)
+ // End 'Nickname' vertical box
+
+ return e
+}
+
+func AddEntry(box *GuiBox, name string) *GuiEntry {
+ var ge *GuiEntry
+ ge = new(GuiEntry)
+
+ ue := ui.NewEntry()
+ ue.SetReadOnly(false)
+ ue.OnChanged(func(*ui.Entry) {
+ log.Println("gui.AddEntry() OK. ue.Text() =", ue.Text())
+ })
+ box.UiBox.Append(ue, false)
+
+ ge.UiEntry = ue
+ box.Window.EntryMap[name] = ge
+
+ return ge
+}