From 46fe81665c20b71571023e2dd607832d725a085e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 3 Jun 2019 19:07:39 -0700 Subject: [PATCH 001/113] fixed a commit --- Makefile | 1 + debug.go | 8 ++++- gui.go | 88 +------------------------------------------------------ window.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 88 deletions(-) create mode 100644 window.go diff --git a/Makefile b/Makefile index 6353f93..2b7dd82 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ # simple sortcut to push all git changes push: + git checkout devel git pull git add --all -git commit -a -s diff --git a/debug.go b/debug.go index 1a20532..3369be6 100644 --- a/debug.go +++ b/debug.go @@ -40,7 +40,13 @@ func DumpBoxes() { log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", window.UiTab.NumPages()) - spew.Dump(window.UiTab) + // tmp := spew.NewDefaultConfig() + // tmp.MaxDepth = 2 + // tmp.Dump(window.UiTab) + if (Config.Debug) { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } } } for i, window := range Data.Windows { diff --git a/gui.go b/gui.go index ef1ff49..fca054e 100644 --- a/gui.go +++ b/gui.go @@ -1,7 +1,7 @@ package gui import "log" -import "time" +// import "time" import "regexp" import "github.com/andlabs/ui" @@ -20,80 +20,6 @@ func GuiInit() { }) } -func InitGuiWindow(name string, gw *GuiWindow) *GuiWindow { - log.Println("InitGuiWindow() START") - var newGuiWindow GuiWindow - newGuiWindow.Width = Config.Width - newGuiWindow.Height = Config.Height - newGuiWindow.Name = name - newGuiWindow.MakeWindow = gw.MakeWindow - newGuiWindow.UiWindow = gw.UiWindow - newGuiWindow.UiTab = gw.UiTab - newGuiWindow.BoxMap = make(map[string]*GuiBox) - newGuiWindow.EntryMap = make(map[string]*GuiEntry) - Data.Windows = append(Data.Windows, &newGuiWindow) - - if (Data.WindowMap == nil) { - log.Println("gui.InitGuiWindow() making the Data.WindowMap here") - Data.WindowMap = make(map[string]*GuiWindow) - } - Data.WindowMap[name] = &newGuiWindow - - // make a blank entry for testing - // newGuiWindow.EntryMap["test"] = nil - - if (Data.buttonMap == nil) { - GuiInit() - } - log.Println("InitGuiWindow() END *GuiWindow =", &newGuiWindow) - return &newGuiWindow -} - - -func StartNewWindow(bg bool, name string, callback func(*GuiWindow) *GuiBox) { - log.Println("StartNewWindow() Create a new window") - var junk GuiWindow - junk.MakeWindow = callback - window := InitGuiWindow(name, &junk) - if (bg) { - log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") - go ui.Main(func() { - log.Println("gui.StartNewWindow() inside ui.Main()") - go InitTabWindow(window) - }) - time.Sleep(2000 * time.Millisecond) // this might make it more stable on windows? - } else { - log.Println("StartNewWindow() WAITING for ui.Main()") - ui.Main(func() { - log.Println("gui.StartNewWindow() inside ui.Main()") - InitTabWindow(window) - }) - } -} - -func InitTabWindow(gw *GuiWindow) { - log.Println("InitTabWindow() START. THIS WINDOW IS NOT YET SHOWN") - - gw.UiWindow = ui.NewWindow(gw.Name, int(gw.Width), int(gw.Height), true) - gw.UiWindow.SetBorderless(false) - - gw.UiWindow.OnClosing(func(*ui.Window) bool { - log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) - ui.Quit() - return true - }) - - gw.UiTab = ui.NewTab() - gw.UiWindow.SetChild(gw.UiTab) - gw.UiWindow.SetMargined(true) - - - box := gw.MakeWindow(gw) - log.Println("InitTabWindow() END box =", box) - log.Println("InitTabWindow() END gw =", gw) - gw.UiWindow.Show() -} - /* // string handling examples that might be helpful for normalizeInt() isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString @@ -127,15 +53,3 @@ func normalizeInt(s string) string { log.Println("normalizeInt() s =", clean) return clean } - -func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { - log.Println("gui.MessageWindow() msg1 =", msg1) - log.Println("gui.MessageWindow() msg2 =", msg2) - ui.MsgBox(gw.UiWindow, msg1, msg2) -} - -func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { - log.Println("gui.ErrorWindow() msg1 =", msg1) - log.Println("gui.ErrorWindow() msg2 =", msg2) - ui.MsgBoxError(gw.UiWindow, msg1, msg2) -} diff --git a/window.go b/window.go new file mode 100644 index 0000000..0100778 --- /dev/null +++ b/window.go @@ -0,0 +1,82 @@ +package gui + +import "log" +import "time" +// import "regexp" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +func InitGuiWindow(action string, gw *GuiWindow) *GuiWindow { + log.Println("InitGuiWindow() START") + var newGuiWindow GuiWindow + newGuiWindow.Width = Config.Width + newGuiWindow.Height = Config.Height + newGuiWindow.MakeWindow = gw.MakeWindow + newGuiWindow.UiWindow = gw.UiWindow + newGuiWindow.UiTab = gw.UiTab + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + newGuiWindow.EntryMap["test"] = nil + Data.Windows = append(Data.Windows, &newGuiWindow) + + if (Data.buttonMap == nil) { + GuiInit() + } + log.Println("InitGuiWindow() END *GuiWindow =", &newGuiWindow) + return &newGuiWindow +} + + +func StartNewWindow(bg bool, action string, callback func(*GuiWindow) *GuiBox) { + log.Println("StartNewWindow() Create a new window") + var junk GuiWindow + junk.MakeWindow = callback +// junk.Action = action + window := InitGuiWindow(action, &junk) + if (bg) { + log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") + go ui.Main(func() { + log.Println("gui.StartNewWindow() inside ui.Main()") + go InitTabWindow(window) + }) + time.Sleep(2000 * time.Millisecond) // this might make it more stable on windows? + } else { + log.Println("StartNewWindow() WAITING for ui.Main()") + ui.Main(func() { + log.Println("gui.StartNewWindow() inside ui.Main()") + InitTabWindow(window) + }) + } +} + +func InitTabWindow(gw *GuiWindow) { + log.Println("InitTabWindow() START. THIS WINDOW IS NOT YET SHOWN") + + gw.UiWindow = ui.NewWindow("InitTabWindow()", int(gw.Width), int(gw.Height), true) + gw.UiWindow.SetBorderless(false) + + gw.UiWindow.OnClosing(func(*ui.Window) bool { + log.Println("InitTabWindow() OnClosing() THIS WINDOW IS CLOSING gw=", gw) + ui.Quit() + return true + }) + + gw.UiTab = ui.NewTab() + gw.UiWindow.SetChild(gw.UiTab) + gw.UiWindow.SetMargined(true) + + + box := gw.MakeWindow(gw) + log.Println("InitTabWindow() END box =", box) + log.Println("InitTabWindow() END gw =", gw) + gw.UiWindow.Show() +} + +func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBox(gw.UiWindow, msg1, msg2) +} + +func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBoxError(gw.UiWindow, msg1, msg2) +} From 534d631c983df6695cc57853aa8371e80b781fd4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 14:39:38 -0500 Subject: [PATCH 002/113] WINDOW: add CreateWindow that has proper padding Signed-off-by: Jeff Carr --- window.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/window.go b/window.go index 5dc3c9c..cc7721c 100644 --- a/window.go +++ b/window.go @@ -162,3 +162,28 @@ func DeleteWindow(name string) { } } } + +// CreateWindow("my title", "my tabname", 300, 200, makeNumbersPagewin2) +func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *ui.Window { + window := ui.NewWindow(title, x, y, false) + window.OnClosing(func(*ui.Window) bool { + log.Println("createWindow().OnClosing()", title) + return true + }) + ui.OnShouldQuit(func() bool { + log.Println("createWindow().Destroy()", title) + window.Destroy() + return true + }) + + tab := ui.NewTab() + window.SetChild(tab) + window.SetMargined(true) + + tab.Append(tabname, custom()) + tab.SetMargined(0, true) + + window.Show() + + return window +} From cfc778b04f6527f9e22beeb80c9fd0c6db99038f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 19:50:29 -0500 Subject: [PATCH 003/113] MINOR: minor change Signed-off-by: Jeff Carr --- window.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/window.go b/window.go index cc7721c..5b8da02 100644 --- a/window.go +++ b/window.go @@ -21,7 +21,7 @@ func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiB window := box.Window log.Println("StartNewWindow() box =", box) - runWindow(window.UiWindow) + window.UiWindow.Show() }) time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? } else { @@ -35,17 +35,11 @@ func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiB window := box.Window log.Println("StartNewWindow() box =", box) - runWindow(window.UiWindow) + window.UiWindow.Show() }) } } -// This creates the raw andlabs/ui Window -func runWindow(uiWindow *ui.Window) { - log.Println("runWindow() START ui.Window.Show()") - uiWindow.Show() -} - func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBox(gw.UiWindow, msg1, msg2) } @@ -81,6 +75,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Width), int(newGuiWindow.Height), true) newGuiWindow.UiWindow.SetBorderless(false) + // newGuiWindow.UiWindow.SetTitle("test") newGuiWindow.UiWindow.OnClosing(func(*ui.Window) bool { log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) // newGuiWindow.UiWindow.Destroy() From c670905b74478e572b683237c27fcd3c6838978b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 20:18:51 -0500 Subject: [PATCH 004/113] WINDOW: add function to create completely blank window Signed-off-by: Jeff Carr --- window.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/window.go b/window.go index 5b8da02..f87b27b 100644 --- a/window.go +++ b/window.go @@ -182,3 +182,30 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C return window } + +func CreateBlankWindow(title string, x int, y int) *GuiBox { + window := ui.NewWindow(title, x, y, false) + window.OnClosing(func(*ui.Window) bool { + log.Println("createWindow().OnClosing()", title) + return true + }) + ui.OnShouldQuit(func() bool { + log.Println("createWindow().Destroy()", title) + window.Destroy() + return true + }) + + window.SetMargined(true) + window.Show() + + var newGuiWindow GuiWindow + newGuiWindow.Width = x + newGuiWindow.Height = y + newGuiWindow.Name = title + newGuiWindow.UiWindow = window + + var box GuiBox + box.Window = &newGuiWindow + + return &box +} From 71a9b13236dc85acad501c1eff02f7006d4800ce Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 21:33:03 -0500 Subject: [PATCH 005/113] TAB: code to more correctly handle gtk tabs Signed-off-by: Jeff Carr --- structs.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ window.go | 7 +++++++ 2 files changed, 52 insertions(+) diff --git a/structs.go b/structs.go index 514febe..fa7c42c 100644 --- a/structs.go +++ b/structs.go @@ -1,5 +1,6 @@ package gui +import "log" import "image/color" import "golang.org/x/image/font" @@ -92,6 +93,50 @@ type GuiBox struct { UiBox *ui.Box } +func (s GuiBox) SetTitle(title string) { + log.Println("DID IT!", title) + if (s.Window == nil) { + return + } + if (s.Window.UiWindow == nil) { + return + } + s.Window.UiWindow.SetTitle(title) + return +} + +func (s GuiBox) InitTab(title string) { + if (s.Window == nil) { + return + } + if (s.Window.UiWindow == nil) { + return + } + + window := s.Window.UiWindow + tab := ui.NewTab() + window.SetChild(tab) + window.SetMargined(true) + + tab.Append(title, InitBlankWindow()) + tab.SetMargined(0, true) + + s.Window.UiTab = tab +} + +func (s GuiBox) AddTab(title string) { + if (s.Window == nil) { + return + } + if (s.Window.UiTab == nil) { + return + } + + tab := s.Window.UiTab + + tab.Append(title, InitBlankWindow()) +} + // Note: every mouse click is handled // as a 'Button' regardless of where // the user clicks it. You could probably diff --git a/window.go b/window.go index f87b27b..7c0250d 100644 --- a/window.go +++ b/window.go @@ -209,3 +209,10 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { return &box } + +func InitBlankWindow() ui.Control { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + + return hbox +} From 83c19cb61409c4aa3b86a43b44eb2fe48fb30662 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 21:54:16 -0500 Subject: [PATCH 006/113] TAB: more tab handling cleanups Signed-off-by: Jeff Carr --- structs.go | 17 +++++++++-- window-template.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 window-template.go diff --git a/structs.go b/structs.go index fa7c42c..a48f1c0 100644 --- a/structs.go +++ b/structs.go @@ -124,7 +124,7 @@ func (s GuiBox) InitTab(title string) { s.Window.UiTab = tab } -func (s GuiBox) AddTab(title string) { +func (s GuiBox) AddTab(title string, custom ui.Control) { if (s.Window == nil) { return } @@ -134,7 +134,20 @@ func (s GuiBox) AddTab(title string) { tab := s.Window.UiTab - tab.Append(title, InitBlankWindow()) + tab.Append(title, custom) +} + +func (s GuiBox) AddDemoTab(title string) { + if (s.Window == nil) { + return + } + if (s.Window.UiTab == nil) { + return + } + + tab := s.Window.UiTab + + tab.Append(title, makeWindowTemplate()) } // Note: every mouse click is handled diff --git a/window-template.go b/window-template.go new file mode 100644 index 0000000..c3e30ef --- /dev/null +++ b/window-template.go @@ -0,0 +1,72 @@ +package gui + +import "log" +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +func makeWindowTemplate() ui.Control { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + + group := ui.NewGroup("Numbers") + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + spinbox := ui.NewSpinbox(47, 100) + slider := ui.NewSlider(21, 100) + pbar := ui.NewProgressBar() + + spinbox.OnChanged(func(*ui.Spinbox) { + slider.SetValue(spinbox.Value()) + pbar.SetValue(spinbox.Value()) + }) + slider.OnChanged(func(*ui.Slider) { + spinbox.SetValue(slider.Value()) + pbar.SetValue(slider.Value()) + }) + vbox.Append(spinbox, false) + vbox.Append(slider, false) + vbox.Append(pbar, false) + + ip := ui.NewProgressBar() + ip.SetValue(-1) + vbox.Append(ip, false) + + group = ui.NewGroup("Lists") + group.SetMargined(true) + hbox.Append(group, true) + + vbox = ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + cbox := ui.NewCombobox() + cbox.Append("Combobox Item 1") + cbox.Append("Combobox Item 2") + cbox.Append("Combobox Item 3") + vbox.Append(cbox, false) + + ecbox := ui.NewEditableCombobox() + ecbox.Append("Editable Item 1") + ecbox.Append("Editable Item 2") + ecbox.Append("Editable Item 3") + vbox.Append(ecbox, false) + + ecbox.OnChanged(func(*ui.EditableCombobox) { + log.Println("test") + test := ecbox.Text() + log.Println("test=", test) + }) + + rb := ui.NewRadioButtons() + rb.Append("Radio Button 1") + rb.Append("Radio Button 2") + rb.Append("Radio Button 3") + vbox.Append(rb, false) + + return hbox +} From e6c44cd2d39413707d348fbcd1202865bb365aa2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Oct 2021 23:38:45 -0500 Subject: [PATCH 007/113] ANALABS: work on improving the abstraction Signed-off-by: Jeff Carr --- structs.go | 22 ++++++++++++++++++---- window.go | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/structs.go b/structs.go index a48f1c0..e5e8520 100644 --- a/structs.go +++ b/structs.go @@ -137,17 +137,31 @@ func (s GuiBox) AddTab(title string, custom ui.Control) { tab.Append(title, custom) } -func (s GuiBox) AddDemoTab(title string) { +func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { if (s.Window == nil) { - return + return nil } if (s.Window.UiTab == nil) { - return + return nil } tab := s.Window.UiTab + tab.Append(title, custom) + return tab +} - tab.Append(title, makeWindowTemplate()) +func (s GuiBox) AddBoxTab(title string) *GuiBox { + uiTab := s.AddTab2(title, InitBlankWindow()) + + var box *GuiBox + box = HardBox(s.Window, Xaxis, "jcarrAddBoxTab") + box.Window.UiTab = uiTab + return box + +} + +func (s GuiBox) AddDemoTab(title string) { + s.AddTab(title, makeWindowTemplate()) } // Note: every mouse click is handled diff --git a/window.go b/window.go index 7c0250d..2bd9291 100644 --- a/window.go +++ b/window.go @@ -204,6 +204,11 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { newGuiWindow.Name = title newGuiWindow.UiWindow = window + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + + Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + var box GuiBox box.Window = &newGuiWindow From 90d8111ada3787d802b20baf4452f2501ba49fae Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 02:00:32 -0500 Subject: [PATCH 008/113] TAB: automatically set all tables to SetMargined(true) Signed-off-by: Jeff Carr --- structs.go | 13 +++++++++++-- window.go | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/structs.go b/structs.go index e5e8520..50784fa 100644 --- a/structs.go +++ b/structs.go @@ -120,6 +120,7 @@ func (s GuiBox) InitTab(title string) { tab.Append(title, InitBlankWindow()) tab.SetMargined(0, true) + // tab.SetMargined(1, true) s.Window.UiTab = tab } @@ -153,17 +154,25 @@ func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { func (s GuiBox) AddBoxTab(title string) *GuiBox { uiTab := s.AddTab2(title, InitBlankWindow()) + tabSetMargined(uiTab) var box *GuiBox box = HardBox(s.Window, Xaxis, "jcarrAddBoxTab") box.Window.UiTab = uiTab - return box - + return box } func (s GuiBox) AddDemoTab(title string) { s.AddTab(title, makeWindowTemplate()) } +func tabSetMargined(tab *ui.Tab) { + c := tab.NumPages() + for i := 0; i < c; i++ { + log.Println("tabSetMargined() i =", i) + tab.SetMargined(i, true) + } +} + // Note: every mouse click is handled // as a 'Button' regardless of where // the user clicks it. You could probably diff --git a/window.go b/window.go index 2bd9291..c6c623f 100644 --- a/window.go +++ b/window.go @@ -161,6 +161,7 @@ func DeleteWindow(name string) { // CreateWindow("my title", "my tabname", 300, 200, makeNumbersPagewin2) func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *ui.Window { window := ui.NewWindow(title, x, y, false) + window.SetBorderless(false) window.OnClosing(func(*ui.Window) bool { log.Println("createWindow().OnClosing()", title) return true @@ -185,6 +186,7 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C func CreateBlankWindow(title string, x int, y int) *GuiBox { window := ui.NewWindow(title, x, y, false) + window.SetBorderless(false) window.OnClosing(func(*ui.Window) bool { log.Println("createWindow().OnClosing()", title) return true From 6f88d8fbf5a340fa17949e351197979162b10d75 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 05:52:50 -0500 Subject: [PATCH 009/113] DEBUG: gui to debug windows Signed-off-by: Jeff Carr --- structs.go | 24 +++++++++----- window-debug.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 window-debug.go diff --git a/structs.go b/structs.go index 50784fa..cc1a421 100644 --- a/structs.go +++ b/structs.go @@ -105,12 +105,12 @@ func (s GuiBox) SetTitle(title string) { return } -func (s GuiBox) InitTab(title string) { +func (s GuiBox) InitTab(title string) *ui.Tab { if (s.Window == nil) { - return + return nil } if (s.Window.UiWindow == nil) { - return + return nil } window := s.Window.UiWindow @@ -123,19 +123,21 @@ func (s GuiBox) InitTab(title string) { // tab.SetMargined(1, true) s.Window.UiTab = tab + return tab } -func (s GuiBox) AddTab(title string, custom ui.Control) { +func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { if (s.Window == nil) { - return + return nil } if (s.Window.UiTab == nil) { - return + return nil } tab := s.Window.UiTab tab.Append(title, custom) + return tab } func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { @@ -153,8 +155,8 @@ func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { func (s GuiBox) AddBoxTab(title string) *GuiBox { uiTab := s.AddTab2(title, InitBlankWindow()) - tabSetMargined(uiTab) + var box *GuiBox box = HardBox(s.Window, Xaxis, "jcarrAddBoxTab") box.Window.UiTab = uiTab @@ -162,7 +164,13 @@ func (s GuiBox) AddBoxTab(title string) *GuiBox { } func (s GuiBox) AddDemoTab(title string) { - s.AddTab(title, makeWindowTemplate()) + uiTab := s.AddTab(title, makeWindowTemplate()) + tabSetMargined(uiTab) +} + +func (s GuiBox) AddDebugTab(title string) { + uiTab := s.AddTab(title, makeWindowDebug()) + tabSetMargined(uiTab) } func tabSetMargined(tab *ui.Tab) { diff --git a/window-debug.go b/window-debug.go new file mode 100644 index 0000000..874b83e --- /dev/null +++ b/window-debug.go @@ -0,0 +1,83 @@ +package gui + +import "log" +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +var names = make([]string, 100) + +func makeWindowDebug() ui.Control { + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + + group := ui.NewGroup("Numbers") + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + spinbox := ui.NewSpinbox(22, 44) + slider := ui.NewSlider(22, 44) + pbar := ui.NewProgressBar() + + spinbox.OnChanged(func(*ui.Spinbox) { + slider.SetValue(spinbox.Value()) + pbar.SetValue(spinbox.Value()) + }) + slider.OnChanged(func(*ui.Slider) { + spinbox.SetValue(slider.Value()) + pbar.SetValue(slider.Value()) + }) + vbox.Append(spinbox, false) + vbox.Append(slider, false) + vbox.Append(pbar, false) + + ip := ui.NewProgressBar() + ip.SetValue(-1) + vbox.Append(ip, false) + + group = ui.NewGroup("WindowMap") + group.SetMargined(true) + hbox.Append(group, true) + + vbox = ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + cbox := ui.NewCombobox() + addName(cbox, "Window 1") + addName(cbox, "Window 2") + addName(cbox, "Combobox Item 3") + vbox.Append(cbox, false) + + cbox.OnSelected(func(*ui.Combobox) { + log.Println("test") + test := cbox.Selected() + log.Println("test=", test) + log.Println("names[test] =", names[test]) + +// for name := range names { +// log.Println("gui.DumpBoxes() name: ", name) +// } +// if (names[test] != nil) { +// } + }) + + for name, _ := range Data.WindowMap { + log.Println("gui.DumpBoxes() name: ", name) + addName(cbox, name) + } + + return hbox +} + +var x int = 0 + +func addName(c *ui.Combobox, s string) { + c.Append(s) + names[x] = s + x = x + 1 +} From 69956385dad7642cce3f2063d446ee4332fa6782 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 06:25:32 -0500 Subject: [PATCH 010/113] DEBUG: list out all the known windows Signed-off-by: Jeff Carr --- window-debug.go | 120 +++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 52 deletions(-) diff --git a/window-debug.go b/window-debug.go index 874b83e..14f0bef 100644 --- a/window-debug.go +++ b/window-debug.go @@ -4,73 +4,42 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +import "github.com/davecgh/go-spew/spew" + var names = make([]string, 100) func makeWindowDebug() ui.Control { - hbox := ui.NewHorizontalBox() hbox.SetPadded(true) - group := ui.NewGroup("Numbers") - group.SetMargined(true) - hbox.Append(group, true) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - group.SetChild(vbox) - - spinbox := ui.NewSpinbox(22, 44) - slider := ui.NewSlider(22, 44) - pbar := ui.NewProgressBar() - - spinbox.OnChanged(func(*ui.Spinbox) { - slider.SetValue(spinbox.Value()) - pbar.SetValue(spinbox.Value()) - }) - slider.OnChanged(func(*ui.Slider) { - spinbox.SetValue(slider.Value()) - pbar.SetValue(slider.Value()) - }) - vbox.Append(spinbox, false) - vbox.Append(slider, false) +///////////////////////////////////////////////////// + vbox := addGroup(hbox, "Numbers") + pbar := ui.NewProgressBar() vbox.Append(pbar, false) - ip := ui.NewProgressBar() - ip.SetValue(-1) - vbox.Append(ip, false) - - group = ui.NewGroup("WindowMap") - group.SetMargined(true) - hbox.Append(group, true) - - vbox = ui.NewVerticalBox() - vbox.SetPadded(true) - group.SetChild(vbox) +///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Buttons") + pbar = ui.NewProgressBar() + vbox.Append(pbar, false) +///////////////////////////////////////////////////// + vbox = addGroup(hbox, "WindowMap") cbox := ui.NewCombobox() - addName(cbox, "Window 1") - addName(cbox, "Window 2") - addName(cbox, "Combobox Item 3") + + for name, _ := range Data.WindowMap { + log.Println("range Data.WindowMap() name =", name) + addName(cbox, name) + } + vbox.Append(cbox, false) cbox.OnSelected(func(*ui.Combobox) { - log.Println("test") - test := cbox.Selected() - log.Println("test=", test) - log.Println("names[test] =", names[test]) - -// for name := range names { -// log.Println("gui.DumpBoxes() name: ", name) -// } -// if (names[test] != nil) { -// } + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) }) - for name, _ := range Data.WindowMap { - log.Println("gui.DumpBoxes() name: ", name) - addName(cbox, name) - } - return hbox } @@ -81,3 +50,50 @@ func addName(c *ui.Combobox, s string) { names[x] = s x = x + 1 } + +func addGroup(hb *ui.Box, name string) *ui.Box{ + group := ui.NewGroup(name) + group.SetMargined(true) + hb.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + return vbox +} + +func dumpBox(s string) { + for name, window := range Data.WindowMap { + if (name != s) { + continue + } + log.Println("gui.DumpBoxes() MAP: ", name) + if (window.TabNumber == nil) { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + if (name == "MAINBOX") { + if (Config.Debug) { + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(abox.UiBox) + } + } + } + if (window.UiTab != nil) { + pages := window.UiTab.NumPages() + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) + tabSetMargined(window.UiTab) + if (Config.Debug) { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } + } + } +} From fa17b1c009122c1a0893de9a4f5003221b655d11 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 06:46:46 -0500 Subject: [PATCH 011/113] DEBUG: add buttons to dump struct info Signed-off-by: Jeff Carr --- window-debug.go | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/window-debug.go b/window-debug.go index 14f0bef..553d74c 100644 --- a/window-debug.go +++ b/window-debug.go @@ -17,11 +17,6 @@ func makeWindowDebug() ui.Control { pbar := ui.NewProgressBar() vbox.Append(pbar, false) -///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Buttons") - pbar = ui.NewProgressBar() - vbox.Append(pbar, false) - ///////////////////////////////////////////////////// vbox = addGroup(hbox, "WindowMap") cbox := ui.NewCombobox() @@ -40,6 +35,20 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) +///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Buttons") + b1 := addButton(vbox, "dumpBox(name)") + b1.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) + }) + b2 := addButton(vbox, "something 2") + b2.OnClicked(func(*ui.Button) { + log.Println("Should do something here b2") + }) + return hbox } @@ -51,10 +60,10 @@ func addName(c *ui.Combobox, s string) { x = x + 1 } -func addGroup(hb *ui.Box, name string) *ui.Box{ +func addGroup(b *ui.Box, name string) *ui.Box { group := ui.NewGroup(name) group.SetMargined(true) - hb.Append(group, true) + b.Append(group, true) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -97,3 +106,14 @@ func dumpBox(s string) { } } } + +func addButton(box *ui.Box, name string) *ui.Button { + button := ui.NewButton(name) + + button.OnClicked(func(*ui.Button) { + log.Println("Should do something here") + }) + + box.Append(button, false) + return button +} From 6035dc8d797c98b85142b15a87a0f4b2e830a457 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 07:13:24 -0500 Subject: [PATCH 012/113] DEBUG: added button to SetMargin() by name Signed-off-by: Jeff Carr --- debug.go | 1 + structs.go | 2 +- window-debug.go | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/debug.go b/debug.go index ec60df2..4253306 100644 --- a/debug.go +++ b/debug.go @@ -41,6 +41,7 @@ func DumpBoxes() { log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if (name == "MAINBOX") { diff --git a/structs.go b/structs.go index cc1a421..d1a1680 100644 --- a/structs.go +++ b/structs.go @@ -177,7 +177,7 @@ func tabSetMargined(tab *ui.Tab) { c := tab.NumPages() for i := 0; i < c; i++ { log.Println("tabSetMargined() i =", i) - tab.SetMargined(i, true) + // tab.SetMargined(i, true) } } diff --git a/window-debug.go b/window-debug.go index 553d74c..7702da3 100644 --- a/window-debug.go +++ b/window-debug.go @@ -37,6 +37,7 @@ func makeWindowDebug() ui.Control { ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Buttons") + b1 := addButton(vbox, "dumpBox(name)") b1.OnClicked(func(*ui.Button) { x := cbox.Selected() @@ -44,9 +45,28 @@ func makeWindowDebug() ui.Control { log.Println("names[x] =", names[x]) dumpBox(names[x]) }) - b2 := addButton(vbox, "something 2") + + b2 := addButton(vbox, "SetMargined()") b2.OnClicked(func(*ui.Button) { - log.Println("Should do something here b2") + x := cbox.Selected() + log.Println("x =", x) + log.Println("findBox; names[x] =", names[x]) + findBox(names[x]) + gw := findBox(names[x]) + if (gw == nil) { + return + } + if (gw.UiTab == nil) { + return + } + if (gw.TabNumber == nil) { + return + } + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(gw) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab) + log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber) + gw.UiTab.SetMargined(*gw.TabNumber, true) }) return hbox @@ -72,6 +92,15 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } +func findBox(s string) *GuiWindow { + for name, window := range Data.WindowMap { + if (name == s) { + return window + } + } + return nil +} + func dumpBox(s string) { for name, window := range Data.WindowMap { if (name != s) { @@ -86,6 +115,7 @@ func dumpBox(s string) { log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if (name == "MAINBOX") { From 6438e4cc6acefac7a4e9bdd6fdfde98255a9a783 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 09:29:55 -0500 Subject: [PATCH 013/113] CODE: not sure, but it compiles and runs somehow Signed-off-by: Jeff Carr --- structs.go | 4 +-- window.go | 94 +++++++++++++++++++++--------------------------------- 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/structs.go b/structs.go index d1a1680..0f1cd1b 100644 --- a/structs.go +++ b/structs.go @@ -118,7 +118,7 @@ func (s GuiBox) InitTab(title string) *ui.Tab { window.SetChild(tab) window.SetMargined(true) - tab.Append(title, InitBlankWindow()) + tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) // tab.SetMargined(1, true) @@ -154,7 +154,7 @@ func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { } func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab2(title, InitBlankWindow()) + uiTab := s.AddTab2(title, initBlankWindow()) tabSetMargined(uiTab) var box *GuiBox diff --git a/window.go b/window.go index c6c623f..e170278 100644 --- a/window.go +++ b/window.go @@ -7,36 +7,27 @@ import "time" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +func initUI(name string, callback func(*GuiBox) *GuiBox) { + ui.Main(func() { + log.Println("gui.initUI() inside ui.Main()") + + box := InitWindow(nil, "StartNewWindow" + name, 0) + box = callback(box) + window := box.Window + log.Println("StartNewWindow() box =", box) + + window.UiWindow.Show() + }) +} + func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { - log.Println("StartNewWindow() Create a new window") + log.Println("StartNewWindow() ui.Main() Create a new window") if (bg) { - log.Println("StartNewWindow() START NEW GOROUTINE for ui.Main()") - go ui.Main(func() { - log.Println("gui.StartNewWindow() inside ui.Main() in NEW goroutine") - - // InitWindow must be called from within ui.Main() - box := InitWindow(nil, name, axis) - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) - - window.UiWindow.Show() - }) + go initUI(name, callback) time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? } else { - log.Println("StartNewWindow() WAITING for ui.Main()") - ui.Main(func() { - log.Println("gui.StartNewWindow() inside ui.Main()") - - // InitWindow must be called from within ui.Main() - box := InitWindow(nil, name, axis) - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) - - window.UiWindow.Show() - }) + initUI(name, callback) } } @@ -62,6 +53,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { return nil } + // return mapWindow(window, name, Config.Height, Config.Width) log.Println("InitGuiWindow() START") var newGuiWindow GuiWindow newGuiWindow.Height = Config.Height @@ -98,7 +90,6 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.UiTab = gw.UiTab } - newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) // Data.Windows = append(Data.Windows, &newGuiWindow) @@ -158,30 +149,10 @@ func DeleteWindow(name string) { } } -// CreateWindow("my title", "my tabname", 300, 200, makeNumbersPagewin2) -func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *ui.Window { - window := ui.NewWindow(title, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", title) - return true - }) - ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", title) - window.Destroy() - return true - }) - - tab := ui.NewTab() - window.SetChild(tab) - window.SetMargined(true) - - tab.Append(tabname, custom()) - tab.SetMargined(0, true) - - window.Show() - - return window +func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *GuiBox { + box := CreateBlankWindow(title, x, y) + box.InitTab(title) + return box } func CreateBlankWindow(title string, x int, y int) *GuiBox { @@ -200,6 +171,17 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { window.SetMargined(true) window.Show() + return mapWindow(window, title, x, y) +} + +func initBlankWindow() ui.Control { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + + return hbox +} + +func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y @@ -209,6 +191,11 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) + if (Data.WindowMap[newGuiWindow.Name] != nil) { + log.Println("Data.WindowMap[newGuiWindow.Name] already exists\n") + panic("Data.WindowMap[newGuiWindow.Name] already exists") + return nil + } Data.WindowMap[newGuiWindow.Name] = &newGuiWindow var box GuiBox @@ -216,10 +203,3 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { return &box } - -func InitBlankWindow() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - return hbox -} From 6d401ea14ad7351a6dcacf2b6d1bcd695fdcc470 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 09:42:30 -0500 Subject: [PATCH 014/113] DEBUG: add Hide(), Show() and Delete() for *ui.Tab Signed-off-by: Jeff Carr --- window-debug.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/window-debug.go b/window-debug.go index 7702da3..92ed9c6 100644 --- a/window-debug.go +++ b/window-debug.go @@ -69,6 +69,57 @@ func makeWindowDebug() ui.Control { gw.UiTab.SetMargined(*gw.TabNumber, true) }) + b3 := addButton(vbox, "Hide()") + b3.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("findBox; names[x] =", names[x]) + findBox(names[x]) + gw := findBox(names[x]) + if (gw == nil) { + return + } + if (gw.UiTab == nil) { + return + } + gw.UiTab.Hide() + }) + + b4 := addButton(vbox, "Show()") + b4.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("findBox; names[x] =", names[x]) + findBox(names[x]) + gw := findBox(names[x]) + if (gw == nil) { + return + } + if (gw.UiTab == nil) { + return + } + gw.UiTab.Show() + }) + + b5 := addButton(vbox, "Delete()") + b5.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("findBox; names[x] =", names[x]) + findBox(names[x]) + gw := findBox(names[x]) + if (gw == nil) { + return + } + if (gw.UiTab == nil) { + return + } + if (gw.TabNumber == nil) { + return + } + gw.UiTab.Delete(*gw.TabNumber) + }) + return hbox } From ccb91460cabdd0135ace5b4a0889bc9a3d5cdb2a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 10:23:27 -0500 Subject: [PATCH 015/113] BUG: fix potential 'nil' reference Signed-off-by: Jeff Carr --- box.go | 6 ++++++ entry.go | 2 +- structs.go | 7 +++++++ window.go | 50 +++++++++++++++++++++++--------------------------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/box.go b/box.go index 08d4918..2640742 100644 --- a/box.go +++ b/box.go @@ -120,6 +120,12 @@ func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { func HorizontalBreak(box *GuiBox) { log.Println("VerticalSeparator added to box =", box.Name) tmp := ui.NewHorizontalSeparator() + if (box == nil) { + return + } + if (box.UiBox == nil) { + return + } box.UiBox.Append(tmp, false) } diff --git a/entry.go b/entry.go index db5013a..d7f31c9 100644 --- a/entry.go +++ b/entry.go @@ -10,7 +10,7 @@ import "github.com/davecgh/go-spew/spew" // functions for handling text entry boxes func NewLabel(box *GuiBox, text string) { - box.UiBox.Append(ui.NewLabel(text), false) + box.Append(ui.NewLabel(text), false) } func GetText(box *GuiBox, name string) string { diff --git a/structs.go b/structs.go index 0f1cd1b..59190f6 100644 --- a/structs.go +++ b/structs.go @@ -105,6 +105,13 @@ func (s GuiBox) SetTitle(title string) { return } +func (s GuiBox) Append(child ui.Control, x bool) { + if (s.UiBox == nil) { + return + } + s.UiBox.Append(child, x) +} + func (s GuiBox) InitTab(title string) *ui.Tab { if (s.Window == nil) { return nil diff --git a/window.go b/window.go index e170278..e64e10b 100644 --- a/window.go +++ b/window.go @@ -45,21 +45,17 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // actual window but that does not appear to work on the MacOS or Windows // func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { - window := Data.WindowMap[name] - if (window != nil) { - box := window.BoxMap["MAINBOX"] - log.Println("gui.InitWindow() tab already exists name =", name) - ErrorWindow(box.Window, "Create Window Error", "Window " + name + " already exists") - return nil + log.Println("InitGuiWindow() START") + + var box *GuiBox + if (gw == nil) { + box = mapWindow(nil, name, Config.Height, Config.Width) + } else { + box = mapWindow(gw.UiWindow, name, Config.Height, Config.Width) } - // return mapWindow(window, name, Config.Height, Config.Width) - log.Println("InitGuiWindow() START") - var newGuiWindow GuiWindow - newGuiWindow.Height = Config.Height - newGuiWindow.Width = Config.Width - newGuiWindow.Axis = axis - newGuiWindow.Name = name + // box.Window = &newGuiWindow + newGuiWindow := box.Window // This is the first window. One must create it here if (gw == nil) { @@ -75,7 +71,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { ui.Quit() } else { // allow a custom exit function - Config.Exit(&newGuiWindow) + Config.Exit(newGuiWindow) } return true }) @@ -102,15 +98,9 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.TabNumber = &tabnum } - Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + Data.WindowMap[newGuiWindow.Name] = newGuiWindow - var box *GuiBox - if (axis == Xaxis) { - box = HardBox(&newGuiWindow, Xaxis, name) - } else { - box = HardBox(&newGuiWindow, Yaxis, name) - } - log.Println("InitGuiWindow() END *GuiWindow =", &newGuiWindow) + log.Println("InitGuiWindow() END *GuiWindow =", newGuiWindow) return box } @@ -181,7 +171,18 @@ func initBlankWindow() ui.Control { return hbox } +var master = 0 + func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { + if (Data.WindowMap[title] != nil) { + log.Println("Data.WindowMap[title] already exists title =", title) + title = title + string(master) + } + if (Data.WindowMap[title] != nil) { + log.Println("Data.WindowMap[title] already exists title =", title) + panic("Data.WindowMap[newGuiWindow.Name] already exists") + return nil + } var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y @@ -191,11 +192,6 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) - if (Data.WindowMap[newGuiWindow.Name] != nil) { - log.Println("Data.WindowMap[newGuiWindow.Name] already exists\n") - panic("Data.WindowMap[newGuiWindow.Name] already exists") - return nil - } Data.WindowMap[newGuiWindow.Name] = &newGuiWindow var box GuiBox From 9dc8d790623f8b52e75f959244911c78ecb19265 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 5 Oct 2021 10:37:53 -0500 Subject: [PATCH 016/113] DEBUG: add DumpMap() Signed-off-by: Jeff Carr --- button.go | 4 ++-- debug.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/button.go b/button.go index 24dcd49..825b79b 100644 --- a/button.go +++ b/button.go @@ -68,7 +68,7 @@ func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values inte Data.AllButtons = append(Data.AllButtons, newB) - box.UiBox.Append(newB.B, false) + box.Append(newB.B, false) return newB } @@ -110,6 +110,6 @@ func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values Data.MouseClick(&newCB) } }) - box.UiBox.Append(newCB.CB, false) + box.Append(newCB.CB, false) return &newCB } diff --git a/debug.go b/debug.go index 4253306..75f5424 100644 --- a/debug.go +++ b/debug.go @@ -30,6 +30,12 @@ func WatchGUI() { } } +func DumpMap() { + for name, _ := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + } +} + func DumpBoxes() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) From facc7857981cae94a991a4c8dd378274ace34372 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 01:52:27 -0500 Subject: [PATCH 017/113] BUG: fix WxH Signed-off-by: Jeff Carr --- window.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/window.go b/window.go index e64e10b..da4f1a8 100644 --- a/window.go +++ b/window.go @@ -2,6 +2,7 @@ package gui import "log" import "time" +import "strconv" // import "regexp" import "github.com/andlabs/ui" @@ -60,7 +61,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if (gw == nil) { log.Println("initWindow() ADDING ui.NewWindow()") - newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Width), int(newGuiWindow.Height), true) + newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Height), int(newGuiWindow.Width), true) newGuiWindow.UiWindow.SetBorderless(false) // newGuiWindow.UiWindow.SetTitle("test") @@ -146,14 +147,16 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C } func CreateBlankWindow(title string, x int, y int) *GuiBox { - window := ui.NewWindow(title, x, y, false) + box := mapWindow(nil, title, x, y) + + window := ui.NewWindow(box.Name, x, y, false) window.SetBorderless(false) window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", title) + log.Println("createWindow().OnClosing()", box.Name) return true }) ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", title) + log.Println("createWindow().Destroy()", box.Name) window.Destroy() return true }) @@ -161,7 +164,8 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { window.SetMargined(true) window.Show() - return mapWindow(window, title, x, y) + box.Window.UiWindow = window + return box } func initBlankWindow() ui.Control { @@ -176,7 +180,8 @@ var master = 0 func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { if (Data.WindowMap[title] != nil) { log.Println("Data.WindowMap[title] already exists title =", title) - title = title + string(master) + master = master + 1 + title = title + " jcarr " + strconv.Itoa(master) } if (Data.WindowMap[title] != nil) { log.Println("Data.WindowMap[title] already exists title =", title) From e7e7080825581da548854f71cc51fe35785c1c5b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 02:02:39 -0500 Subject: [PATCH 018/113] BUILD: remove old rules that don't work anymore Signed-off-by: Jeff Carr --- Makefile | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 2b7dd82..31212b9 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,4 @@ -# simple sortcut to push all git changes -push: - git checkout devel - git pull - git add --all - -git commit -a -s - git push - # should update every go dependancy (?) update: git pull - go get -v -t -u ./... - -merge-devel: - git checkout master - git pull origin master - git merge devel - git push origin master - git checkout devel + GO111MODULE="off" go get -v -t -u ./... From cabdb12495011260c9edb3e694208cef1115d665 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 05:14:24 -0500 Subject: [PATCH 019/113] BUILD: suck it up and try to use go.mod Signed-off-by: Jeff Carr --- Makefile | 5 +++-- go.mod | 9 +++++++++ go.sum | 8 ++++++++ structs.go | 6 ++++++ window.go | 4 ++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 go.mod create mode 100644 go.sum diff --git a/Makefile b/Makefile index 31212b9..df5d201 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ # should update every go dependancy (?) update: - git pull - GO111MODULE="off" go get -v -t -u ./... + # git pull + wit go update + # go get -v -t -u ./... diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c72bbca --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module git.wit.org/wit/gui + +go 1.17 + +require ( + github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e + github.com/davecgh/go-spew v1.1.1 + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..27ff5d2 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU= +github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/structs.go b/structs.go index 59190f6..ac67588 100644 --- a/structs.go +++ b/structs.go @@ -44,6 +44,12 @@ type GuiData struct { buttonMap map[*ui.Button]*GuiButton } +type GuiTab struct { + Name string // field for human readable name + Number int // the andlabs/ui tab index + Window *GuiWindow // the parent Window +} + // // stores information on the 'window' // diff --git a/window.go b/window.go index da4f1a8..a6c5b4f 100644 --- a/window.go +++ b/window.go @@ -148,6 +148,7 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C func CreateBlankWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) + log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) window := ui.NewWindow(box.Name, x, y, false) window.SetBorderless(false) @@ -178,6 +179,7 @@ func initBlankWindow() ui.Control { var master = 0 func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { + log.Println("gui.WindowMap START title =", title) if (Data.WindowMap[title] != nil) { log.Println("Data.WindowMap[title] already exists title =", title) master = master + 1 @@ -188,6 +190,7 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { panic("Data.WindowMap[newGuiWindow.Name] already exists") return nil } + log.Println("gui.WindowMap START title =", title) var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y @@ -201,6 +204,7 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { var box GuiBox box.Window = &newGuiWindow + box.Name = title return &box } From b4a11c0aa1c14504121adbdbf02f418e7969d3f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 08:36:28 -0500 Subject: [PATCH 020/113] CODE: start a general code refactor Signed-off-by: Jeff Carr --- main.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ new-structs.go | 29 +++++++++++++++++++++++++++++ structs.go | 1 + window-debug.go | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 main.go create mode 100644 new-structs.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..eb9bdb4 --- /dev/null +++ b/main.go @@ -0,0 +1,46 @@ +package gui + +import "log" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +func Main(f func()) { + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") + ui.Main(f) +} + +// Other goroutines must use this +// +// You can not acess / process the GUI thread directly from +// other goroutines. This is due to the nature of how +// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) +// For example: gui.Queue(addNewTabForColorSelection()) +func Queue(f func()) { + log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)") + ui.QueueMain(f) +} + +// gui.Main( +// gui.MainExample() +// ) +func MainExample() { + name := "jcarr" + log.Println("gui.initUI() inside ui.Main()") + + box := InitWindow(nil, "StartNewWindow" + name, 0) + window := box.Window + log.Println("StartNewWindow() box =", box) + + window.UiWindow.Show() +} + +func TestExample() { + log.Println("gui.initUI() inside ui.Main()") + + box := InitWindow(nil, "test", 0) + window := box.Window + log.Println("StartNewWindow() box =", box) + + window.UiWindow.Show() +} diff --git a/new-structs.go b/new-structs.go new file mode 100644 index 0000000..8d65147 --- /dev/null +++ b/new-structs.go @@ -0,0 +1,29 @@ +package gui + +import "log" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +type Node struct { + Name string + tag string + Width int + Height int + + uiType *ui.Control + Children []*Node +} + +func (n Node) SetName(name string) { + // n.uiType.SetName(name) + log.Println("n.uiType =", n.uiType) + return +} + +func (n Node) Append(child Node) { +// if (n.UiBox == nil) { +// return +// } + // n.uiType.Append(child, x) +} diff --git a/structs.go b/structs.go index ac67588..6387b45 100644 --- a/structs.go +++ b/structs.go @@ -42,6 +42,7 @@ type GuiData struct { // andlabs/ui & andlabs/libui work AllButtons []*GuiButton buttonMap map[*ui.Button]*GuiButton + Nodes *Node } type GuiTab struct { diff --git a/window-debug.go b/window-debug.go index 92ed9c6..6d757a2 100644 --- a/window-debug.go +++ b/window-debug.go @@ -18,7 +18,7 @@ func makeWindowDebug() ui.Control { vbox.Append(pbar, false) ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "WindowMap") + vbox = addGroup(hbox, "WindowMap 2") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { From 790e6f2c4614a4a8deaad275ec0e3d9fb201d6e6 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 10:43:58 -0500 Subject: [PATCH 021/113] REFACTOR: continue to move in a better direction Signed-off-by: Jeff Carr --- main.go | 25 +++++++------- window.go | 98 +++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 75 insertions(+), 48 deletions(-) diff --git a/main.go b/main.go index eb9bdb4..5e4d1b4 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package gui -import "log" +import ( + "log" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) func Main(f func()) { log.Println("Starting gui.Main() (using gtk via andlabs/ui)") @@ -13,7 +15,7 @@ func Main(f func()) { // Other goroutines must use this // // You can not acess / process the GUI thread directly from -// other goroutines. This is due to the nature of how +// other goroutines. This is due to the nature of how // Linux, MacOS and Windows work (they all work differently. suprise. surprise.) // For example: gui.Queue(addNewTabForColorSelection()) func Queue(f func()) { @@ -21,16 +23,15 @@ func Queue(f func()) { ui.QueueMain(f) } -// gui.Main( -// gui.MainExample() -// ) -func MainExample() { - name := "jcarr" - log.Println("gui.initUI() inside ui.Main()") +// gui.Main(gui.MainExample()) +func ExampleWindow() { + log.Println("START gui.ExampleWindow()") - box := InitWindow(nil, "StartNewWindow" + name, 0) + title := "Test Window" + box := InitWindow(nil, title, 0) window := box.Window - log.Println("StartNewWindow() box =", box) + log.Println("box =", box) + log.Println("window =", window) window.UiWindow.Show() } diff --git a/window.go b/window.go index a6c5b4f..1dfe05a 100644 --- a/window.go +++ b/window.go @@ -1,18 +1,22 @@ package gui -import "log" -import "time" -import "strconv" -// import "regexp" +import ( + "log" + "strconv" + "time" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + + // import "regexp" + + _ "github.com/andlabs/ui/winmanifest" +) func initUI(name string, callback func(*GuiBox) *GuiBox) { ui.Main(func() { log.Println("gui.initUI() inside ui.Main()") - box := InitWindow(nil, "StartNewWindow" + name, 0) + box := InitWindow(nil, "StartNewWindow"+name, 0) box = callback(box) window := box.Window log.Println("StartNewWindow() box =", box) @@ -24,7 +28,7 @@ func initUI(name string, callback func(*GuiBox) *GuiBox) { func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { log.Println("StartNewWindow() ui.Main() Create a new window") - if (bg) { + if bg { go initUI(name, callback) time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? } else { @@ -49,7 +53,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { log.Println("InitGuiWindow() START") var box *GuiBox - if (gw == nil) { + if gw == nil { box = mapWindow(nil, name, Config.Height, Config.Width) } else { box = mapWindow(gw.UiWindow, name, Config.Height, Config.Width) @@ -59,7 +63,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow := box.Window // This is the first window. One must create it here - if (gw == nil) { + if gw == nil { log.Println("initWindow() ADDING ui.NewWindow()") newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Height), int(newGuiWindow.Width), true) newGuiWindow.UiWindow.SetBorderless(false) @@ -68,7 +72,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { newGuiWindow.UiWindow.OnClosing(func(*ui.Window) bool { log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) // newGuiWindow.UiWindow.Destroy() - if (Config.Exit == nil) { + if Config.Exit == nil { ui.Quit() } else { // allow a custom exit function @@ -83,23 +87,23 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { tmp := 0 newGuiWindow.TabNumber = &tmp } else { - newGuiWindow.UiWindow = gw.UiWindow - newGuiWindow.UiTab = gw.UiTab + newGuiWindow.UiWindow = gw.UiWindow + newGuiWindow.UiTab = gw.UiTab } - newGuiWindow.BoxMap = make(map[string]*GuiBox) - newGuiWindow.EntryMap = make(map[string]*GuiEntry) + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) // Data.Windows = append(Data.Windows, &newGuiWindow) - if (newGuiWindow.UiTab == nil) { - tabnum := 0 - newGuiWindow.TabNumber = &tabnum + if newGuiWindow.UiTab == nil { + tabnum := 0 + newGuiWindow.TabNumber = &tabnum } else { - tabnum := newGuiWindow.UiTab.NumPages() - newGuiWindow.TabNumber = &tabnum + tabnum := newGuiWindow.UiTab.NumPages() + newGuiWindow.TabNumber = &tabnum } - Data.WindowMap[newGuiWindow.Name] = newGuiWindow + Data.WindowMap[newGuiWindow.Name] = newGuiWindow log.Println("InitGuiWindow() END *GuiWindow =", newGuiWindow) return box @@ -108,14 +112,14 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { func DeleteWindow(name string) { log.Println("gui.DeleteWindow() START name =", name) window := Data.WindowMap[name] - if (window == nil) { + if window == nil { log.Println("gui.DeleteWindow() NO WINDOW WITH name =", name) return } log.Println("gui.DumpBoxes() MAP: ", name) log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) - if (window.TabNumber == nil) { + if window.TabNumber == nil { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } tab := *window.TabNumber @@ -127,11 +131,11 @@ func DeleteWindow(name string) { // renumber tabs here for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) - if (window.TabNumber == nil) { + if window.TabNumber == nil { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } else { log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) - if (tab < *window.TabNumber) { + if tab < *window.TabNumber { log.Println("gui.DumpBoxes() \tSubtracting 1 from TabNumber") *window.TabNumber -= 1 log.Println("gui.DumpBoxes() \tWindows.TabNumber is now =", *window.TabNumber) @@ -170,8 +174,8 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { } func initBlankWindow() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) return hbox } @@ -180,27 +184,27 @@ var master = 0 func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { log.Println("gui.WindowMap START title =", title) - if (Data.WindowMap[title] != nil) { + if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) master = master + 1 title = title + " jcarr " + strconv.Itoa(master) } - if (Data.WindowMap[title] != nil) { + if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) panic("Data.WindowMap[newGuiWindow.Name] already exists") return nil } log.Println("gui.WindowMap START title =", title) var newGuiWindow GuiWindow - newGuiWindow.Width = x - newGuiWindow.Height = y - newGuiWindow.Name = title - newGuiWindow.UiWindow = window + newGuiWindow.Width = x + newGuiWindow.Height = y + newGuiWindow.Name = title + newGuiWindow.UiWindow = window - newGuiWindow.BoxMap = make(map[string]*GuiBox) - newGuiWindow.EntryMap = make(map[string]*GuiEntry) + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) - Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + Data.WindowMap[newGuiWindow.Name] = &newGuiWindow var box GuiBox box.Window = &newGuiWindow @@ -208,3 +212,25 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { return &box } + +func NewWindow(title string, x int, y int) { + box := mapWindow(nil, title, x, y) + log.Println("gui.NewWindow() title = box.Name =", box.Name) + + window := ui.NewWindow(box.Name, x, y, false) + window.SetBorderless(false) + window.OnClosing(func(*ui.Window) bool { + log.Println("createWindow().OnClosing()", box.Name) + return true + }) + ui.OnShouldQuit(func() bool { + log.Println("createWindow().Destroy()", box.Name) + window.Destroy() + return true + }) + + window.SetMargined(true) + window.Show() + + box.Window.UiWindow = window +} From 02943567b1d7f367614a06c77a96541ed717a371 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 10:59:22 -0500 Subject: [PATCH 022/113] EXAMPLE: provide a clean example Signed-off-by: Jeff Carr --- .gitignore | 1 + gui-example/Makefile | 5 +++++ gui-example/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 4 files changed, 50 insertions(+) create mode 100644 gui-example/Makefile create mode 100644 gui-example/main.go diff --git a/.gitignore b/.gitignore index 1377554..bb1e72d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +gui-example/gui-example diff --git a/gui-example/Makefile b/gui-example/Makefile new file mode 100644 index 0000000..b705093 --- /dev/null +++ b/gui-example/Makefile @@ -0,0 +1,5 @@ +run: build + ~/go/bin/gui-example + +build: + GO111MODULE="off" go install diff --git a/gui-example/main.go b/gui-example/main.go new file mode 100644 index 0000000..f3e4c48 --- /dev/null +++ b/gui-example/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "log" + "os" + "time" + + "git.wit.org/wit/gui" +) + +func customExit(gw *gui.GuiWindow) { + log.Println("Should Exit Here") + os.Exit(0) +} + +func main() { + log.Println("starting my Control Panel") + + gui.Config.Width = 1000 + gui.Config.Height = 400 + gui.Config.Exit = customExit + + go gui.Main(initGUI) + + watchGUI() +} + +func initGUI() { + gui.NewWindow("jcarr start", 640, 480) +} + +func watchGUI() { + var i = 1 + for { + log.Println("Waiting for customExit()", i) + i += 1 + time.Sleep(time.Second) + if i == 3 { + log.Println("Sending ExampleWindow to gui.Queue()") + gui.Queue(gui.ExampleWindow) + } + } +} diff --git a/main.go b/main.go index 5e4d1b4..6d371a6 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ func ExampleWindow() { window := box.Window log.Println("box =", box) log.Println("window =", window) + box.AddDebugTab("jcarr Debug") window.UiWindow.Show() } From 07061a47e74daccec9382506845ff4ce51d44069 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 11:17:43 -0500 Subject: [PATCH 023/113] EXAMPLE: further improvements to the example Signed-off-by: Jeff Carr --- Makefile | 14 ++++++++--- gui-example/Makefile | 4 +-- gui-example/main.go | 6 ++--- main.go | 12 +++++---- window-debug.go | 60 ++++++++++++++++++++++++++------------------ 5 files changed, 59 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index df5d201..7225bce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ +all: + @echo + @echo "make examples # will run all the examples" + @echo "make update # full git update" + @echo + # should update every go dependancy (?) update: - # git pull - wit go update - # go get -v -t -u ./... + git pull + go get -v -t -u ./... + +examples: + make -C gui-example diff --git a/gui-example/Makefile b/gui-example/Makefile index b705093..5028ebd 100644 --- a/gui-example/Makefile +++ b/gui-example/Makefile @@ -1,5 +1,5 @@ run: build - ~/go/bin/gui-example + ./gui-example build: - GO111MODULE="off" go install + GO111MODULE="off" go build diff --git a/gui-example/main.go b/gui-example/main.go index f3e4c48..1ff286d 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -16,8 +16,8 @@ func customExit(gw *gui.GuiWindow) { func main() { log.Println("starting my Control Panel") - gui.Config.Width = 1000 - gui.Config.Height = 400 + gui.Config.Width = 800 + gui.Config.Height = 300 gui.Config.Exit = customExit go gui.Main(initGUI) @@ -37,7 +37,7 @@ func watchGUI() { time.Sleep(time.Second) if i == 3 { log.Println("Sending ExampleWindow to gui.Queue()") - gui.Queue(gui.ExampleWindow) + gui.Queue(gui.DebugWindow) } } } diff --git a/main.go b/main.go index 6d371a6..09d105f 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ func Queue(f func()) { ui.QueueMain(f) } -// gui.Main(gui.MainExample()) func ExampleWindow() { log.Println("START gui.ExampleWindow()") @@ -37,12 +36,15 @@ func ExampleWindow() { window.UiWindow.Show() } -func TestExample() { - log.Println("gui.initUI() inside ui.Main()") +func DebugWindow() { + log.Println("START gui.ExampleWindow()") - box := InitWindow(nil, "test", 0) + title := "Debug Window" + box := InitWindow(nil, title, 0) window := box.Window - log.Println("StartNewWindow() box =", box) + log.Println("box =", box) + log.Println("window =", window) + box.AddDebugTab("jcarr Debug") window.UiWindow.Show() } diff --git a/window-debug.go b/window-debug.go index 6d757a2..bf93a9b 100644 --- a/window-debug.go +++ b/window-debug.go @@ -1,10 +1,12 @@ package gui -import "log" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" +import ( + "log" -import "github.com/davecgh/go-spew/spew" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" + "github.com/davecgh/go-spew/spew" +) var names = make([]string, 100) @@ -12,12 +14,12 @@ func makeWindowDebug() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox := addGroup(hbox, "Numbers") pbar := ui.NewProgressBar() vbox.Append(pbar, false) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox = addGroup(hbox, "WindowMap 2") cbox := ui.NewCombobox() @@ -35,7 +37,7 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Buttons") b1 := addButton(vbox, "dumpBox(name)") @@ -46,6 +48,16 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) + dump2 := addButton(vbox, "Dump Boxes") + dump2.OnClicked(func(*ui.Button) { + DumpBoxes() + }) + + dump1 := addButton(vbox, "Dump MAP") + dump1.OnClicked(func(*ui.Button) { + DumpMap() + }) + b2 := addButton(vbox, "SetMargined()") b2.OnClicked(func(*ui.Button) { x := cbox.Selected() @@ -53,13 +65,13 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } - if (gw.TabNumber == nil) { + if gw.TabNumber == nil { return } scs := spew.ConfigState{MaxDepth: 1} @@ -76,10 +88,10 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } gw.UiTab.Hide() @@ -92,10 +104,10 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } gw.UiTab.Show() @@ -108,13 +120,13 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } - if (gw.TabNumber == nil) { + if gw.TabNumber == nil { return } gw.UiTab.Delete(*gw.TabNumber) @@ -145,7 +157,7 @@ func addGroup(b *ui.Box, name string) *ui.Box { func findBox(s string) *GuiWindow { for name, window := range Data.WindowMap { - if (name == s) { + if name == s { return window } } @@ -154,11 +166,11 @@ func findBox(s string) *GuiWindow { func dumpBox(s string) { for name, window := range Data.WindowMap { - if (name != s) { + if name != s { continue } log.Println("gui.DumpBoxes() MAP: ", name) - if (window.TabNumber == nil) { + if window.TabNumber == nil { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } else { log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) @@ -169,18 +181,18 @@ func dumpBox(s string) { log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - if (name == "MAINBOX") { - if (Config.Debug) { + if name == "MAINBOX" { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 1} scs.Dump(abox.UiBox) } } } - if (window.UiTab != nil) { + if window.UiTab != nil { pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) tabSetMargined(window.UiTab) - if (Config.Debug) { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 2} scs.Dump(window.UiTab) } From 62010a8d167f1d6f15b43547ac3861234e328836 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 11:50:35 -0500 Subject: [PATCH 024/113] FORMAT: I think somehow I formatted this --- debug.go | 44 +++++++++++++++++++++++--------------------- gui.go | 19 +++++++++++-------- window-debug.go | 1 + 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/debug.go b/debug.go index 75f5424..c0ae5dd 100644 --- a/debug.go +++ b/debug.go @@ -1,26 +1,28 @@ package gui -import "log" -import "time" -import "fmt" +import ( + "fmt" + "log" + "time" + + "github.com/davecgh/go-spew/spew" +) + // import "reflect" // 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 watches the GUI primarily to process protobuf's -// this is pointless or wrong but I use it for debugging +// Dump out debugging information every 4 seconds // func WatchGUI() { count := 0 for { - if (count > 20) { + if count > 20 { log.Println("Sleep() in watchGUI()") - if (Config.Debug) { + if Config.Debug { DumpBoxes() } count = 0 @@ -39,7 +41,7 @@ func DumpMap() { func DumpBoxes() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) - if (window.TabNumber == nil) { + if window.TabNumber == nil { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } else { log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) @@ -50,14 +52,14 @@ func DumpBoxes() { log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - if (name == "MAINBOX") { - if (Config.Debug) { + if name == "MAINBOX" { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 1} scs.Dump(abox.UiBox) } } } - if (window.UiTab != nil) { + if window.UiTab != nil { // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) pages := window.UiTab.NumPages() @@ -68,20 +70,20 @@ func DumpBoxes() { // tmp := spew.NewDefaultConfig() // tmp.MaxDepth = 2 // tmp.Dump(window.UiTab) - if (Config.Debug) { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 2} scs.Dump(window.UiTab) } } } /* - for i, window := range Data.Windows { - if (window.TabNumber == nil) { - log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") - } else { - log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) + for i, window := range Data.Windows { + if (window.TabNumber == nil) { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) + } } - } */ } @@ -93,7 +95,7 @@ func addTableTab() { var b TableColumnData b.CellType = foo - b.Heading = fmt.Sprintf("heading%d", key) + b.Heading = fmt.Sprintf("heading%d", key) parts = append(parts, b) } diff --git a/gui.go b/gui.go index 3bdd32e..97e3c24 100644 --- a/gui.go +++ b/gui.go @@ -1,11 +1,14 @@ package gui -import "log" -// import "time" -import "regexp" +import ( + "github.com/andlabs/ui" // import "time" + "log" + "regexp" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" // the _ means we only need this for the init() + _ "github.com/andlabs/ui/winmanifest" +) + +// the _ means we only need this for the init() const Xaxis = 0 // box that is horizontal const Yaxis = 1 // box that is vertical @@ -13,13 +16,13 @@ const Yaxis = 1 // box that is vertical func init() { log.Println("gui.init() has been run") - Data.buttonMap = make(map[*ui.Button]*GuiButton) - Data.WindowMap = make(map[string]*GuiWindow) + Data.buttonMap = make(map[*ui.Button]*GuiButton) + Data.WindowMap = make(map[string]*GuiWindow) } func GuiInit() { ui.OnShouldQuit(func() bool { - ui.Quit() + ui.Quit() return true }) } diff --git a/window-debug.go b/window-debug.go index bf93a9b..77a7e5e 100644 --- a/window-debug.go +++ b/window-debug.go @@ -27,6 +27,7 @@ func makeWindowDebug() ui.Control { log.Println("range Data.WindowMap() name =", name) addName(cbox, name) } + cbox.SetSelected(0) vbox.Append(cbox, false) From 375444ea2899389618feee546c6741cca6abf180 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 11:56:52 -0500 Subject: [PATCH 025/113] VIM-GO: auto-reformatting by vim-go Signed-off-by: Jeff Carr --- new-structs.go | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/new-structs.go b/new-structs.go index 8d65147..c254bbe 100644 --- a/new-structs.go +++ b/new-structs.go @@ -1,18 +1,23 @@ package gui -import "log" +import ( + "log" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +) + +// https://ieftimov.com/post/golang-datastructures-trees/ type Node struct { - Name string - tag string - Width int - Height int + id int + Name string + tag string + Width int + Height int - uiType *ui.Control - Children []*Node + uiType *ui.Control + Children []*Node } func (n Node) SetName(name string) { @@ -22,8 +27,21 @@ func (n Node) SetName(name string) { } func (n Node) Append(child Node) { -// if (n.UiBox == nil) { -// return -// } + // if (n.UiBox == nil) { + // return + // } // n.uiType.Append(child, x) } + +func findByIdDFS(node *Node, id string) *Node { + if node.id == id { + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + findByIdDFS(child, id) + } + } + return nil +} From c58dee3d019e4ef809a98666f01a232d62af226c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 11:58:39 -0500 Subject: [PATCH 026/113] BUG: make it compile Signed-off-by: Jeff Carr --- new-structs.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/new-structs.go b/new-structs.go index c254bbe..0fa326a 100644 --- a/new-structs.go +++ b/new-structs.go @@ -10,14 +10,13 @@ import ( // https://ieftimov.com/post/golang-datastructures-trees/ type Node struct { - id int + id string Name string - tag string Width int Height int uiType *ui.Control - Children []*Node + children []*Node } func (n Node) SetName(name string) { From 908615c0387446ef2a181c8754dc95323e275a0e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 13:23:00 -0500 Subject: [PATCH 027/113] TAB: correctly lookup and add tabs to blank windows Signed-off-by: Jeff Carr --- debug.go | 6 +- structs.go | 228 ++++++++++++++++++++++++++---------------------- window-debug.go | 77 +++++++++------- window.go | 2 + 4 files changed, 178 insertions(+), 135 deletions(-) diff --git a/debug.go b/debug.go index c0ae5dd..8c1e947 100644 --- a/debug.go +++ b/debug.go @@ -33,8 +33,12 @@ func WatchGUI() { } func DumpMap() { - for name, _ := range Data.WindowMap { + for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) + log.Println("gui.DumpBoxes() BOXES:", name) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + } } } diff --git a/structs.go b/structs.go index 6387b45..71921bd 100644 --- a/structs.go +++ b/structs.go @@ -1,36 +1,39 @@ package gui -import "log" -import "image/color" -import "golang.org/x/image/font" +import ( + "image/color" + "log" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + "golang.org/x/image/font" + + _ "github.com/andlabs/ui/winmanifest" +) // // All GUI Data Structures and functions that are external // If you need cross platform support, these might only // be the safe way to interact with the GUI // -var Data GuiData -var Config GuiConfig +var Data GuiData +var Config GuiConfig type GuiConfig struct { - Width int - Height int - Debug bool - DebugTable bool - Exit func(*GuiWindow) + Width int + Height int + Debug bool + DebugTable bool + Exit func(*GuiWindow) } type GuiData struct { - // a fallback default function to handle mouse events + // a fallback default function to handle mouse events // if nothing else is defined to handle them - MouseClick func(*GuiButton) + MouseClick func(*GuiButton) // A map of all the entry boxes - AllEntries []*GuiEntry - WindowMap map[string]*GuiWindow + AllEntries []*GuiEntry + WindowMap map[string]*GuiWindow // Windows []*GuiWindow @@ -40,15 +43,15 @@ type GuiData struct { // // This has to work this way because of how // andlabs/ui & andlabs/libui work - AllButtons []*GuiButton - buttonMap map[*ui.Button]*GuiButton - Nodes *Node + AllButtons []*GuiButton + buttonMap map[*ui.Button]*GuiButton + Nodes *Node } type GuiTab struct { - Name string // field for human readable name - Number int // the andlabs/ui tab index - Window *GuiWindow // the parent Window + Name string // field for human readable name + Number int // the andlabs/ui tab index + Window *GuiWindow // the parent Window } // @@ -70,42 +73,42 @@ type GuiTab struct { // can destroy and replace it with something else // type GuiWindow struct { - Name string // field for human readable name - Width int - Height int - Axis int // does it add items to the X or Y axis - TabNumber *int // the andlabs/ui tab index + Name string // field for human readable name + Width int + Height int + Axis int // does it add items to the X or Y axis + TabNumber *int // the andlabs/ui tab index // the callback function to make the window contents // MakeWindow func(*GuiBox) *GuiBox // the components of the window - BoxMap map[string]*GuiBox - EntryMap map[string]*GuiEntry - Area *GuiArea + BoxMap map[string]*GuiBox + EntryMap map[string]*GuiEntry + Area *GuiArea // andlabs/ui abstraction mapping - UiWindow *ui.Window - UiTab *ui.Tab // if this != nil, the window is 'tabbed' + UiWindow *ui.Window + UiTab *ui.Tab // if this != nil, the window is 'tabbed' } // GuiBox is any type of ui.Hbox or ui.Vbox // There can be lots of these for each GuiWindow type GuiBox struct { - Name string // field for human readable name - Axis int // does it add items to the X or Y axis - Window *GuiWindow // the parent Window + Name string // field for human readable name + Axis int // does it add items to the X or Y axis + Window *GuiWindow // the parent Window // andlabs/ui abstraction mapping - UiBox *ui.Box + UiBox *ui.Box } func (s GuiBox) SetTitle(title string) { log.Println("DID IT!", title) - if (s.Window == nil) { + if s.Window == nil { return } - if (s.Window.UiWindow == nil) { + if s.Window.UiWindow == nil { return } s.Window.UiWindow.SetTitle(title) @@ -113,17 +116,33 @@ func (s GuiBox) SetTitle(title string) { } func (s GuiBox) Append(child ui.Control, x bool) { - if (s.UiBox == nil) { + if s.UiBox == nil { return } s.UiBox.Append(child, x) } -func (s GuiBox) InitTab(title string) *ui.Tab { - if (s.Window == nil) { +func (w GuiWindow) InitBox(title string) *GuiBox { + if w.UiWindow == nil { + log.Println("gui.InitBox() THIS SHOULD NEVER HAPPEN. Window doesn't exist", w) return nil } - if (s.Window.UiWindow == nil) { + tab := ui.NewTab() + w.UiWindow.SetChild(tab) + w.UiWindow.SetMargined(true) + + tab.Append(title, initBlankWindow()) + tab.SetMargined(0, true) + + w.UiTab = tab + return nil +} + +func (s GuiBox) InitTab(title string) *ui.Tab { + if s.Window == nil { + return nil + } + if s.Window.UiWindow == nil { return nil } @@ -141,10 +160,10 @@ func (s GuiBox) InitTab(title string) *ui.Tab { } func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { - if (s.Window == nil) { + if s.Window == nil { return nil } - if (s.Window.UiTab == nil) { + if s.Window.UiTab == nil { return nil } @@ -155,10 +174,10 @@ func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { } func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { - if (s.Window == nil) { + if s.Window == nil { return nil } - if (s.Window.UiTab == nil) { + if s.Window.UiTab == nil { return nil } @@ -200,32 +219,32 @@ func tabSetMargined(tab *ui.Tab) { // the user clicks it. You could probably // call this 'GuiMouseClick' type GuiButton struct { - Name string // field for human readable name - Box *GuiBox // what box the button click was in + Name string // field for human readable name + Box *GuiBox // what box the button click was in // a callback function for the main application - Custom func (*GuiButton) - Values interface {} - Color color.RGBA + Custom func(*GuiButton) + Values interface{} + Color color.RGBA // andlabs/ui abstraction mapping - B *ui.Button - FB *ui.FontButton - CB *ui.ColorButton + B *ui.Button + FB *ui.FontButton + CB *ui.ColorButton } // text entry fields type GuiEntry struct { - Name string // field for human readable name - Edit bool - Last string // the last value - Normalize func (string) string // function to 'normalize' the data + Name string // field for human readable name + Edit bool + Last string // the last value + Normalize func(string) string // function to 'normalize' the data - B *GuiButton - Box *GuiBox + B *GuiButton + Box *GuiBox // andlabs/ui abstraction mapping - UiEntry *ui.Entry + UiEntry *ui.Entry } // @@ -233,20 +252,21 @@ type GuiEntry struct { // AREA STRUCTURES START // AREA STRUCTURES START // -type GuiArea struct{ - Button *GuiButton // what button handles mouse events - Box *GuiBox +type GuiArea struct { + Button *GuiButton // what button handles mouse events + Box *GuiBox - UiAttrstr *ui.AttributedString - UiArea *ui.Area + UiAttrstr *ui.AttributedString + UiArea *ui.Area } type FontString struct { - S string - Size int - F font.Face - W font.Weight + S string + Size int + F font.Face + W font.Weight } + // // AREA STRUCTURES END // AREA STRUCTURES END @@ -264,18 +284,18 @@ type FontString struct { // to the GUI. This is the "authoritative" data. // type TableData struct { - RowCount int // This is the number of 'rows' which really means data elements not what the human sees - RowWidth int // This is how wide each row is - Rows []RowData // This is all the table data by row - generatedColumnTypes []ui.TableValue // generate this dynamically + RowCount int // This is the number of 'rows' which really means data elements not what the human sees + RowWidth int // This is how wide each row is + Rows []RowData // This is all the table data by row + generatedColumnTypes []ui.TableValue // generate this dynamically - Cells [20]CellData - Human [20]HumanMap + Cells [20]CellData + Human [20]HumanMap - Box *GuiBox + Box *GuiBox - lastRow int - lastColumn int + lastRow int + lastColumn int } // @@ -294,44 +314,44 @@ type TableData struct { // TODO: re-add images and the progress bar (works in andlabs/ui) // type HumanCellData struct { - Name string // what kind of row is this? - Text string - TextID int - Color color.RGBA - ColorID int - Button *GuiButton + Name string // what kind of row is this? + Text string + TextID int + Color color.RGBA + ColorID int + Button *GuiButton } type HumanMap struct { - Name string // what kind of row is this? - TextID int - ColorID int + Name string // what kind of row is this? + TextID int + ColorID int } type TableColumnData struct { - Index int - CellType string - Heading string - Color string + Index int + CellType string + Heading string + Color string } type CellData struct { - Index int - HumanID int - Name string // what type of cell is this? + Index int + HumanID int + Name string // what type of cell is this? } // hmm. will this stand the test of time? type RowData struct { - Name string // what kind of row is this? - Status string // status of the row? -/* - // TODO: These may or may not be implementable - // depending on if it's possible to detect the bgcolor or what row is selected - click func() // what function to call if the user clicks on it - doubleclick func() // what function to call if the user double clicks on it -*/ - HumanData [20]HumanCellData + Name string // what kind of row is this? + Status string // status of the row? + /* + // TODO: These may or may not be implementable + // depending on if it's possible to detect the bgcolor or what row is selected + click func() // what function to call if the user clicks on it + doubleclick func() // what function to call if the user double clicks on it + */ + HumanData [20]HumanCellData } // diff --git a/window-debug.go b/window-debug.go index 77a7e5e..704ef7b 100644 --- a/window-debug.go +++ b/window-debug.go @@ -20,7 +20,7 @@ func makeWindowDebug() ui.Control { vbox.Append(pbar, false) ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "WindowMap 2") + vbox = addGroup(hbox, "Window") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { @@ -39,9 +39,9 @@ func makeWindowDebug() ui.Control { }) ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Buttons") + vbox = addGroup(hbox, "Debug Window") - b1 := addButton(vbox, "dumpBox(name)") + b1 := addButton(vbox, "dumpBox(window)") b1.OnClicked(func(*ui.Button) { x := cbox.Selected() log.Println("x =", x) @@ -49,23 +49,12 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) - dump2 := addButton(vbox, "Dump Boxes") - dump2.OnClicked(func(*ui.Button) { - DumpBoxes() - }) - - dump1 := addButton(vbox, "Dump MAP") - dump1.OnClicked(func(*ui.Button) { - DumpMap() - }) - - b2 := addButton(vbox, "SetMargined()") + b2 := addButton(vbox, "SetMargined(tab)") b2.OnClicked(func(*ui.Button) { x := cbox.Selected() log.Println("x =", x) - log.Println("findBox; names[x] =", names[x]) - findBox(names[x]) - gw := findBox(names[x]) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) if gw == nil { return } @@ -82,13 +71,12 @@ func makeWindowDebug() ui.Control { gw.UiTab.SetMargined(*gw.TabNumber, true) }) - b3 := addButton(vbox, "Hide()") + b3 := addButton(vbox, "Hide(tab)") b3.OnClicked(func(*ui.Button) { x := cbox.Selected() log.Println("x =", x) - log.Println("findBox; names[x] =", names[x]) - findBox(names[x]) - gw := findBox(names[x]) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) if gw == nil { return } @@ -98,13 +86,12 @@ func makeWindowDebug() ui.Control { gw.UiTab.Hide() }) - b4 := addButton(vbox, "Show()") + b4 := addButton(vbox, "Show(tab)") b4.OnClicked(func(*ui.Button) { x := cbox.Selected() log.Println("x =", x) - log.Println("findBox; names[x] =", names[x]) - findBox(names[x]) - gw := findBox(names[x]) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) if gw == nil { return } @@ -114,13 +101,12 @@ func makeWindowDebug() ui.Control { gw.UiTab.Show() }) - b5 := addButton(vbox, "Delete()") + b5 := addButton(vbox, "Delete(tab)") b5.OnClicked(func(*ui.Button) { x := cbox.Selected() log.Println("x =", x) - log.Println("findBox; names[x] =", names[x]) - findBox(names[x]) - gw := findBox(names[x]) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) if gw == nil { return } @@ -133,6 +119,19 @@ func makeWindowDebug() ui.Control { gw.UiTab.Delete(*gw.TabNumber) }) + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Global Debug") + + dump2 := addButton(vbox, "Dump Boxes") + dump2.OnClicked(func(*ui.Button) { + DumpBoxes() + }) + + dump1 := addButton(vbox, "Dump MAP") + dump1.OnClicked(func(*ui.Button) { + DumpMap() + }) + return hbox } @@ -156,12 +155,28 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } -func findBox(s string) *GuiWindow { +func FindWindow(s string) *GuiWindow { for name, window := range Data.WindowMap { if name == s { return window } } + log.Printf("COULD NOT FIND WINDOW", s) + return nil +} + +func FindBox(s string) *GuiBox { + for name, window := range Data.WindowMap { + if name != s { + continue + } + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + return abox + } + log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) + } + log.Println("gui.FindBox() COULD NOT FIND BOX", s) return nil } @@ -180,6 +195,7 @@ func dumpBox(s string) { // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + log.Println("gui.dumpBox() BoxMap START") for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if name == "MAINBOX" { @@ -189,6 +205,7 @@ func dumpBox(s string) { } } } + log.Println("gui.dumpBox() BoxMap END") if window.UiTab != nil { pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) diff --git a/window.go b/window.go index 1dfe05a..24bd879 100644 --- a/window.go +++ b/window.go @@ -210,6 +210,8 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { box.Window = &newGuiWindow box.Name = title + newGuiWindow.BoxMap["jcarrInitTest"] = &box + return &box } From 2ccc1b518ddc404a4dbdc41971005cf04cc06e66 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 14:32:07 -0500 Subject: [PATCH 028/113] REFACTOR: things are back to working as they were Signed-off-by: Jeff Carr --- structs.go | 12 +++++++----- window.go | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/structs.go b/structs.go index 71921bd..ad3307b 100644 --- a/structs.go +++ b/structs.go @@ -122,7 +122,8 @@ func (s GuiBox) Append(child ui.Control, x bool) { s.UiBox.Append(child, x) } -func (w GuiWindow) InitBox(title string) *GuiBox { +/* +func (w GuiWindow) InitWindow(title string) *GuiBox { if w.UiWindow == nil { log.Println("gui.InitBox() THIS SHOULD NEVER HAPPEN. Window doesn't exist", w) return nil @@ -131,14 +132,15 @@ func (w GuiWindow) InitBox(title string) *GuiBox { w.UiWindow.SetChild(tab) w.UiWindow.SetMargined(true) - tab.Append(title, initBlankWindow()) + tab.Append(title, InitBlankWindow()) tab.SetMargined(0, true) w.UiTab = tab return nil } +*/ -func (s GuiBox) InitTab(title string) *ui.Tab { +func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab { if s.Window == nil { return nil } @@ -151,7 +153,7 @@ func (s GuiBox) InitTab(title string) *ui.Tab { window.SetChild(tab) window.SetMargined(true) - tab.Append(title, initBlankWindow()) + tab.Append(title, custom()) tab.SetMargined(0, true) // tab.SetMargined(1, true) @@ -187,7 +189,7 @@ func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { } func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab2(title, initBlankWindow()) + uiTab := s.AddTab2(title, InitBlankWindow()) tabSetMargined(uiTab) var box *GuiBox diff --git a/window.go b/window.go index 24bd879..2b615b5 100644 --- a/window.go +++ b/window.go @@ -146,7 +146,7 @@ func DeleteWindow(name string) { func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *GuiBox { box := CreateBlankWindow(title, x, y) - box.InitTab(title) + box.InitTab(title, custom) return box } @@ -173,7 +173,7 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { return box } -func initBlankWindow() ui.Control { +func InitBlankWindow() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) @@ -215,7 +215,7 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { return &box } -func NewWindow(title string, x int, y int) { +func NewWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) log.Println("gui.NewWindow() title = box.Name =", box.Name) @@ -235,4 +235,5 @@ func NewWindow(title string, x int, y int) { window.Show() box.Window.UiWindow = window + return box } From e796008fbdeced81a845eff3b00e8424bd5dbf72 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 01:37:37 -0500 Subject: [PATCH 029/113] DEBUG: add more debugging options --- debug.go | 6 ++++++ gui-example/main.go | 4 ++-- window-debug.go | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/debug.go b/debug.go index 8c1e947..0b383c8 100644 --- a/debug.go +++ b/debug.go @@ -32,6 +32,12 @@ func WatchGUI() { } } +func DumpWindows() { + for name, _ := range Data.WindowMap { + log.Println("gui.DumpWindows() window =", name) + } +} + func DumpMap() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) diff --git a/gui-example/main.go b/gui-example/main.go index 1ff286d..5f34f98 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -34,8 +34,8 @@ func watchGUI() { for { log.Println("Waiting for customExit()", i) i += 1 - time.Sleep(time.Second) - if i == 3 { + time.Sleep(3 * time.Second) + if i == 2 { log.Println("Sending ExampleWindow to gui.Queue()") gui.Queue(gui.DebugWindow) } diff --git a/window-debug.go b/window-debug.go index 704ef7b..7ffcb8e 100644 --- a/window-debug.go +++ b/window-debug.go @@ -15,12 +15,7 @@ func makeWindowDebug() ui.Control { hbox.SetPadded(true) ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "Numbers") - pbar := ui.NewProgressBar() - vbox.Append(pbar, false) - - ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Window") + vbox := addGroup(hbox, "Window") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { @@ -122,6 +117,11 @@ func makeWindowDebug() ui.Control { ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Global Debug") + dump3 := addButton(vbox, "Dump Windows") + dump3.OnClicked(func(*ui.Button) { + DumpWindows() + }) + dump2 := addButton(vbox, "Dump Boxes") dump2.OnClicked(func(*ui.Button) { DumpBoxes() @@ -132,6 +132,12 @@ func makeWindowDebug() ui.Control { DumpMap() }) + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Numbers") + pbar := ui.NewProgressBar() + vbox.Append(pbar, false) + + return hbox } From 5e439f73407baa7894e376ca504a8392e7fee5d9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 02:23:04 -0500 Subject: [PATCH 030/113] NODE: start populating the node tree --- gui.go | 1 + structs.go | 4 ++-- window.go | 49 ++++++++++++++++++++++++++++--------------------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/gui.go b/gui.go index 97e3c24..5fa3215 100644 --- a/gui.go +++ b/gui.go @@ -18,6 +18,7 @@ func init() { Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.WindowMap = make(map[string]*GuiWindow) + Data.NodeMap = make(map[string]*Node) } func GuiInit() { diff --git a/structs.go b/structs.go index ad3307b..a7e78b5 100644 --- a/structs.go +++ b/structs.go @@ -35,7 +35,8 @@ type GuiData struct { AllEntries []*GuiEntry WindowMap map[string]*GuiWindow - // Windows []*GuiWindow + // Store access to everything via binary tree's + NodeMap map[string]*Node // A map of all buttons everywhere on all // windows, all tabs, across all goroutines @@ -45,7 +46,6 @@ type GuiData struct { // andlabs/ui & andlabs/libui work AllButtons []*GuiButton buttonMap map[*ui.Button]*GuiButton - Nodes *Node } type GuiTab struct { diff --git a/window.go b/window.go index 2b615b5..8e68a70 100644 --- a/window.go +++ b/window.go @@ -65,11 +65,11 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if gw == nil { log.Println("initWindow() ADDING ui.NewWindow()") - newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Height), int(newGuiWindow.Width), true) - newGuiWindow.UiWindow.SetBorderless(false) + w := uiNewWindow(name, Config.Height, Config.Width) + newGuiWindow.UiWindow = w // newGuiWindow.UiWindow.SetTitle("test") - newGuiWindow.UiWindow.OnClosing(func(*ui.Window) bool { + w.OnClosing(func(*ui.Window) bool { log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) // newGuiWindow.UiWindow.Destroy() if Config.Exit == nil { @@ -150,25 +150,38 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C return box } +func uiNewWindow(title string, x int, y int) *ui.Window { + var node Node + node.Name = title + node.Width = x + node.Height = y + Data.NodeMap[title] = &node + + w := ui.NewWindow(title, x, y, false) + w.SetBorderless(false) + w.OnClosing(func(*ui.Window) bool { + log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title) + return true + }) + + w.SetMargined(true) + w.Show() + + return w +} + func CreateBlankWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) - window := ui.NewWindow(box.Name, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", box.Name) - return true - }) + window := uiNewWindow(box.Name, x, y) + ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) window.Destroy() return true }) - window.SetMargined(true) - window.Show() - box.Window.UiWindow = window return box } @@ -194,6 +207,7 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { panic("Data.WindowMap[newGuiWindow.Name] already exists") return nil } + log.Println("gui.WindowMap START title =", title) var newGuiWindow GuiWindow newGuiWindow.Width = x @@ -219,21 +233,14 @@ func NewWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) log.Println("gui.NewWindow() title = box.Name =", box.Name) - window := ui.NewWindow(box.Name, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", box.Name) - return true - }) + window := uiNewWindow(box.Name, x, y) + ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) window.Destroy() return true }) - window.SetMargined(true) - window.Show() - box.Window.UiWindow = window return box } From a3c0cc390ccfa23dd64372e1e98a93c4cef8dbec Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 05:52:22 -0500 Subject: [PATCH 031/113] NODE: start passing *Node around Signed-off-by: Jeff Carr --- box.go | 10 +++++++++- new-structs.go | 11 +++++++++-- structs.go | 36 +++++++++++++++++++----------------- window.go | 25 ++++++++++++++++++------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/box.go b/box.go index 2640742..a077064 100644 --- a/box.go +++ b/box.go @@ -1,6 +1,7 @@ package gui import "log" +import "os" // import "reflect" import "github.com/andlabs/ui" @@ -64,7 +65,14 @@ func add(box *GuiBox, newbox *GuiBox) { } func NewBox(box *GuiBox, axis int, name string) *GuiBox { - log.Println("VerticalBox START") + log.Println("gui.NewBox() START") + n := box.FindNode() + if (n == nil) { + log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") + } else { + log.Println("gui.NewBox() node =", n.Name) + os.Exit(0) + } var newbox *GuiBox newbox = new(GuiBox) newbox.Window = box.Window diff --git a/new-structs.go b/new-structs.go index 0fa326a..df25cae 100644 --- a/new-structs.go +++ b/new-structs.go @@ -15,13 +15,20 @@ type Node struct { Width int Height int - uiType *ui.Control children []*Node + + control *ui.Control + window *ui.Window } func (n Node) SetName(name string) { // n.uiType.SetName(name) - log.Println("n.uiType =", n.uiType) + if (n.window != nil) { + log.Println("node is a window. setting title =", name) + n.window.SetTitle(name) + return + } + log.Println("*ui.Control =", n.control) return } diff --git a/structs.go b/structs.go index a7e78b5..2629cdc 100644 --- a/structs.go +++ b/structs.go @@ -3,6 +3,7 @@ package gui import ( "image/color" "log" + "os" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -87,6 +88,8 @@ type GuiWindow struct { EntryMap map[string]*GuiEntry Area *GuiArea + node *Node + // andlabs/ui abstraction mapping UiWindow *ui.Window UiTab *ui.Tab // if this != nil, the window is 'tabbed' @@ -99,6 +102,8 @@ type GuiBox struct { Axis int // does it add items to the X or Y axis Window *GuiWindow // the parent Window + node *Node + // andlabs/ui abstraction mapping UiBox *ui.Box } @@ -115,6 +120,13 @@ func (s GuiBox) SetTitle(title string) { return } +func (s GuiBox) FindNode() *Node { + if s.node != nil { + return s.node + } + return nil +} + func (s GuiBox) Append(child ui.Control, x bool) { if s.UiBox == nil { return @@ -140,7 +152,7 @@ func (w GuiWindow) InitWindow(title string) *GuiBox { } */ -func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab { +func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node { if s.Window == nil { return nil } @@ -158,7 +170,11 @@ func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab { // tab.SetMargined(1, true) s.Window.UiTab = tab - return tab + if s.node == nil { + log.Println("Fuck node = ", s.node) + os.Exit(-1) + } + return s.node } func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { @@ -169,27 +185,13 @@ func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { return nil } - tab := s.Window.UiTab - - tab.Append(title, custom) - return tab -} - -func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { - if s.Window == nil { - return nil - } - if s.Window.UiTab == nil { - return nil - } - tab := s.Window.UiTab tab.Append(title, custom) return tab } func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab2(title, InitBlankWindow()) + uiTab := s.AddTab(title, InitBlankWindow()) tabSetMargined(uiTab) var box *GuiBox diff --git a/window.go b/window.go index 8e68a70..d3b329a 100644 --- a/window.go +++ b/window.go @@ -65,7 +65,9 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if gw == nil { log.Println("initWindow() ADDING ui.NewWindow()") - w := uiNewWindow(name, Config.Height, Config.Width) + n := uiNewWindow(name, Config.Height, Config.Width) + box.node = n + w := n.window newGuiWindow.UiWindow = w // newGuiWindow.UiWindow.SetTitle("test") @@ -150,11 +152,16 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C return box } -func uiNewWindow(title string, x int, y int) *ui.Window { +func uiNewWindow(title string, x int, y int) *Node { var node Node node.Name = title node.Width = x node.Height = y + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate uiNewWindow() name =", title) + // TODO: just change the 'title' to something unique + return nil + } Data.NodeMap[title] = &node w := ui.NewWindow(title, x, y, false) @@ -163,18 +170,20 @@ func uiNewWindow(title string, x int, y int) *ui.Window { log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title) return true }) - w.SetMargined(true) w.Show() - - return w + node.window = w + // w.node = &node + return &node } func CreateBlankWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) - window := uiNewWindow(box.Name, x, y) + n := uiNewWindow(box.Name, x, y) + box.node = n + window := n.window ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) @@ -233,7 +242,9 @@ func NewWindow(title string, x int, y int) *GuiBox { box := mapWindow(nil, title, x, y) log.Println("gui.NewWindow() title = box.Name =", box.Name) - window := uiNewWindow(box.Name, x, y) + n := uiNewWindow(box.Name, x, y) + box.node = n + window := n.window ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) From e4446ea51a4dd2db83c15200c94dc82c9812f7f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 06:19:35 -0500 Subject: [PATCH 032/113] NODE: continued work on implementing a node tree --- new-structs.go | 20 ++++++++++++++++++-- structs.go | 2 +- window.go | 19 +++++++++++++------ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/new-structs.go b/new-structs.go index df25cae..d6ff409 100644 --- a/new-structs.go +++ b/new-structs.go @@ -16,12 +16,13 @@ type Node struct { Height int children []*Node + box *GuiBox control *ui.Control window *ui.Window } -func (n Node) SetName(name string) { +func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.window != nil) { log.Println("node is a window. setting title =", name) @@ -32,15 +33,30 @@ func (n Node) SetName(name string) { return } -func (n Node) Append(child Node) { +func (n *Node) FindWindowBox() *GuiBox { + if (n.box == nil) { + log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") + log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") + log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") + log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") + } + return n.box +} + +func (n *Node) Append(child Node) { // if (n.UiBox == nil) { // return // } // n.uiType.Append(child, x) } +func (n *Node) List() { + findByIdDFS(n, "test") +} func findByIdDFS(node *Node, id string) *Node { + log.Println("findByIdDFS()", id, node) if node.id == id { + log.Println("Found node id =", id, node) return node } diff --git a/structs.go b/structs.go index 2629cdc..e1993a9 100644 --- a/structs.go +++ b/structs.go @@ -177,7 +177,7 @@ func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node { return s.node } -func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { +func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { if s.Window == nil { return nil } diff --git a/window.go b/window.go index d3b329a..960c8bf 100644 --- a/window.go +++ b/window.go @@ -146,10 +146,16 @@ func DeleteWindow(name string) { } } -func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *GuiBox { - box := CreateBlankWindow(title, x, y) - box.InitTab(title, custom) - return box +func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *Node { + n := CreateBlankWindow(title, x, y) + if (n.box == nil) { + log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") + log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") + log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") + log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") + } + n.box.InitTab(title, custom) + return n } func uiNewWindow(title string, x int, y int) *Node { @@ -177,12 +183,13 @@ func uiNewWindow(title string, x int, y int) *Node { return &node } -func CreateBlankWindow(title string, x int, y int) *GuiBox { +func CreateBlankWindow(title string, x int, y int) *Node { box := mapWindow(nil, title, x, y) log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) n := uiNewWindow(box.Name, x, y) box.node = n + n.box = box window := n.window ui.OnShouldQuit(func() bool { @@ -192,7 +199,7 @@ func CreateBlankWindow(title string, x int, y int) *GuiBox { }) box.Window.UiWindow = window - return box + return n } func InitBlankWindow() ui.Control { From b288902b1c66d9ece6f90685d90ed632253d424c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 06:48:50 -0500 Subject: [PATCH 033/113] NODE: continued work on implementing a node tree --- new-structs.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ structs.go | 19 +--------------- window.go | 2 +- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/new-structs.go b/new-structs.go index d6ff409..b70623e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -2,6 +2,7 @@ package gui import ( "log" + "os" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" @@ -15,13 +16,36 @@ type Node struct { Width int Height int + parent *Node children []*Node + box *GuiBox control *ui.Control window *ui.Window } +func (n *Node) Parent() *Node { + return n.parent +} + +func (n *Node) Window() *Node { + return n.parent +} + +func (n *Node) Dump() { + log.Println("gui.Node.Dump() id = ", n.id) + log.Println("gui.Node.Dump() Name = ", n.Name) + log.Println("gui.Node.Dump() Width = ", n.Width) + log.Println("gui.Node.Dump() Height = ", n.Height) + log.Println("gui.Node.Dump() parent = ", n.parent) + log.Println("gui.Node.Dump() children = ", n.children) + log.Println("gui.Node.Dump() box = ", n.box) + log.Println("gui.Node.Dump() control = ", n.control) + log.Println("gui.Node.Dump() window = ", n.window) +} + + func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.window != nil) { @@ -67,3 +91,41 @@ func findByIdDFS(node *Node, id string) *Node { } return nil } + +func (n *Node) InitTab(title string, custom func() ui.Control) *Node { + boxs := n.box + if boxs == nil { + log.Println("gui.InitTab() 1 Fuck node = ", n) + n.Dump() + os.Exit(-1) + } + if boxs.Window == nil { + log.Println("gui.InitTab() 2 Fuck node = ", n) + n.Dump() + os.Exit(-1) + return nil + } + if boxs.Window.UiWindow == nil { + log.Println("gui.InitTab() 3 Fuck node = ", n) + n.Dump() + os.Exit(-1) + return nil + } + + window := boxs.Window.UiWindow + tab := ui.NewTab() + window.SetChild(tab) + window.SetMargined(true) + + tab.Append(title, custom()) + tab.SetMargined(0, true) + // tab.SetMargined(1, true) + + boxs.Window.UiTab = tab + if boxs.node == nil { + log.Println("gui.InitTab() 4 Fuck node = ", n) + n.Dump() + os.Exit(-1) + } + return n +} diff --git a/structs.go b/structs.go index e1993a9..9cec347 100644 --- a/structs.go +++ b/structs.go @@ -3,7 +3,6 @@ package gui import ( "image/color" "log" - "os" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -135,23 +134,6 @@ func (s GuiBox) Append(child ui.Control, x bool) { } /* -func (w GuiWindow) InitWindow(title string) *GuiBox { - if w.UiWindow == nil { - log.Println("gui.InitBox() THIS SHOULD NEVER HAPPEN. Window doesn't exist", w) - return nil - } - tab := ui.NewTab() - w.UiWindow.SetChild(tab) - w.UiWindow.SetMargined(true) - - tab.Append(title, InitBlankWindow()) - tab.SetMargined(0, true) - - w.UiTab = tab - return nil -} -*/ - func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node { if s.Window == nil { return nil @@ -176,6 +158,7 @@ func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node { } return s.node } +*/ func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { if s.Window == nil { diff --git a/window.go b/window.go index 960c8bf..cd03a7d 100644 --- a/window.go +++ b/window.go @@ -154,7 +154,7 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") } - n.box.InitTab(title, custom) + n.InitTab(title, custom) return n } From 189d31bb336bc31d845e15361db3558cd8f469bb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 12:04:48 -0500 Subject: [PATCH 034/113] NODE: continued work on implementing a node tree Signed-off-by: Jeff Carr --- box.go | 2 +- debug.go | 52 +++++++++++++++++++++++++++ main.go | 4 +++ new-structs.go | 96 ++++++++++++++++++++++++++++++++------------------ structs.go | 39 ++++++++++++++++++-- window.go | 41 +++++++++++++++++---- 6 files changed, 189 insertions(+), 45 deletions(-) diff --git a/box.go b/box.go index a077064..237788a 100644 --- a/box.go +++ b/box.go @@ -69,9 +69,9 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { n := box.FindNode() if (n == nil) { log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") + os.Exit(0) } else { log.Println("gui.NewBox() node =", n.Name) - os.Exit(0) } var newbox *GuiBox newbox = new(GuiBox) diff --git a/debug.go b/debug.go index 0b383c8..79a5fb3 100644 --- a/debug.go +++ b/debug.go @@ -2,6 +2,7 @@ package gui import ( "fmt" + "os" "log" "time" @@ -112,3 +113,54 @@ func addTableTab() { log.Println("Sleep for 1 second, then try to add new tabs") time.Sleep(1 * time.Second) } + +func DebugDataNodeMap() { + if Data.NodeMap == nil { + log.Println("Data.NodeMap == nil") + return + } + log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.Width, node.Height, name) + // node.SetName("yahoo") + // log.Println("\tData.NodeMap node =", node) + } +} + +func FindNode(name string) *Node { + if Data.NodeMap == nil { + log.Println("gui.FindNode() gui.Data.NodeMap == nil") + return nil + } + log.Println("gui.FindNode() searching Data.NodeMap:") + for id, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.Width, node.Height, id) + node.Dump() + if (name == node.Name) { + return node + } + newNode := findByName(node, name) + if (newNode != nil) { + return newNode + } + log.Println("gui.FindNode() could not find node name =", name) + os.Exit(-1) + } + log.Println("gui.FindNode() could not find node name =", name) + return nil +} + +func DebugNodeChildren() { + if Data.NodeMap == nil { + log.Println("Data.NodeMap == nil") + return + } + log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.Width, node.Height, name) + node.Dump() + node.List() + // node.SetName("yahoo") + // log.Println("\tData.NodeMap node =", node) + } +} diff --git a/main.go b/main.go index 09d105f..cb130ef 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,10 @@ import ( ) func Main(f func()) { + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") log.Println("Starting gui.Main() (using gtk via andlabs/ui)") ui.Main(f) } diff --git a/new-structs.go b/new-structs.go index b70623e..a24262d 100644 --- a/new-structs.go +++ b/new-structs.go @@ -21,8 +21,9 @@ type Node struct { box *GuiBox - control *ui.Control - window *ui.Window + uiControl *ui.Control + uiWindow *ui.Window + uiTab *ui.Tab } func (n *Node) Parent() *Node { @@ -34,44 +35,50 @@ func (n *Node) Window() *Node { } func (n *Node) Dump() { - log.Println("gui.Node.Dump() id = ", n.id) - log.Println("gui.Node.Dump() Name = ", n.Name) - log.Println("gui.Node.Dump() Width = ", n.Width) - log.Println("gui.Node.Dump() Height = ", n.Height) - log.Println("gui.Node.Dump() parent = ", n.parent) - log.Println("gui.Node.Dump() children = ", n.children) - log.Println("gui.Node.Dump() box = ", n.box) - log.Println("gui.Node.Dump() control = ", n.control) - log.Println("gui.Node.Dump() window = ", n.window) + log.Println("gui.Node.Dump() id = ", n.id) + log.Println("gui.Node.Dump() Name = ", n.Name) + log.Println("gui.Node.Dump() Width = ", n.Width) + log.Println("gui.Node.Dump() Height = ", n.Height) + log.Println("gui.Node.Dump() parent = ", n.parent) + log.Println("gui.Node.Dump() children = ", n.children) + log.Println("gui.Node.Dump() box = ", n.box) + log.Println("gui.Node.Dump() uiControl = ", n.uiControl) + log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) + log.Println("gui.Node.Dump() uiTab = ", n.uiTab) } func (n *Node) SetName(name string) { // n.uiType.SetName(name) - if (n.window != nil) { + if (n.uiWindow != nil) { log.Println("node is a window. setting title =", name) - n.window.SetTitle(name) + n.uiWindow.SetTitle(name) return } - log.Println("*ui.Control =", n.control) + log.Println("*ui.Control =", n.uiControl) return } +func (n *Node) FindTab() *ui.Tab { + return n.uiTab +} + func (n *Node) FindWindowBox() *GuiBox { if (n.box == nil) { log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") + os.Exit(-1) } return n.box } -func (n *Node) Append(child Node) { +func (n *Node) Append(child *Node) { // if (n.UiBox == nil) { // return // } - // n.uiType.Append(child, x) + n.children = append(n.children, child) } func (n *Node) List() { findByIdDFS(n, "test") @@ -79,6 +86,7 @@ func (n *Node) List() { func findByIdDFS(node *Node, id string) *Node { log.Println("findByIdDFS()", id, node) + node.Dump() if node.id == id { log.Println("Found node id =", id, node) return node @@ -86,46 +94,64 @@ func findByIdDFS(node *Node, id string) *Node { if len(node.children) > 0 { for _, child := range node.children { - findByIdDFS(child, id) + newNode := findByIdDFS(child, id) + if (newNode != nil) { + return newNode + } + } + } + return nil +} + +func findByName(node *Node, name string) *Node { + log.Println("findByName()", name, node) + node.Dump() + if node.Name == name { + log.Println("findByName() Found node name =", name, node) + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + newNode := findByName(child, name) + if (newNode != nil) { + return newNode + } } } return nil } func (n *Node) InitTab(title string, custom func() ui.Control) *Node { - boxs := n.box - if boxs == nil { - log.Println("gui.InitTab() 1 Fuck node = ", n) + if n.uiWindow == nil { + log.Println("gui.InitTab() ERROR ui.Window == nil") n.Dump() os.Exit(-1) } - if boxs.Window == nil { - log.Println("gui.InitTab() 2 Fuck node = ", n) + if n.box != nil { + log.Println("gui.InitTab() ERROR box already exists") n.Dump() os.Exit(-1) - return nil - } - if boxs.Window.UiWindow == nil { - log.Println("gui.InitTab() 3 Fuck node = ", n) - n.Dump() - os.Exit(-1) - return nil } - window := boxs.Window.UiWindow tab := ui.NewTab() - window.SetChild(tab) - window.SetMargined(true) + n.uiWindow.SetChild(tab) + n.uiWindow.SetMargined(true) tab.Append(title, custom()) tab.SetMargined(0, true) - // tab.SetMargined(1, true) - boxs.Window.UiTab = tab + var newNode Node + newNode.Name = title + newNode.parent = n + n.Append(&newNode) + newNode.uiTab = tab + /* if boxs.node == nil { log.Println("gui.InitTab() 4 Fuck node = ", n) n.Dump() os.Exit(-1) } - return n + */ + return &newNode } diff --git a/structs.go b/structs.go index 9cec347..4dffe3f 100644 --- a/structs.go +++ b/structs.go @@ -3,6 +3,7 @@ package gui import ( "image/color" "log" + "os" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -24,6 +25,8 @@ type GuiConfig struct { Debug bool DebugTable bool Exit func(*GuiWindow) + + depth int } type GuiData struct { @@ -107,6 +110,14 @@ type GuiBox struct { UiBox *ui.Box } +func (gb *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", gb.Name) + log.Println("gui.GuiBox.Dump() Axis = ", gb.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", gb.Window) + log.Println("gui.GuiBox.Dump() node = ", gb.node) + log.Println("gui.GuiBox.Dump() UiBox = ", gb.UiBox) +} + func (s GuiBox) SetTitle(title string) { log.Println("DID IT!", title) if s.Window == nil { @@ -119,10 +130,30 @@ func (s GuiBox) SetTitle(title string) { return } -func (s GuiBox) FindNode() *Node { - if s.node != nil { - return s.node +func (b *GuiBox) SetNode(n *Node) { + if (b.node != nil) { + b.Dump() + log.Println("gui.SetNode() Error not nil") + os.Exit(-1) } + b.node = n + if (b.node == nil) { + b.Dump() + log.Println("gui.SetNode() node == nil") + os.Exit(-1) + } + b.Dump() +} + +func (b *GuiBox) FindNode() *Node { + log.Println("gui.FindNode() on GuiBox") + if b.node != nil { + return b.node + } + DebugNodeChildren() + b.Dump() + log.Println("gui.FindNode() on GuiBox is nil") + os.Exit(-1) return nil } @@ -194,6 +225,8 @@ func (s GuiBox) AddDebugTab(title string) { } func tabSetMargined(tab *ui.Tab) { + log.Println("tabSetMargined() IGNORE THIS") + return c := tab.NumPages() for i := 0; i < c; i++ { log.Println("tabSetMargined() i =", i) diff --git a/window.go b/window.go index cd03a7d..dae070f 100644 --- a/window.go +++ b/window.go @@ -2,6 +2,7 @@ package gui import ( "log" + "os" "strconv" "time" @@ -50,7 +51,7 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // actual window but that does not appear to work on the MacOS or Windows // func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { - log.Println("InitGuiWindow() START") + log.Println("InitWindow() START") var box *GuiBox if gw == nil { @@ -67,8 +68,12 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { log.Println("initWindow() ADDING ui.NewWindow()") n := uiNewWindow(name, Config.Height, Config.Width) box.node = n - w := n.window + if (n.box == nil) { + n.box = box + } + w := n.uiWindow newGuiWindow.UiWindow = w + os.Exit(-1) // newGuiWindow.UiWindow.SetTitle("test") w.OnClosing(func(*ui.Window) bool { @@ -107,7 +112,31 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { Data.WindowMap[newGuiWindow.Name] = newGuiWindow - log.Println("InitGuiWindow() END *GuiWindow =", newGuiWindow) + if (box.node == nil) { + fn := FindNode("full initTab") + log.Println("InitWindow() fn =", fn) + log.Println("InitWindow() mapping node <=> box") + box.node = fn + if (fn.box == nil) { + log.Println("InitWindow() mapping node <=> box") + fn.box = box + } + } + if (box.node == nil) { + DebugNodeChildren() + log.Println("InitWindow() box has a FUCKING nil node") + fn := FindNode("full initTab") + log.Println("InitWindow() fn =", fn) + os.Exit(-1) + } + + if (newGuiWindow.node == nil) { + DebugNodeChildren() + log.Println("InitWindow() newGuiWindow has a FUCKING nil node") + // os.Exit(-1) + } + + log.Println("InitWindow() END *GuiWindow =", newGuiWindow) return box } @@ -178,7 +207,7 @@ func uiNewWindow(title string, x int, y int) *Node { }) w.SetMargined(true) w.Show() - node.window = w + node.uiWindow = w // w.node = &node return &node } @@ -190,7 +219,7 @@ func CreateBlankWindow(title string, x int, y int) *Node { n := uiNewWindow(box.Name, x, y) box.node = n n.box = box - window := n.window + window := n.uiWindow ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) @@ -251,7 +280,7 @@ func NewWindow(title string, x int, y int) *GuiBox { n := uiNewWindow(box.Name, x, y) box.node = n - window := n.window + window := n.uiWindow ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) From dcdced47db8c6dd86820fd29d0ec657b15ce2393 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 21:04:16 -0500 Subject: [PATCH 035/113] NODE: continued work on implementing a node tree --- window.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/window.go b/window.go index dae070f..7370dca 100644 --- a/window.go +++ b/window.go @@ -51,7 +51,7 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // actual window but that does not appear to work on the MacOS or Windows // func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { - log.Println("InitWindow() START") + log.Println("gui.InitWindow() START") var box *GuiBox if gw == nil { @@ -65,7 +65,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if gw == nil { - log.Println("initWindow() ADDING ui.NewWindow()") + log.Println("gui.initWindow() ADDING ui.NewWindow()") n := uiNewWindow(name, Config.Height, Config.Width) box.node = n if (n.box == nil) { @@ -73,11 +73,10 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { } w := n.uiWindow newGuiWindow.UiWindow = w - os.Exit(-1) // newGuiWindow.UiWindow.SetTitle("test") w.OnClosing(func(*ui.Window) bool { - log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) + log.Println("gui.InitWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) // newGuiWindow.UiWindow.Destroy() if Config.Exit == nil { ui.Quit() From 387b7ead6e94b745d1b0ec007df6eb392798eb77 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 21:31:15 -0500 Subject: [PATCH 036/113] NODE: continued work on implementing a node tree Signed-off-by: Jeff Carr --- debug.go | 5 +++++ new-structs.go | 4 ++-- window-debug.go | 15 +++++++++++++++ window.go | 6 +++--- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/debug.go b/debug.go index 79a5fb3..d9cb9b5 100644 --- a/debug.go +++ b/debug.go @@ -122,6 +122,11 @@ func DebugDataNodeMap() { log.Println("Dumping Data.NodeMap:") for name, node := range Data.NodeMap { log.Println("\tData.NodeMap name =", node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + } else { + log.Println("\t\tHas children:", node.children) + } // node.SetName("yahoo") // log.Println("\tData.NodeMap node =", node) } diff --git a/new-structs.go b/new-structs.go index a24262d..03b6b94 100644 --- a/new-structs.go +++ b/new-structs.go @@ -129,9 +129,9 @@ func (n *Node) InitTab(title string, custom func() ui.Control) *Node { os.Exit(-1) } if n.box != nil { - log.Println("gui.InitTab() ERROR box already exists") + log.Println("gui.InitTab() ERROR box already exists title =", title) n.Dump() - os.Exit(-1) + // os.Exit(-1) } tab := ui.NewTab() diff --git a/window-debug.go b/window-debug.go index 7ffcb8e..19aadad 100644 --- a/window-debug.go +++ b/window-debug.go @@ -132,10 +132,25 @@ func makeWindowDebug() ui.Control { DumpMap() }) + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Node Debug") + + n1 := addButton(vbox, "DebugDataNodeMap()") + n1.OnClicked(func(*ui.Button) { + DebugDataNodeMap() + }) + + n2 := addButton(vbox, "DebugNodeChildren()") + n2.OnClicked(func(*ui.Button) { + DebugNodeChildren() + }) + +/* ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Numbers") pbar := ui.NewProgressBar() vbox.Append(pbar, false) +*/ return hbox diff --git a/window.go b/window.go index 7370dca..3c5589c 100644 --- a/window.go +++ b/window.go @@ -55,9 +55,9 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { var box *GuiBox if gw == nil { - box = mapWindow(nil, name, Config.Height, Config.Width) + box = mapWindow(nil, name, Config.Width, Config.Height) } else { - box = mapWindow(gw.UiWindow, name, Config.Height, Config.Width) + box = mapWindow(gw.UiWindow, name, Config.Width, Config.Height) } // box.Window = &newGuiWindow @@ -66,7 +66,7 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if gw == nil { log.Println("gui.initWindow() ADDING ui.NewWindow()") - n := uiNewWindow(name, Config.Height, Config.Width) + n := uiNewWindow(name, Config.Width, Config.Height) box.node = n if (n.box == nil) { n.box = box From f83ab4577dd69270bd37b6ed64ee1b88e3a0c1c8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 21:56:16 -0500 Subject: [PATCH 037/113] NODE: continued work on implementing a node tree Signed-off-by: Jeff Carr --- debug.go | 26 +++++++++++++++++++++----- new-structs.go | 21 +++++++++++++++++++++ window-debug.go | 7 ++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/debug.go b/debug.go index d9cb9b5..ae6801d 100644 --- a/debug.go +++ b/debug.go @@ -116,12 +116,12 @@ func addTableTab() { func DebugDataNodeMap() { if Data.NodeMap == nil { - log.Println("Data.NodeMap == nil") + log.Println("DebugDataNodeMap() NodeMap == nil") return } - log.Println("Dumping Data.NodeMap:") + log.Println("DebugDataNodeMap():") for name, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.Width, node.Height, name) + log.Println("\tNode name =", node.Width, node.Height, name) if (node.children == nil) { log.Println("\t\tNo children") } else { @@ -132,6 +132,22 @@ func DebugDataNodeMap() { } } +func DebugDataNodeChildren() { + if Data.NodeMap == nil { + log.Println("DebugDataNodeChildren() NodeMap == nil") + return + } + log.Println("DebugDataNodeChildren():") + for name, node := range Data.NodeMap { + log.Println("\tNode name =", node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + break + } + log.Println("\t\tHas children:", node.children) + } +} + func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") @@ -163,8 +179,8 @@ func DebugNodeChildren() { log.Println("Dumping Data.NodeMap:") for name, node := range Data.NodeMap { log.Println("\tData.NodeMap name =", node.Width, node.Height, name) - node.Dump() - node.List() + // node.Dump() + node.ListChildren() // node.SetName("yahoo") // log.Println("\tData.NodeMap node =", node) } diff --git a/new-structs.go b/new-structs.go index 03b6b94..a9cd2a6 100644 --- a/new-structs.go +++ b/new-structs.go @@ -80,10 +80,31 @@ func (n *Node) Append(child *Node) { // } n.children = append(n.children, child) } + func (n *Node) List() { findByIdDFS(n, "test") } +func (n *Node) ListChildren() { + log.Println("gui.Node.ListChildren() node =", n.Name, n) + + if len(n.children) == 0 { + log.Println("\t\tNo children START") + return + } +// if len(n.children) > 0 { + for _, child := range n.children { + log.Println("gui.Node.ListChildren() child =", child.Name, child) + if (child.children == nil) { + log.Println("\t\tNo children END") + break + } + log.Println("\t\tHas children:", child.children) + child.ListChildren() + } + return +} + func findByIdDFS(node *Node, id string) *Node { log.Println("findByIdDFS()", id, node) node.Dump() diff --git a/window-debug.go b/window-debug.go index 19aadad..2e31440 100644 --- a/window-debug.go +++ b/window-debug.go @@ -140,8 +140,13 @@ func makeWindowDebug() ui.Control { DebugDataNodeMap() }) - n2 := addButton(vbox, "DebugNodeChildren()") + n2 := addButton(vbox, "DebugDataNodeChildren()") n2.OnClicked(func(*ui.Button) { + DebugDataNodeChildren() + }) + + n3 := addButton(vbox, "DebugNodeChildren()") + n3.OnClicked(func(*ui.Button) { DebugNodeChildren() }) From 3cdc5859133ff12aed2e0e9d1f57bff55ccd6e9b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 8 Oct 2021 07:36:53 -0500 Subject: [PATCH 038/113] NODE: going down a rabbit hole --- box.go | 4 ++ debug.go | 2 +- gui.go | 2 + main.go | 6 ++- new-structs.go | 66 +++++++++++++++-------------- structs.go | 31 +++++++++++--- table.go | 4 +- window-debug.go | 2 +- window.go | 108 +++++++++++++++++++++++++++++++++++------------- 9 files changed, 155 insertions(+), 70 deletions(-) diff --git a/box.go b/box.go index 237788a..fffb463 100644 --- a/box.go +++ b/box.go @@ -93,6 +93,10 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { log.Println("HardBox() START axis =", axis) + if (gw.node == nil) { + gw.Dump() + panic("gui.HardBox() gw.node == nil") + } // add a Vertical Seperator if there is already a box // Is this right? box := gw.BoxMap["MAINBOX"] diff --git a/debug.go b/debug.go index ae6801d..dbdbc68 100644 --- a/debug.go +++ b/debug.go @@ -178,7 +178,7 @@ func DebugNodeChildren() { } log.Println("Dumping Data.NodeMap:") for name, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.Width, node.Height, name) + log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) // node.Dump() node.ListChildren() // node.SetName("yahoo") diff --git a/gui.go b/gui.go index 5fa3215..9e7c253 100644 --- a/gui.go +++ b/gui.go @@ -19,6 +19,8 @@ func init() { Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) + + Config.counter = 0 } func GuiInit() { diff --git a/main.go b/main.go index cb130ef..0876e4a 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,8 @@ func ExampleWindow() { log.Println("START gui.ExampleWindow()") title := "Test Window" - box := InitWindow(nil, title, 0) + node := InitWindow(nil, nil, title, 0) + box := node.box window := box.Window log.Println("box =", box) log.Println("window =", window) @@ -44,7 +45,8 @@ func DebugWindow() { log.Println("START gui.ExampleWindow()") title := "Debug Window" - box := InitWindow(nil, title, 0) + node := InitWindow(nil, nil, title, 0) + box := node.box window := box.Window log.Println("box =", box) log.Println("window =", window) diff --git a/new-structs.go b/new-structs.go index a9cd2a6..2f006ef 100644 --- a/new-structs.go +++ b/new-structs.go @@ -2,7 +2,9 @@ package gui import ( "log" - "os" + "time" + + // "github.com/davecgh/go-spew/spew" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" @@ -45,6 +47,9 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() uiControl = ", n.uiControl) log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) log.Println("gui.Node.Dump() uiTab = ", n.uiTab) + if (n.id == "") { + panic("gui.Node.Dump() id == nil") + } } @@ -63,13 +68,13 @@ func (n *Node) FindTab() *ui.Tab { return n.uiTab } +func (n *Node) FindBox() *GuiBox { + return n.box +} + func (n *Node) FindWindowBox() *GuiBox { if (n.box == nil) { - log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") - log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") - log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") - log.Println("SERIOUS ERROR n.box == nil in FindWindowBox()") - os.Exit(-1) + panic("SERIOUS ERROR n.box == nil in FindWindowBox()") } return n.box } @@ -79,6 +84,11 @@ func (n *Node) Append(child *Node) { // return // } n.children = append(n.children, child) + log.Println("child node:") + child.Dump() + log.Println("parent node:") + n.Dump() + time.Sleep(3 * time.Second) } func (n *Node) List() { @@ -86,20 +96,28 @@ func (n *Node) List() { } func (n *Node) ListChildren() { - log.Println("gui.Node.ListChildren() node =", n.Name, n) + log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height) if len(n.children) == 0 { + log.Println("\t\t\tparent =",n.parent.id) log.Println("\t\tNo children START") return } -// if len(n.children) > 0 { + // spew.Dump(n) for _, child := range n.children { - log.Println("gui.Node.ListChildren() child =", child.Name, child) - if (child.children == nil) { - log.Println("\t\tNo children END") - break + log.Println("\t\tListChildren() child =",child.id, child.Name, child.Width, child.Height) + if (child.parent != nil) { + log.Println("\t\t\tparent =",child.parent.id) + } else { + log.Println("\t\t\tno parent") + panic("no parent") } - log.Println("\t\tHas children:", child.children) + // child.Dump() + if (child.children == nil) { + log.Println("\t\t\tNo children END") + // break + } + log.Println("\t\t\tHas children:", child.children) child.ListChildren() } return @@ -145,14 +163,12 @@ func findByName(node *Node, name string) *Node { func (n *Node) InitTab(title string, custom func() ui.Control) *Node { if n.uiWindow == nil { - log.Println("gui.InitTab() ERROR ui.Window == nil") n.Dump() - os.Exit(-1) + panic("gui.InitTab() ERROR ui.Window == nil") } - if n.box != nil { - log.Println("gui.InitTab() ERROR box already exists title =", title) + if n.box == nil { n.Dump() - // os.Exit(-1) + panic("gui.InitTab() ERROR box == nil") } tab := ui.NewTab() @@ -162,17 +178,7 @@ func (n *Node) InitTab(title string, custom func() ui.Control) *Node { tab.Append(title, custom()) tab.SetMargined(0, true) - var newNode Node - newNode.Name = title - newNode.parent = n - n.Append(&newNode) + newNode := makeNode(n, title, 555, 666) newNode.uiTab = tab - /* - if boxs.node == nil { - log.Println("gui.InitTab() 4 Fuck node = ", n) - n.Dump() - os.Exit(-1) - } - */ - return &newNode + return newNode } diff --git a/structs.go b/structs.go index 4dffe3f..8b1a99a 100644 --- a/structs.go +++ b/structs.go @@ -27,6 +27,7 @@ type GuiConfig struct { Exit func(*GuiWindow) depth int + counter int // used to make unique ID's } type GuiData struct { @@ -97,6 +98,13 @@ type GuiWindow struct { UiTab *ui.Tab // if this != nil, the window is 'tabbed' } +func (gw *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", gw.Name) + log.Println("gui.GuiWindow.Dump() node = ", gw.node) + log.Println("gui.GuiWindow.Dump() Width = ", gw.Width) + log.Println("gui.GuiWindow.Dump() Height = ", gw.Height) +} + // GuiBox is any type of ui.Hbox or ui.Vbox // There can be lots of these for each GuiWindow type GuiBox struct { @@ -130,19 +138,32 @@ func (s GuiBox) SetTitle(title string) { return } +func (w *GuiWindow) SetNode(n *Node) { + if (w.node != nil) { + w.Dump() + panic("gui.SetNode() Error not nil") + } + w.node = n + if (w.node == nil) { + w.Dump() + panic("gui.SetNode() node == nil") + } +} + func (b *GuiBox) SetNode(n *Node) { if (b.node != nil) { b.Dump() - log.Println("gui.SetNode() Error not nil") - os.Exit(-1) + panic("gui.SetNode() Error not nil") } b.node = n if (b.node == nil) { b.Dump() - log.Println("gui.SetNode() node == nil") - os.Exit(-1) + panic("gui.SetNode() node == nil") } - b.Dump() +} + +func (w *GuiWindow) FindNode() *Node { + return w.node } func (b *GuiBox) FindNode() *Node { diff --git a/table.go b/table.go index 87e69b2..a6bb84e 100644 --- a/table.go +++ b/table.go @@ -98,9 +98,9 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { - box := InitWindow(gw, name, Yaxis) + node := InitWindow(nil, gw, name, Yaxis) - return AddTableBox(box, name, rowcount, parts) + return AddTableBox(node.box, name, rowcount, parts) } func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData { diff --git a/window-debug.go b/window-debug.go index 2e31440..c68468d 100644 --- a/window-debug.go +++ b/window-debug.go @@ -145,7 +145,7 @@ func makeWindowDebug() ui.Control { DebugDataNodeChildren() }) - n3 := addButton(vbox, "DebugNodeChildren()") + n3 := addButton(vbox, "Node.ListChildren()") n3.OnClicked(func(*ui.Button) { DebugNodeChildren() }) diff --git a/window.go b/window.go index 3c5589c..649f02b 100644 --- a/window.go +++ b/window.go @@ -2,7 +2,6 @@ package gui import ( "log" - "os" "strconv" "time" @@ -17,7 +16,8 @@ func initUI(name string, callback func(*GuiBox) *GuiBox) { ui.Main(func() { log.Println("gui.initUI() inside ui.Main()") - box := InitWindow(nil, "StartNewWindow"+name, 0) + node := InitWindow(nil, nil, "StartNewWindow"+name, 0) + box := node.box box = callback(box) window := box.Window log.Println("StartNewWindow() box =", box) @@ -50,14 +50,18 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // This is this way because on Linux you can have more than one // actual window but that does not appear to work on the MacOS or Windows // -func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { +func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { log.Println("gui.InitWindow() START") var box *GuiBox + var node *Node + if gw == nil { - box = mapWindow(nil, name, Config.Width, Config.Height) + node = mapWindow(parent, nil, name, Config.Width, Config.Height) + box = node.box } else { - box = mapWindow(gw.UiWindow, name, Config.Width, Config.Height) + node = mapWindow(parent, gw.UiWindow, name, Config.Width, Config.Height) + box = node.box } // box.Window = &newGuiWindow @@ -66,12 +70,12 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { // This is the first window. One must create it here if gw == nil { log.Println("gui.initWindow() ADDING ui.NewWindow()") - n := uiNewWindow(name, Config.Width, Config.Height) - box.node = n - if (n.box == nil) { - n.box = box + node = uiNewWindow(node, name, Config.Width, Config.Height) + box.node = node + if (node.box == nil) { + node.box = box } - w := n.uiWindow + w := node.uiWindow newGuiWindow.UiWindow = w // newGuiWindow.UiWindow.SetTitle("test") @@ -126,17 +130,36 @@ func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { log.Println("InitWindow() box has a FUCKING nil node") fn := FindNode("full initTab") log.Println("InitWindow() fn =", fn) - os.Exit(-1) + panic(-1) } if (newGuiWindow.node == nil) { DebugNodeChildren() log.Println("InitWindow() newGuiWindow has a FUCKING nil node") - // os.Exit(-1) + // panic(-1) } log.Println("InitWindow() END *GuiWindow =", newGuiWindow) - return box + if (box.node == nil) { + box.Dump() + panic(-1) + } + box.Dump() + box.node.Dump() + if (box.node != node) { + log.Println("InitWindow() box.node != node. Hmmm....") + log.Println("InitWindow() box.node != node. Hmmm....") + log.Println("InitWindow() box.node != node. Hmmm....") + panic(-1) + } + if (node.box != box) { + log.Println("InitWindow() node.box != box. Hmmm....") + log.Println("InitWindow() node.box != box. Hmmm....") + log.Println("InitWindow() node.box != box. Hmmm....") + panic(-1) + } + // panic("InitWindow") + return node } func DeleteWindow(name string) { @@ -186,17 +209,40 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C return n } -func uiNewWindow(title string, x int, y int) *Node { +// +// Create a new node +// if parent == nil, that means it is a new window and needs to be put +// in the window map (aka Data.NodeMap) +// +func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title node.Width = x node.Height = y - if (Data.NodeMap[title] != nil) { - log.Println("Duplicate uiNewWindow() name =", title) - // TODO: just change the 'title' to something unique - return nil + + id := "jwc" + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + if (parent == nil) { + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate uiNewWindow() name =", title) + // TODO: just change the 'title' to something unique + return nil + } + Data.NodeMap[title] = &node + return &node + } else { + parent.Append(&node) + } + node.parent = parent + return &node +} + +func uiNewWindow(node *Node, title string, x int, y int) *Node { + if (node == nil) { + node = makeNode(nil, title, x, y) } - Data.NodeMap[title] = &node w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) @@ -208,16 +254,15 @@ func uiNewWindow(title string, x int, y int) *Node { w.Show() node.uiWindow = w // w.node = &node - return &node + return node } func CreateBlankWindow(title string, x int, y int) *Node { - box := mapWindow(nil, title, x, y) + n := mapWindow(nil, nil, title, x, y) + box := n.box log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) - n := uiNewWindow(box.Name, x, y) - box.node = n - n.box = box + n = uiNewWindow(n, box.Name, x, y) window := n.uiWindow ui.OnShouldQuit(func() bool { @@ -239,7 +284,7 @@ func InitBlankWindow() ui.Control { var master = 0 -func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { +func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) @@ -268,17 +313,22 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { box.Window = &newGuiWindow box.Name = title + // func makeNode(parent *Node, title string, x int, y int) *Node { + node := makeNode(parent, title, x, y) + node.box = &box + box.node = node + newGuiWindow.BoxMap["jcarrInitTest"] = &box - return &box + return node } func NewWindow(title string, x int, y int) *GuiBox { - box := mapWindow(nil, title, x, y) + n := mapWindow(nil, nil, title, x, y) + box := n.box log.Println("gui.NewWindow() title = box.Name =", box.Name) - n := uiNewWindow(box.Name, x, y) - box.node = n + n = uiNewWindow(n, box.Name, x, y) window := n.uiWindow ui.OnShouldQuit(func() bool { From 7d5b353f0dacde823d584848f3e35f2bf02067be Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 8 Oct 2021 10:22:38 -0500 Subject: [PATCH 039/113] NODE: going down a rabbit hole --- box.go | 32 ++++++++++++++++++++++++++++++++ new-structs.go | 4 ++-- window.go | 11 ++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/box.go b/box.go index fffb463..10fb1bc 100644 --- a/box.go +++ b/box.go @@ -64,6 +64,38 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() END") } +func (n *Node) NewBox(axis int, name string) *Node { + var newBox *GuiBox + var newNode *Node = n + + newBox = new(GuiBox) + // newBox.Window = newNode.uiWindow + newBox.Name = name + + if (n.box == nil) { + panic("node.newBox() box == nil") + } + if (n.box == nil) { + // add a box here + newBox.node = n + n.box = newBox + } else { + // make a new box & a new node + newNode = makeNode(n, name, 111, 112) + } + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newBox.UiBox = uiBox + add(n.box, newBox) + return newNode +} + func NewBox(box *GuiBox, axis int, name string) *GuiBox { log.Println("gui.NewBox() START") n := box.FindNode() diff --git a/new-structs.go b/new-structs.go index 2f006ef..aa86ef9 100644 --- a/new-structs.go +++ b/new-structs.go @@ -2,7 +2,7 @@ package gui import ( "log" - "time" + // "time" // "github.com/davecgh/go-spew/spew" @@ -88,7 +88,7 @@ func (n *Node) Append(child *Node) { child.Dump() log.Println("parent node:") n.Dump() - time.Sleep(3 * time.Second) + // time.Sleep(3 * time.Second) } func (n *Node) List() { diff --git a/window.go b/window.go index 649f02b..518b92c 100644 --- a/window.go +++ b/window.go @@ -96,9 +96,11 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { newGuiWindow.UiWindow.SetMargined(true) tmp := 0 newGuiWindow.TabNumber = &tmp + node.uiTab = newGuiWindow.UiTab } else { newGuiWindow.UiWindow = gw.UiWindow newGuiWindow.UiTab = gw.UiTab + node.uiTab = newGuiWindow.UiTab } newGuiWindow.BoxMap = make(map[string]*GuiBox) @@ -111,6 +113,9 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } else { tabnum := newGuiWindow.UiTab.NumPages() newGuiWindow.TabNumber = &tabnum + if (node.uiTab == nil) { + node.uiTab = newGuiWindow.UiTab + } } Data.WindowMap[newGuiWindow.Name] = newGuiWindow @@ -158,7 +163,10 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { log.Println("InitWindow() node.box != box. Hmmm....") panic(-1) } - // panic("InitWindow") + if (node.uiTab == nil) { + // DebugNodeChildren() + // panic("node.uiTab = nil") + } return node } @@ -316,6 +324,7 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod // func makeNode(parent *Node, title string, x int, y int) *Node { node := makeNode(parent, title, x, y) node.box = &box + node.uiWindow = window box.node = node newGuiWindow.BoxMap["jcarrInitTest"] = &box From e16eb26379763661789a51b36217040dc01dd79e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 01:51:15 -0500 Subject: [PATCH 040/113] NODE: going down a rabbit hole --- box.go | 22 +++++++++++++++------- entry.go | 11 +++++++++++ new-structs.go | 35 +++++++++++++++++++++++++++++++---- structs.go | 2 +- window.go | 5 +++-- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/box.go b/box.go index 10fb1bc..0d2a487 100644 --- a/box.go +++ b/box.go @@ -47,16 +47,24 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) // copy the box settings over newbox.Window = box.Window - if (box.UiBox == nil) { - log.Println("\tgui.add() ERROR box.UiBox == nil") - panic("crap") + if (box.node == nil) { + box.Dump() + panic("gui.add() ERROR box.node == nil") } + if (newbox.UiBox == nil) { - log.Println("\tgui.add() ERROR newbox.UiBox == nil") - panic("crap") + panic("gui.add() ERROR newbox.UiBox == nil") + } + + if (box.UiBox == nil) { + } + + if (box.UiBox == nil) { + DebugDataNodeChildren() + box.Dump() + return + panic("gui.add() ERROR box.UiBox == nil") } - // log.Println("\tgui.add() newbox.UiBox == ", newbox.UiBox.GetParent()) - // spew.Dump(newbox.UiBox) box.UiBox.Append(newbox.UiBox, false) // add the newbox to the Window.BoxMap[] diff --git a/entry.go b/entry.go index d7f31c9..f3abce2 100644 --- a/entry.go +++ b/entry.go @@ -13,6 +13,17 @@ func NewLabel(box *GuiBox, text string) { box.Append(ui.NewLabel(text), false) } +func (n *Node) NewLabel(text string) *Node { + // make new node here + // n.Append(ui.NewLabel(text), false) + newNode := makeNode(n, text, 333, 334) + newNode.Dump() + // panic("node.NewLabel()") + + n.Append(newNode) + return newNode +} + func GetText(box *GuiBox, name string) string { if (box == nil) { log.Println("gui.GetText() ERROR box == nil") diff --git a/new-structs.go b/new-structs.go index aa86ef9..d6e2550 100644 --- a/new-structs.go +++ b/new-structs.go @@ -68,6 +68,10 @@ func (n *Node) FindTab() *ui.Tab { return n.uiTab } +func (n *Node) FindControl() *ui.Control { + return n.uiControl +} + func (n *Node) FindBox() *GuiBox { return n.box } @@ -99,7 +103,9 @@ func (n *Node) ListChildren() { log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height) if len(n.children) == 0 { - log.Println("\t\t\tparent =",n.parent.id) + if (n.parent != nil) { + log.Println("\t\t\tparent =",n.parent.id) + } log.Println("\t\tNo children START") return } @@ -161,7 +167,7 @@ func findByName(node *Node, name string) *Node { return nil } -func (n *Node) InitTab(title string, custom func() ui.Control) *Node { +func (n *Node) InitTab(title string) *Node { if n.uiWindow == nil { n.Dump() panic("gui.InitTab() ERROR ui.Window == nil") @@ -175,10 +181,31 @@ func (n *Node) InitTab(title string, custom func() ui.Control) *Node { n.uiWindow.SetChild(tab) n.uiWindow.SetMargined(true) - tab.Append(title, custom()) + tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) - newNode := makeNode(n, title, 555, 666) + newNode := makeNode(n, title, 555, 600 + Config.counter) + newNode.uiTab = tab + return newNode +} + +func (n *Node) AddTab(title string, custom func() ui.Control) *Node { + if n.uiWindow == nil { + n.Dump() + panic("gui.AddTab() ERROR ui.Window == nil") + } + if n.box == nil { + n.Dump() + panic("gui.AddTab() ERROR box == nil") + } + + tab := ui.NewTab() + n.uiWindow.SetMargined(true) + + tab.Append(title, custom()) + tab.SetMargined(0, true) + + newNode := makeNode(n, title, 555, 600 + Config.counter) newNode.uiTab = tab return newNode } diff --git a/structs.go b/structs.go index 8b1a99a..bf5dec8 100644 --- a/structs.go +++ b/structs.go @@ -226,7 +226,7 @@ func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { } func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab(title, InitBlankWindow()) + uiTab := s.AddTab(title, initBlankWindow()) tabSetMargined(uiTab) var box *GuiBox diff --git a/window.go b/window.go index 518b92c..75a427c 100644 --- a/window.go +++ b/window.go @@ -213,7 +213,8 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") } - n.InitTab(title, custom) + n.InitTab(title) + // TODO: run custom() here // Oct 9 return n } @@ -283,7 +284,7 @@ func CreateBlankWindow(title string, x int, y int) *Node { return n } -func InitBlankWindow() ui.Control { +func initBlankWindow() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) From 24244a206ed093a03c61f26fc1d38530035990d3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 02:37:14 -0500 Subject: [PATCH 041/113] NODE: walking around in the rabbit hole --- debug.go | 34 ++++++++++++++++++++++++++++++++++ new-structs.go | 8 +++++--- structs.go | 2 +- window-debug.go | 44 +++++++++++++++++++++++++++++++++++++++++--- window.go | 4 ++-- 5 files changed, 83 insertions(+), 9 deletions(-) diff --git a/debug.go b/debug.go index dbdbc68..d5273e0 100644 --- a/debug.go +++ b/debug.go @@ -171,6 +171,39 @@ func FindNode(name string) *Node { return nil } +func (dn *GuiData) ListChildren(dump bool) { + if Data.NodeMap == nil { + log.Println("Data.NodeMap == nil") + return + } + log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + if (dump == true) { + node.Dump() + } + node.ListChildren(dump) + } +} + +func (dn *GuiData) findId(id string) *Node { + if Data.NodeMap == nil { + log.Println("Data.NodeMap == nil") + return nil + } + log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + if (id == node.id) { + return node + } + // TODO: fix // Oct 9 + // node.findId(id) + } + return nil +} + +/* func DebugNodeChildren() { if Data.NodeMap == nil { log.Println("Data.NodeMap == nil") @@ -185,3 +218,4 @@ func DebugNodeChildren() { // log.Println("\tData.NodeMap node =", node) } } +*/ diff --git a/new-structs.go b/new-structs.go index d6e2550..4c24692 100644 --- a/new-structs.go +++ b/new-structs.go @@ -99,7 +99,7 @@ func (n *Node) List() { findByIdDFS(n, "test") } -func (n *Node) ListChildren() { +func (n *Node) ListChildren(dump bool) { log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height) if len(n.children) == 0 { @@ -118,13 +118,15 @@ func (n *Node) ListChildren() { log.Println("\t\t\tno parent") panic("no parent") } - // child.Dump() + if (dump == true) { + child.Dump() + } if (child.children == nil) { log.Println("\t\t\tNo children END") // break } log.Println("\t\t\tHas children:", child.children) - child.ListChildren() + child.ListChildren(dump) } return } diff --git a/structs.go b/structs.go index bf5dec8..961e743 100644 --- a/structs.go +++ b/structs.go @@ -171,7 +171,7 @@ func (b *GuiBox) FindNode() *Node { if b.node != nil { return b.node } - DebugNodeChildren() + Data.ListChildren(true) b.Dump() log.Println("gui.FindNode() on GuiBox is nil") os.Exit(-1) diff --git a/window-debug.go b/window-debug.go index c68468d..308c3ea 100644 --- a/window-debug.go +++ b/window-debug.go @@ -9,13 +9,21 @@ import ( ) var names = make([]string, 100) +var nodeNames = make([]string, 100) + +// TODO: remove this crap +func addNodeName(c *ui.Combobox, s string) { + c.Append(s) + nodeNames[y] = s + y = y + 1 +} func makeWindowDebug() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "Window") + vbox := addGroup(hbox, "range Data.WindowMap") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { @@ -132,6 +140,28 @@ func makeWindowDebug() ui.Control { DumpMap() }) + ///////////////////////////////////////////////////// + nodeBox := addGroup(hbox, "range Data.NodeMap") + nodeCombo := ui.NewCombobox() + + for name, node := range Data.NodeMap { + log.Println("range Data.NodeMap() name =", name) + addNodeName(nodeCombo, node.id) + } + nodeCombo.SetSelected(0) + + nodeBox.Append(nodeCombo, false) + + nodeCombo.OnSelected(func(*ui.Combobox) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.Dump() + } + }) + ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Node Debug") @@ -145,9 +175,14 @@ func makeWindowDebug() ui.Control { DebugDataNodeChildren() }) - n3 := addButton(vbox, "Node.ListChildren()") + n3 := addButton(vbox, "Node.ListChildren(false)") n3.OnClicked(func(*ui.Button) { - DebugNodeChildren() + Data.ListChildren(false) + }) + + n4 := addButton(vbox, "Node.ListChildren(true)") + n4.OnClicked(func(*ui.Button) { + Data.ListChildren(true) }) /* @@ -161,8 +196,11 @@ func makeWindowDebug() ui.Control { return hbox } +// TODO: remove this crap var x int = 0 +var y int = 0 +// TODO: remove this crap func addName(c *ui.Combobox, s string) { c.Append(s) names[x] = s diff --git a/window.go b/window.go index 75a427c..e603050 100644 --- a/window.go +++ b/window.go @@ -131,7 +131,7 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } } if (box.node == nil) { - DebugNodeChildren() + Data.ListChildren(true) log.Println("InitWindow() box has a FUCKING nil node") fn := FindNode("full initTab") log.Println("InitWindow() fn =", fn) @@ -139,7 +139,7 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } if (newGuiWindow.node == nil) { - DebugNodeChildren() + Data.ListChildren(true) log.Println("InitWindow() newGuiWindow has a FUCKING nil node") // panic(-1) } From 310569479b167092a6f4873b82cdf129c3bf8b7c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 03:04:15 -0500 Subject: [PATCH 042/113] NODE: walking around in the rabbit hole --- debug.go | 23 ++++++++++------------- new-structs.go | 12 ++++++++---- window-debug.go | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/debug.go b/debug.go index d5273e0..9d6ad3b 100644 --- a/debug.go +++ b/debug.go @@ -114,14 +114,10 @@ func addTableTab() { time.Sleep(1 * time.Second) } -func DebugDataNodeMap() { - if Data.NodeMap == nil { - log.Println("DebugDataNodeMap() NodeMap == nil") - return - } +func (dn *GuiData) DumpNodeMap() { log.Println("DebugDataNodeMap():") - for name, node := range Data.NodeMap { - log.Println("\tNode name =", node.Width, node.Height, name) + for name, node := range dn.NodeMap { + log.Println("\tNode =", node.id, node.Width, node.Height, name) if (node.children == nil) { log.Println("\t\tNo children") } else { @@ -173,12 +169,12 @@ func FindNode(name string) *Node { func (dn *GuiData) ListChildren(dump bool) { if Data.NodeMap == nil { - log.Println("Data.NodeMap == nil") + log.Println("gui.Data.ListChildren() Data.NodeMap == nil") return } - log.Println("Dumping Data.NodeMap:") + log.Println("gui.Data.ListChildren() Data.NodeMap:") for name, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + log.Println("\tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) if (dump == true) { node.Dump() } @@ -188,13 +184,14 @@ func (dn *GuiData) ListChildren(dump bool) { func (dn *GuiData) findId(id string) *Node { if Data.NodeMap == nil { - log.Println("Data.NodeMap == nil") + log.Println("gui.Data.findId() map == nil") return nil } - log.Println("Dumping Data.NodeMap:") + // log.Println("Dumping Data.NodeMap:") for name, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + // log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) if (id == node.id) { + log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name) return node } // TODO: fix // Oct 9 diff --git a/new-structs.go b/new-structs.go index 4c24692..d5aa2fb 100644 --- a/new-structs.go +++ b/new-structs.go @@ -102,14 +102,16 @@ func (n *Node) List() { func (n *Node) ListChildren(dump bool) { log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height) + if (dump == true) { + n.Dump() + } if len(n.children) == 0 { if (n.parent != nil) { log.Println("\t\t\tparent =",n.parent.id) } - log.Println("\t\tNo children START") + log.Println("\t\t", n.id, "has no children") return } - // spew.Dump(n) for _, child := range n.children { log.Println("\t\tListChildren() child =",child.id, child.Name, child.Width, child.Height) if (child.parent != nil) { @@ -118,12 +120,14 @@ func (n *Node) ListChildren(dump bool) { log.Println("\t\t\tno parent") panic("no parent") } + /* if (dump == true) { child.Dump() } + */ if (child.children == nil) { - log.Println("\t\t\tNo children END") - // break + log.Println("\t\t", child.id, "has no children") + break } log.Println("\t\t\tHas children:", child.children) child.ListChildren(dump) diff --git a/window-debug.go b/window-debug.go index 308c3ea..9b0525a 100644 --- a/window-debug.go +++ b/window-debug.go @@ -165,26 +165,48 @@ func makeWindowDebug() ui.Control { ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Node Debug") - n1 := addButton(vbox, "DebugDataNodeMap()") + n1 := addButton(vbox, "Data.DumpNodeMap()") n1.OnClicked(func(*ui.Button) { - DebugDataNodeMap() + Data.DumpNodeMap() }) - n2 := addButton(vbox, "DebugDataNodeChildren()") - n2.OnClicked(func(*ui.Button) { + n1 = addButton(vbox, "DebugDataNodeChildren()") + n1.OnClicked(func(*ui.Button) { DebugDataNodeChildren() }) - n3 := addButton(vbox, "Node.ListChildren(false)") - n3.OnClicked(func(*ui.Button) { + n1 = addButton(vbox, "Data.ListChildren(false)") + n1.OnClicked(func(*ui.Button) { Data.ListChildren(false) }) - n4 := addButton(vbox, "Node.ListChildren(true)") - n4.OnClicked(func(*ui.Button) { + n1 = addButton(vbox, "Data.ListChildren(true)") + n1.OnClicked(func(*ui.Button) { Data.ListChildren(true) }) + n1 = addButton(vbox, "Node.ListChildren(false)") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.ListChildren(false) + } + }) + + n1 = addButton(vbox, "Node.ListChildren(true)") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.ListChildren(true) + } + }) + /* ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Numbers") From 043c5d7fcbaad15942ffd30f7e8838410977c824 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 05:31:59 -0500 Subject: [PATCH 043/113] NODE: going down a rabbit hole --- box.go | 2 +- debug.go | 2 ++ window-debug.go | 2 ++ window.go | 35 ++++++++++++++++------------------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/box.go b/box.go index 0d2a487..1b08945 100644 --- a/box.go +++ b/box.go @@ -60,9 +60,9 @@ func add(box *GuiBox, newbox *GuiBox) { } if (box.UiBox == nil) { - DebugDataNodeChildren() box.Dump() return + // TODO: fix this whole add() function // Oct 9 panic("gui.add() ERROR box.UiBox == nil") } box.UiBox.Append(newbox.UiBox, false) diff --git a/debug.go b/debug.go index 9d6ad3b..ce18b2d 100644 --- a/debug.go +++ b/debug.go @@ -128,6 +128,7 @@ func (dn *GuiData) DumpNodeMap() { } } +/* func DebugDataNodeChildren() { if Data.NodeMap == nil { log.Println("DebugDataNodeChildren() NodeMap == nil") @@ -143,6 +144,7 @@ func DebugDataNodeChildren() { log.Println("\t\tHas children:", node.children) } } +*/ func FindNode(name string) *Node { if Data.NodeMap == nil { diff --git a/window-debug.go b/window-debug.go index 9b0525a..c440e03 100644 --- a/window-debug.go +++ b/window-debug.go @@ -170,10 +170,12 @@ func makeWindowDebug() ui.Control { Data.DumpNodeMap() }) +/* n1 = addButton(vbox, "DebugDataNodeChildren()") n1.OnClicked(func(*ui.Button) { DebugDataNodeChildren() }) +*/ n1 = addButton(vbox, "Data.ListChildren(false)") n1.OnClicked(func(*ui.Button) { diff --git a/window.go b/window.go index e603050..cfab004 100644 --- a/window.go +++ b/window.go @@ -70,7 +70,7 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { // This is the first window. One must create it here if gw == nil { log.Println("gui.initWindow() ADDING ui.NewWindow()") - node = uiNewWindow(node, name, Config.Width, Config.Height) + node.uiNewWindow(name, Config.Width, Config.Height) box.node = node if (node.box == nil) { node.box = box @@ -248,11 +248,7 @@ func makeNode(parent *Node, title string, x int, y int) *Node { return &node } -func uiNewWindow(node *Node, title string, x int, y int) *Node { - if (node == nil) { - node = makeNode(nil, title, x, y) - } - +func (n *Node) uiNewWindow(title string, x int, y int) { w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) w.OnClosing(func(*ui.Window) bool { @@ -261,18 +257,18 @@ func uiNewWindow(node *Node, title string, x int, y int) *Node { }) w.SetMargined(true) w.Show() - node.uiWindow = w + n.uiWindow = w // w.node = &node - return node + return } func CreateBlankWindow(title string, x int, y int) *Node { - n := mapWindow(nil, nil, title, x, y) - box := n.box + node := mapWindow(nil, nil, title, x, y) + box := node.box log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) - n = uiNewWindow(n, box.Name, x, y) - window := n.uiWindow + node.uiNewWindow(box.Name, x, y) + window := node.uiWindow ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) @@ -281,7 +277,7 @@ func CreateBlankWindow(title string, x int, y int) *Node { }) box.Window.UiWindow = window - return n + return node } func initBlankWindow() ui.Control { @@ -333,13 +329,14 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod return node } -func NewWindow(title string, x int, y int) *GuiBox { - n := mapWindow(nil, nil, title, x, y) - box := n.box +func NewWindow(title string, x int, y int) *Node { + var node *Node + node = mapWindow(nil, nil, title, x, y) + box := node.box log.Println("gui.NewWindow() title = box.Name =", box.Name) - n = uiNewWindow(n, box.Name, x, y) - window := n.uiWindow + node.uiNewWindow(box.Name, x, y) + window := node.uiWindow ui.OnShouldQuit(func() bool { log.Println("createWindow().Destroy()", box.Name) @@ -348,5 +345,5 @@ func NewWindow(title string, x int, y int) *GuiBox { }) box.Window.UiWindow = window - return box + return node } From 3d6e0e55183d19bde39b41965ee53bfe31a196f6 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 06:38:32 -0500 Subject: [PATCH 044/113] NODE: walking around in the rabbit hole --- gui.go | 1 + new-structs.go | 79 ++++++++++++++++++++++++++++++++++++-------------- structs.go | 1 + window.go | 27 +++++++++++++++-- 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/gui.go b/gui.go index 9e7c253..ccefa00 100644 --- a/gui.go +++ b/gui.go @@ -21,6 +21,7 @@ func init() { Data.NodeMap = make(map[string]*Node) Config.counter = 0 + Config.prefix = "jwc" } func GuiInit() { diff --git a/new-structs.go b/new-structs.go index d5aa2fb..1089fcf 100644 --- a/new-structs.go +++ b/new-structs.go @@ -10,7 +10,33 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) +type Element int + // https://ieftimov.com/post/golang-datastructures-trees/ +const ( + Unknown Element = iota + Window + Tab + Box + Label + Combo +) + +func (s Element) String() string { + switch s { + case Window: + return "window" + case Tab: + return "tab" + case Box: + return "box" + case Label: + return "label" + case Combo: + return "combo" + } + return "unknown" +} type Node struct { id string @@ -120,16 +146,14 @@ func (n *Node) ListChildren(dump bool) { log.Println("\t\t\tno parent") panic("no parent") } - /* if (dump == true) { child.Dump() } - */ if (child.children == nil) { log.Println("\t\t", child.id, "has no children") - break + } else { + log.Println("\t\t\tHas children:", child.children) } - log.Println("\t\t\tHas children:", child.children) child.ListChildren(dump) } return @@ -173,45 +197,56 @@ func findByName(node *Node, name string) *Node { return nil } -func (n *Node) InitTab(title string) *Node { - if n.uiWindow == nil { - n.Dump() +/* +func (parent *Node) InitTab(title string) *Node { + if parent.uiWindow == nil { + parent.Dump() panic("gui.InitTab() ERROR ui.Window == nil") } - if n.box == nil { - n.Dump() + if parent.box == nil { + parent.Dump() panic("gui.InitTab() ERROR box == nil") } tab := ui.NewTab() - n.uiWindow.SetChild(tab) - n.uiWindow.SetMargined(true) + parent.uiWindow.SetChild(tab) + parent.uiWindow.SetMargined(true) + parent.uiTab = tab tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) - newNode := makeNode(n, title, 555, 600 + Config.counter) - newNode.uiTab = tab + newNode := makeNode(parent, title, 555, 600 + Config.counter) return newNode } +*/ -func (n *Node) AddTab(title string, custom func() ui.Control) *Node { - if n.uiWindow == nil { - n.Dump() +func (parent *Node) AddTab(title string) *Node { + if parent.uiWindow == nil { + parent.Dump() panic("gui.AddTab() ERROR ui.Window == nil") } - if n.box == nil { - n.Dump() + if parent.box == nil { + parent.Dump() panic("gui.AddTab() ERROR box == nil") } + if parent.uiTab == nil { + inittab := ui.NewTab() // no, not that 'inittab' + parent.uiWindow.SetChild(inittab) + parent.uiWindow.SetMargined(true) + parent.uiTab = inittab - tab := ui.NewTab() - n.uiWindow.SetMargined(true) + parent.Dump() + // panic("gui.AddTab() ERROR uiTab == nil") + } - tab.Append(title, custom()) + tab := parent.uiTab + parent.uiWindow.SetMargined(true) + + tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) - newNode := makeNode(n, title, 555, 600 + Config.counter) + newNode := makeNode(parent, title, 555, 600 + Config.counter) newNode.uiTab = tab return newNode } diff --git a/structs.go b/structs.go index 961e743..3bb8c05 100644 --- a/structs.go +++ b/structs.go @@ -28,6 +28,7 @@ type GuiConfig struct { depth int counter int // used to make unique ID's + prefix string } type GuiData struct { diff --git a/window.go b/window.go index cfab004..8505242 100644 --- a/window.go +++ b/window.go @@ -213,23 +213,46 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") } - n.InitTab(title) + n.AddTab(title) // TODO: run custom() here // Oct 9 return n } +func (n *Node) Add(e Element) *Node { + newNode := n.addNode("testingAdd") + if(e == Tab) { + log.Println("gui.Add() SHOULD ADD element =", e.String()) + } + return newNode +} + // // Create a new node // if parent == nil, that means it is a new window and needs to be put // in the window map (aka Data.NodeMap) // +func (parent *Node) addNode(title string) *Node { + var node Node + node.Name = title + node.Width = parent.Width + node.Height = parent.Height + node.parent = parent + + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + parent.Append(&node) + return &node +} + func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title node.Width = x node.Height = y - id := "jwc" + strconv.Itoa(Config.counter) + id := Config.prefix + strconv.Itoa(Config.counter) Config.counter += 1 node.id = id From da16b8106c42b8aef0b6190b829a7005aabb82e7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 07:13:58 -0500 Subject: [PATCH 045/113] NODE: walking around in the rabbit hole --- box.go | 30 +++++++++++++----------------- gui-example/main.go | 2 +- new-structs.go | 35 +++++++++-------------------------- structs.go | 26 -------------------------- window.go | 16 ++++++++++++++++ 5 files changed, 39 insertions(+), 70 deletions(-) diff --git a/box.go b/box.go index 1b08945..6b77912 100644 --- a/box.go +++ b/box.go @@ -72,25 +72,18 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() END") } -func (n *Node) NewBox(axis int, name string) *Node { - var newBox *GuiBox - var newNode *Node = n +func (parent *Node) NewBox(axis int, name string) *Node { + if (parent.box == nil) { + panic("gui.Node.NewBox() parent.box == nil") + } - newBox = new(GuiBox) - // newBox.Window = newNode.uiWindow + newBox := new(GuiBox) + newBox.Window = parent.window newBox.Name = name - if (n.box == nil) { - panic("node.newBox() box == nil") - } - if (n.box == nil) { - // add a box here - newBox.node = n - n.box = newBox - } else { - // make a new box & a new node - newNode = makeNode(n, name, 111, 112) - } + // make a new box & a new node + newNode := parent.makeNode(name, 111, 100 + Config.counter) + Config.counter += 1 var uiBox *ui.Box if (axis == Xaxis) { @@ -100,7 +93,10 @@ func (n *Node) NewBox(axis int, name string) *Node { } uiBox.SetPadded(true) newBox.UiBox = uiBox - add(n.box, newBox) + newNode.uiBox = uiBox + + parent.Append(newNode) + // add(n.box, newBox) return newNode } diff --git a/gui-example/main.go b/gui-example/main.go index 5f34f98..cba4545 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -34,7 +34,7 @@ func watchGUI() { for { log.Println("Waiting for customExit()", i) i += 1 - time.Sleep(3 * time.Second) + time.Sleep(1 * time.Second) if i == 2 { log.Println("Sending ExampleWindow to gui.Queue()") gui.Queue(gui.DebugWindow) diff --git a/new-structs.go b/new-structs.go index 1089fcf..ffe83d4 100644 --- a/new-structs.go +++ b/new-structs.go @@ -47,11 +47,13 @@ type Node struct { parent *Node children []*Node + window *GuiWindow box *GuiBox uiControl *ui.Control uiWindow *ui.Window uiTab *ui.Tab + uiBox *ui.Box } func (n *Node) Parent() *Node { @@ -67,12 +69,17 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() Name = ", n.Name) log.Println("gui.Node.Dump() Width = ", n.Width) log.Println("gui.Node.Dump() Height = ", n.Height) + log.Println("gui.Node.Dump() parent = ", n.parent) log.Println("gui.Node.Dump() children = ", n.children) + + log.Println("gui.Node.Dump() window = ", n.window) log.Println("gui.Node.Dump() box = ", n.box) - log.Println("gui.Node.Dump() uiControl = ", n.uiControl) + log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) log.Println("gui.Node.Dump() uiTab = ", n.uiTab) + log.Println("gui.Node.Dump() uiBox = ", n.uiBox) + log.Println("gui.Node.Dump() uiControl = ", n.uiControl) if (n.id == "") { panic("gui.Node.Dump() id == nil") } @@ -197,30 +204,6 @@ func findByName(node *Node, name string) *Node { return nil } -/* -func (parent *Node) InitTab(title string) *Node { - if parent.uiWindow == nil { - parent.Dump() - panic("gui.InitTab() ERROR ui.Window == nil") - } - if parent.box == nil { - parent.Dump() - panic("gui.InitTab() ERROR box == nil") - } - - tab := ui.NewTab() - parent.uiWindow.SetChild(tab) - parent.uiWindow.SetMargined(true) - parent.uiTab = tab - - tab.Append(title, initBlankWindow()) - tab.SetMargined(0, true) - - newNode := makeNode(parent, title, 555, 600 + Config.counter) - return newNode -} -*/ - func (parent *Node) AddTab(title string) *Node { if parent.uiWindow == nil { parent.Dump() @@ -246,7 +229,7 @@ func (parent *Node) AddTab(title string) *Node { tab.Append(title, initBlankWindow()) tab.SetMargined(0, true) - newNode := makeNode(parent, title, 555, 600 + Config.counter) + newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab return newNode } diff --git a/structs.go b/structs.go index 3bb8c05..d09efb8 100644 --- a/structs.go +++ b/structs.go @@ -186,32 +186,6 @@ func (s GuiBox) Append(child ui.Control, x bool) { s.UiBox.Append(child, x) } -/* -func (s GuiBox) InitTab(title string, custom func() ui.Control) *Node { - if s.Window == nil { - return nil - } - if s.Window.UiWindow == nil { - return nil - } - - window := s.Window.UiWindow - tab := ui.NewTab() - window.SetChild(tab) - window.SetMargined(true) - - tab.Append(title, custom()) - tab.SetMargined(0, true) - // tab.SetMargined(1, true) - - s.Window.UiTab = tab - if s.node == nil { - log.Println("Fuck node = ", s.node) - os.Exit(-1) - } - return s.node -} -*/ func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { if s.Window == nil { diff --git a/window.go b/window.go index 8505242..2f7c58a 100644 --- a/window.go +++ b/window.go @@ -20,6 +20,7 @@ func initUI(name string, callback func(*GuiBox) *GuiBox) { box := node.box box = callback(box) window := box.Window + node.window = window log.Println("StartNewWindow() box =", box) window.UiWindow.Show() @@ -271,6 +272,21 @@ func makeNode(parent *Node, title string, x int, y int) *Node { return &node } +func (parent *Node) makeNode(title string, x int, y int) *Node { + var node Node + node.Name = title + node.Width = x + node.Height = y + + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + parent.Append(&node) + node.parent = parent + return &node +} + func (n *Node) uiNewWindow(title string, x int, y int) { w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) From b3e00c173b474941d4a46d82bfc59102985cb0f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 10:46:57 -0500 Subject: [PATCH 046/113] NODE: climbing up the rabbit hole --- new-structs.go | 13 ++++++++++--- structs.go | 9 ++++++--- window-debug.go | 17 ++++++++++++++++- window.go | 4 ++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/new-structs.go b/new-structs.go index ffe83d4..ffc90b9 100644 --- a/new-structs.go +++ b/new-structs.go @@ -70,7 +70,11 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() Width = ", n.Width) log.Println("gui.Node.Dump() Height = ", n.Height) - log.Println("gui.Node.Dump() parent = ", n.parent) + if (n.parent == nil) { + log.Println("gui.Node.Dump() parent = nil") + } else { + log.Println("gui.Node.Dump() parent = ", n.parent.id) + } log.Println("gui.Node.Dump() children = ", n.children) log.Println("gui.Node.Dump() window = ", n.window) @@ -204,7 +208,7 @@ func findByName(node *Node, name string) *Node { return nil } -func (parent *Node) AddTab(title string) *Node { +func (parent *Node) AddTab(title string, uiC ui.Control) *Node { if parent.uiWindow == nil { parent.Dump() panic("gui.AddTab() ERROR ui.Window == nil") @@ -226,7 +230,10 @@ func (parent *Node) AddTab(title string) *Node { tab := parent.uiTab parent.uiWindow.SetMargined(true) - tab.Append(title, initBlankWindow()) + if (uiC == nil) { + uiC = parent.initBlankWindow() + } + tab.Append(title, uiC) tab.SetMargined(0, true) newNode := parent.makeNode(title, 555, 600 + Config.counter) diff --git a/structs.go b/structs.go index d09efb8..f15a0e0 100644 --- a/structs.go +++ b/structs.go @@ -200,6 +200,7 @@ func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { return tab } +/* func (s GuiBox) AddBoxTab(title string) *GuiBox { uiTab := s.AddTab(title, initBlankWindow()) tabSetMargined(uiTab) @@ -209,10 +210,12 @@ func (s GuiBox) AddBoxTab(title string) *GuiBox { box.Window.UiTab = uiTab return box } +*/ -func (s GuiBox) AddDemoTab(title string) { - uiTab := s.AddTab(title, makeWindowTemplate()) - tabSetMargined(uiTab) +func (n *Node) AddDemoTab(title string) { + newNode := n.AddTab(title, makeWindowTemplate()) + newNode.Dump() + tabSetMargined(newNode.uiTab) } func (s GuiBox) AddDebugTab(title string) { diff --git a/window-debug.go b/window-debug.go index c440e03..de4b31b 100644 --- a/window-debug.go +++ b/window-debug.go @@ -187,6 +187,17 @@ func makeWindowDebug() ui.Control { Data.ListChildren(true) }) + n1 = addButton(vbox, "Node.Dump()") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.Dump() + } + }) + n1 = addButton(vbox, "Node.ListChildren(false)") n1.OnClicked(func(*ui.Button) { y := nodeCombo.Selected() @@ -269,7 +280,10 @@ func FindBox(s string) *GuiBox { } func dumpBox(s string) { - for name, window := range Data.WindowMap { + var name string + var window *GuiWindow + + for name, window = range Data.WindowMap { if name != s { continue } @@ -286,6 +300,7 @@ func dumpBox(s string) { log.Println("gui.dumpBox() BoxMap START") for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + abox.Dump() if name == "MAINBOX" { if Config.Debug { scs := spew.ConfigState{MaxDepth: 1} diff --git a/window.go b/window.go index 2f7c58a..3543b2b 100644 --- a/window.go +++ b/window.go @@ -214,7 +214,7 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") } - n.AddTab(title) + n.AddTab(title, custom()) // TODO: run custom() here // Oct 9 return n } @@ -319,7 +319,7 @@ func CreateBlankWindow(title string, x int, y int) *Node { return node } -func initBlankWindow() ui.Control { +func (n *Node) initBlankWindow() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) From 9ea89ac01ffd24d6daa325d72a59a46cc3ad37dc Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 11:23:27 -0500 Subject: [PATCH 047/113] NODE: walking around in the rabbit hole --- main.go | 4 ++-- new-structs.go | 17 +++++++++++++++++ structs.go | 10 ++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0876e4a..688e949 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func ExampleWindow() { window := box.Window log.Println("box =", box) log.Println("window =", window) - box.AddDebugTab("jcarr Debug") + // box.AddDebugTab("jcarr Debug") window.UiWindow.Show() } @@ -50,7 +50,7 @@ func DebugWindow() { window := box.Window log.Println("box =", box) log.Println("window =", window) - box.AddDebugTab("jcarr Debug") + // box.AddDebugTab("jcarr Debug") window.UiWindow.Show() } diff --git a/new-structs.go b/new-structs.go index ffc90b9..d6741c4 100644 --- a/new-structs.go +++ b/new-structs.go @@ -90,6 +90,10 @@ func (n *Node) Dump() { } +func (n *Node) SetBox(box *GuiBox) { + n.box = box +} + func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.uiWindow != nil) { @@ -208,6 +212,19 @@ func findByName(node *Node, name string) *Node { return nil } +func (parent *Node) AddTabNode(title string, n *Node) *Node { + // Ybox := gui.NewBox(box, gui.Yaxis, "Working Stuff") + // var baseControl ui.Control + // baseControl = Ybox.UiBox + // return baseControl + + parent.Dump() + + newNode := parent.makeNode(title, 444, 400 + Config.counter) + newNode.uiTab = parent.uiTab + return newNode +} + func (parent *Node) AddTab(title string, uiC ui.Control) *Node { if parent.uiWindow == nil { parent.Dump() diff --git a/structs.go b/structs.go index f15a0e0..b7520d1 100644 --- a/structs.go +++ b/structs.go @@ -186,7 +186,7 @@ func (s GuiBox) Append(child ui.Control, x bool) { s.UiBox.Append(child, x) } - +/* func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { if s.Window == nil { return nil @@ -199,6 +199,7 @@ func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { tab.Append(title, custom) return tab } +*/ /* func (s GuiBox) AddBoxTab(title string) *GuiBox { @@ -218,9 +219,10 @@ func (n *Node) AddDemoTab(title string) { tabSetMargined(newNode.uiTab) } -func (s GuiBox) AddDebugTab(title string) { - uiTab := s.AddTab(title, makeWindowDebug()) - tabSetMargined(uiTab) +func (n *Node) AddDebugTab(title string) { + newNode := n.AddTab(title, makeWindowDebug()) + newNode.Dump() + tabSetMargined(newNode.uiTab) } func tabSetMargined(tab *ui.Tab) { From af1042c85dd40e040b37190b363e5d9e829734e0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 9 Oct 2021 19:25:52 -0500 Subject: [PATCH 048/113] NODE: climbing up the rabbit hole --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 688e949..203edff 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,7 @@ func ExampleWindow() { window := box.Window log.Println("box =", box) log.Println("window =", window) - // box.AddDebugTab("jcarr Debug") + node.AddDebugTab("jcarr Debug") window.UiWindow.Show() } @@ -50,7 +50,7 @@ func DebugWindow() { window := box.Window log.Println("box =", box) log.Println("window =", window) - // box.AddDebugTab("jcarr Debug") + node.AddDebugTab("jcarr Debug") window.UiWindow.Show() } From f71355f57152197d46fe8543c6bd8389ecdbafe4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 11 Oct 2021 03:39:15 -0500 Subject: [PATCH 049/113] NODE: walking around in the rabbit hole --- new-structs.go | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/new-structs.go b/new-structs.go index d6741c4..397372c 100644 --- a/new-structs.go +++ b/new-structs.go @@ -2,6 +2,7 @@ package gui import ( "log" + "fmt" // "time" // "github.com/davecgh/go-spew/spew" @@ -212,16 +213,50 @@ func findByName(node *Node, name string) *Node { return nil } -func (parent *Node) AddTabNode(title string, n *Node) *Node { +// The parent Node needs to be the raw Window +// The 'stuff' Node needs to be the contents of the tab +// +// This function should make a new node with the parent and +// the 'stuff' Node as a child +func (parent *Node) AddTabNode(title string, b *GuiBox) *Node { // Ybox := gui.NewBox(box, gui.Yaxis, "Working Stuff") // var baseControl ui.Control // baseControl = Ybox.UiBox // return baseControl + var newNode *Node + // var newControl ui.Control + + if (parent.box == nil) { + // TODO: fix this to use a blank box + uiC := parent.initBlankWindow() + newNode.uiControl = &uiC + panic("node.AddTabNode() can not add a tab if the box == nil") + } + if (parent.uiTab == nil) { + panic("node.AddTabNode() can not add a tab if parent.uiTab == nil") + } + + newNode = parent.makeNode(title, 444, 400 + Config.counter) + newNode.uiTab = parent.uiTab + newNode.box = b + + /* + newControl = b.UiBox + newNode.uiTab.Append(title, newControl) + */ + newNode.uiTab.Append(title, b.UiBox) + + fmt.Println("") + log.Println("parent:") parent.Dump() - newNode := parent.makeNode(title, 444, 400 + Config.counter) - newNode.uiTab = parent.uiTab + fmt.Println("") + log.Println("newNode:") + newNode.Dump() + + // panic("node.AddTabNode()") + return newNode } From 4e0b71320193f838c1205d2dccf142991ceaf03c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 24 Oct 2021 09:01:51 -0500 Subject: [PATCH 050/113] NODE: it builds, runs and doesn't crash Also, it doesn't really work as the formatting and other buttons and things don't get populated --- box.go | 10 ++++++---- debug.go | 13 ++++++------- gui.go | 2 ++ new-structs.go | 14 +++++++++----- structs.go | 2 ++ tableCallbacks.go | 3 ++- window.go | 30 ++++++++++++++++++++++++++---- 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/box.go b/box.go index 6b77912..51da1c5 100644 --- a/box.go +++ b/box.go @@ -35,6 +35,7 @@ func add(box *GuiBox, newbox *GuiBox) { newbox.Window.BoxMap["MAINBOX"] = newbox log.Println("gui.add() END") + panic("gui.add() MAINBOX gui.add() END") return } else { log.Println("\tgui.add() ERROR DONT KNOW HOW TO ADD TO A RAW WINDOW YET") @@ -42,6 +43,7 @@ func add(box *GuiBox, newbox *GuiBox) { } log.Println("\tgui.add() ERROR DON'T KNOW HOW TO add to Window as MAINBOX DONE") log.Println("gui.add() END") + panic("gui.add() gui.add() END") return } log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) @@ -56,16 +58,15 @@ func add(box *GuiBox, newbox *GuiBox) { panic("gui.add() ERROR newbox.UiBox == nil") } - if (box.UiBox == nil) { - } - if (box.UiBox == nil) { box.Dump() + // panic("gui.add() ERROR box.UiBox == nil") return // TODO: fix this whole add() function // Oct 9 - panic("gui.add() ERROR box.UiBox == nil") } box.UiBox.Append(newbox.UiBox, false) + box.Dump() + panic("gui.add()") // add the newbox to the Window.BoxMap[] box.Window.BoxMap[newbox.Name] = newbox @@ -123,6 +124,7 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { uiBox.SetPadded(true) newbox.UiBox = uiBox add(box, newbox) + // panic("gui.NewBox") return newbox } diff --git a/debug.go b/debug.go index ce18b2d..e548b98 100644 --- a/debug.go +++ b/debug.go @@ -9,14 +9,13 @@ import ( "github.com/davecgh/go-spew/spew" ) -// import "reflect" - -// import "github.com/andlabs/ui" -// import _ "github.com/andlabs/ui/winmanifest" - -// -// Dump out debugging information every 4 seconds +// WatchGUI() opens a goroutine // +// From that goroutine, it dumps out debugging information every 4 seconds +/* + TODO: add configuration triggers on what to dump out + TODO: allow this to be sent to /var/log, syslogd, systemd's journalctl, etc +*/ func WatchGUI() { count := 0 diff --git a/gui.go b/gui.go index ccefa00..0c903b4 100644 --- a/gui.go +++ b/gui.go @@ -20,6 +20,8 @@ func init() { Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) + Data.NodeSlice = make([]*Node, 0) + Config.counter = 0 Config.prefix = "jwc" } diff --git a/new-structs.go b/new-structs.go index 397372c..d1ed875 100644 --- a/new-structs.go +++ b/new-structs.go @@ -130,10 +130,12 @@ func (n *Node) Append(child *Node) { // return // } n.children = append(n.children, child) - log.Println("child node:") - child.Dump() - log.Println("parent node:") - n.Dump() + if (Config.Debug) { + log.Println("child node:") + child.Dump() + log.Println("parent node:") + n.Dump() + } // time.Sleep(3 * time.Second) } @@ -275,7 +277,7 @@ func (parent *Node) AddTab(title string, uiC ui.Control) *Node { parent.uiWindow.SetMargined(true) parent.uiTab = inittab - parent.Dump() + // parent.Dump() // panic("gui.AddTab() ERROR uiTab == nil") } @@ -288,7 +290,9 @@ func (parent *Node) AddTab(title string, uiC ui.Control) *Node { tab.Append(title, uiC) tab.SetMargined(0, true) + // panic("gui.AddTab() before makeNode()") newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab + // panic("gui.AddTab() after makeNode()") return newNode } diff --git a/structs.go b/structs.go index b7520d1..dca855f 100644 --- a/structs.go +++ b/structs.go @@ -42,6 +42,8 @@ type GuiData struct { // Store access to everything via binary tree's NodeMap map[string]*Node + NodeArray []*Node + NodeSlice []*Node // A map of all buttons everywhere on all // windows, all tabs, across all goroutines diff --git a/tableCallbacks.go b/tableCallbacks.go index 966f173..6eefd8d 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -30,7 +30,8 @@ func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue { } // TODO: Figure out why this is being called 1000 times a second (10 times for each row & column) -// Nevermind this TODO. Who gives a shit. This is a really smart way to treat the OS toolkits +// +// Nevermind that TODO. Who gives a shit. This is a really smart way to treat the OS toolkits func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue { if (Config.DebugTable) { log.Println("CellValue() row, column =", row, column) diff --git a/window.go b/window.go index 3543b2b..4940e35 100644 --- a/window.go +++ b/window.go @@ -2,6 +2,7 @@ package gui import ( "log" + "fmt" "strconv" "time" @@ -257,16 +258,24 @@ func makeNode(parent *Node, title string, x int, y int) *Node { Config.counter += 1 node.id = id + // panic("gui.makeNode() START") if (parent == nil) { if (Data.NodeMap[title] != nil) { log.Println("Duplicate uiNewWindow() name =", title) // TODO: just change the 'title' to something unique + panic(fmt.Sprintf("Duplicate uiNewWindow() name = %s\n", title)) return nil } + // panic("gui.makeNode() before NodeMap()") Data.NodeMap[title] = &node + Data.NodeArray = append(Data.NodeArray, &node) + Data.NodeSlice = append(Data.NodeSlice, &node) + // panic("gui.makeNode() after NodeMap()") return &node } else { + panic("gui.makeNode() before Append()") parent.Append(&node) + panic("gui.makeNode() after Append()") } node.parent = parent return &node @@ -326,14 +335,28 @@ func (n *Node) initBlankWindow() ui.Control { return hbox } -var master = 0 +func makeBlankNode(title string) *Node { + log.Println("gui.makeBlankNode() title =", title) + if Data.NodeMap[title] != nil { + log.Println("gui.makeBlankNode() already exists title =", title) + title = title + Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + } + if Data.NodeMap[title] != nil { + panic("gui.makeBlankNode() already exists") + return nil + } + + node := makeNode(nil, title, x, y) + return node +} func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) - master = master + 1 - title = title + " jcarr " + strconv.Itoa(master) + title = title + Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 } if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) @@ -357,7 +380,6 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod box.Window = &newGuiWindow box.Name = title - // func makeNode(parent *Node, title string, x int, y int) *Node { node := makeNode(parent, title, x, y) node.box = &box node.uiWindow = window From 585e7f00f04fa45ff9be874e357f2c53574820ae Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 05:00:12 -0500 Subject: [PATCH 051/113] DEBUG: add buttons to add demo & debug tabs. TabMargin is now always set to true Signed-off-by: Jeff Carr --- structs.go | 49 ------------------------------------------------- window-debug.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/structs.go b/structs.go index dca855f..8833dd5 100644 --- a/structs.go +++ b/structs.go @@ -188,55 +188,6 @@ func (s GuiBox) Append(child ui.Control, x bool) { s.UiBox.Append(child, x) } -/* -func (s *GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { - if s.Window == nil { - return nil - } - if s.Window.UiTab == nil { - return nil - } - - tab := s.Window.UiTab - tab.Append(title, custom) - return tab -} -*/ - -/* -func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab(title, initBlankWindow()) - tabSetMargined(uiTab) - - var box *GuiBox - box = HardBox(s.Window, Xaxis, "jcarrAddBoxTab") - box.Window.UiTab = uiTab - return box -} -*/ - -func (n *Node) AddDemoTab(title string) { - newNode := n.AddTab(title, makeWindowTemplate()) - newNode.Dump() - tabSetMargined(newNode.uiTab) -} - -func (n *Node) AddDebugTab(title string) { - newNode := n.AddTab(title, makeWindowDebug()) - newNode.Dump() - tabSetMargined(newNode.uiTab) -} - -func tabSetMargined(tab *ui.Tab) { - log.Println("tabSetMargined() IGNORE THIS") - return - c := tab.NumPages() - for i := 0; i < c; i++ { - log.Println("tabSetMargined() i =", i) - // tab.SetMargined(i, true) - } -} - // Note: every mouse click is handled // as a 'Button' regardless of where // the user clicks it. You could probably diff --git a/window-debug.go b/window-debug.go index de4b31b..ef457aa 100644 --- a/window-debug.go +++ b/window-debug.go @@ -12,6 +12,8 @@ var names = make([]string, 100) var nodeNames = make([]string, 100) // TODO: remove this crap +// What does this actually do? +// It populates the nodeNames in a map. No, not a map, an array. What is the difference again? func addNodeName(c *ui.Combobox, s string) { c.Append(s) nodeNames[y] = s @@ -220,6 +222,28 @@ func makeWindowDebug() ui.Control { } }) + n1 = addButton(vbox, "Node.AddDebugTab") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.AddDebugTab("added this DebugTab") + } + }) + + n1 = addButton(vbox, "Node.DemoTab") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.AddDemoTab("added this DemoTab") + } + }) + /* ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Numbers") @@ -331,3 +355,27 @@ func addButton(box *ui.Box, name string) *ui.Button { box.Append(button, false) return button } + +func (n *Node) AddDemoTab(title string) { + newNode := n.AddTab(title, makeWindowTemplate()) + newNode.Dump() + tabSetMargined(newNode.uiTab) +} + +func (n *Node) AddDebugTab(title string) { + newNode := n.AddTab(title, makeWindowDebug()) + newNode.Dump() + tabSetMargined(newNode.uiTab) +} + +// This sets _all_ the tabs to Margin = true +// +// TODO: do proper tab tracking (will be complicated). low priority +func tabSetMargined(tab *ui.Tab) { + log.Println("tabSetMargined() IGNORE THIS") + c := tab.NumPages() + for i := 0; i < c; i++ { + log.Println("tabSetMargined() i =", i) + tab.SetMargined(i, true) + } +} From 9a07e2b2af75202621ad966b8ccd4ee1c53a2734 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 05:25:10 -0500 Subject: [PATCH 052/113] EXAMPLE: correctly add a tab to the example app Signed-off-by: Jeff Carr --- gui-example/main.go | 5 +++-- gui.go | 2 ++ structs.go | 2 ++ window-debug.go | 18 +++++++++--------- window-template.go | 8 ++++++++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gui-example/main.go b/gui-example/main.go index cba4545..69f3172 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -26,7 +26,8 @@ func main() { } func initGUI() { - gui.NewWindow("jcarr start", 640, 480) + n := gui.NewWindow("jcarr start", 640, 480) + n.AddDemoTab("up the rabbit hole") } func watchGUI() { @@ -35,7 +36,7 @@ func watchGUI() { log.Println("Waiting for customExit()", i) i += 1 time.Sleep(1 * time.Second) - if i == 2 { + if i == 4 { log.Println("Sending ExampleWindow to gui.Queue()") gui.Queue(gui.DebugWindow) } diff --git a/gui.go b/gui.go index 0c903b4..b9a8d06 100644 --- a/gui.go +++ b/gui.go @@ -24,6 +24,8 @@ func init() { Config.counter = 0 Config.prefix = "jwc" + Config.DebugNode = false + Config.DebugTabs = false } func GuiInit() { diff --git a/structs.go b/structs.go index 8833dd5..80c763d 100644 --- a/structs.go +++ b/structs.go @@ -23,6 +23,8 @@ type GuiConfig struct { Width int Height int Debug bool + DebugNode bool + DebugTabs bool DebugTable bool Exit func(*GuiWindow) diff --git a/window-debug.go b/window-debug.go index ef457aa..3afe8e3 100644 --- a/window-debug.go +++ b/window-debug.go @@ -356,15 +356,11 @@ func addButton(box *ui.Box, name string) *ui.Button { return button } -func (n *Node) AddDemoTab(title string) { - newNode := n.AddTab(title, makeWindowTemplate()) - newNode.Dump() - tabSetMargined(newNode.uiTab) -} - func (n *Node) AddDebugTab(title string) { newNode := n.AddTab(title, makeWindowDebug()) - newNode.Dump() + if (Config.DebugNode) { + newNode.Dump() + } tabSetMargined(newNode.uiTab) } @@ -372,10 +368,14 @@ func (n *Node) AddDebugTab(title string) { // // TODO: do proper tab tracking (will be complicated). low priority func tabSetMargined(tab *ui.Tab) { - log.Println("tabSetMargined() IGNORE THIS") + if (Config.DebugTabs) { + log.Println("tabSetMargined() IGNORE THIS") + } c := tab.NumPages() for i := 0; i < c; i++ { - log.Println("tabSetMargined() i =", i) + if (Config.DebugTabs) { + log.Println("tabSetMargined() i =", i) + } tab.SetMargined(i, true) } } diff --git a/window-template.go b/window-template.go index c3e30ef..82162dd 100644 --- a/window-template.go +++ b/window-template.go @@ -4,6 +4,14 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +func (n *Node) AddDemoTab(title string) { + newNode := n.AddTab(title, makeWindowTemplate()) + if (Config.DebugNode) { + newNode.Dump() + } + tabSetMargined(newNode.uiTab) +} + func makeWindowTemplate() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) From e907164e176fe823c14b861d1b3e9c083860de34 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 05:41:12 -0500 Subject: [PATCH 053/113] CLEAN: clean up labels Signed-off-by: Jeff Carr --- find.go | 35 +++++++++++++++++++++++++ gui-example/main.go | 9 ++++--- gui.go | 2 +- main.go | 14 ---------- window-debug.go | 39 ++++++++++------------------ window-template.go => window-demo.go | 0 6 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 find.go rename window-template.go => window-demo.go (100%) diff --git a/find.go b/find.go new file mode 100644 index 0000000..baf1a45 --- /dev/null +++ b/find.go @@ -0,0 +1,35 @@ +package gui + +import ( + "log" + +// "github.com/andlabs/ui" +// _ "github.com/andlabs/ui/winmanifest" +// "github.com/davecgh/go-spew/spew" +) + + +func FindWindow(s string) *GuiWindow { + for name, window := range Data.WindowMap { + if name == s { + return window + } + } + log.Printf("COULD NOT FIND WINDOW", s) + return nil +} + +func FindBox(s string) *GuiBox { + for name, window := range Data.WindowMap { + if name != s { + continue + } + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + return abox + } + log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) + } + log.Println("gui.FindBox() COULD NOT FIND BOX", s) + return nil +} diff --git a/gui-example/main.go b/gui-example/main.go index 69f3172..c9e8cbd 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -26,10 +26,13 @@ func main() { } func initGUI() { - n := gui.NewWindow("jcarr start", 640, 480) - n.AddDemoTab("up the rabbit hole") + n := gui.NewWindow("WIT GUI Example Window", 640, 480) + n.AddDemoTab("A Simple Tab Demo") } +// This demonstrates how to properly interact with the GUI +// You can not involke the GUI from external goroutines in most cases. + func watchGUI() { var i = 1 for { @@ -37,7 +40,7 @@ func watchGUI() { i += 1 time.Sleep(1 * time.Second) if i == 4 { - log.Println("Sending ExampleWindow to gui.Queue()") + log.Println("Opening a Debug Window via the gui.Queue()") gui.Queue(gui.DebugWindow) } } diff --git a/gui.go b/gui.go index b9a8d06..4174133 100644 --- a/gui.go +++ b/gui.go @@ -23,7 +23,7 @@ func init() { Data.NodeSlice = make([]*Node, 0) Config.counter = 0 - Config.prefix = "jwc" + Config.prefix = "wit" Config.DebugNode = false Config.DebugTabs = false } diff --git a/main.go b/main.go index 203edff..9c8092f 100644 --- a/main.go +++ b/main.go @@ -40,17 +40,3 @@ func ExampleWindow() { window.UiWindow.Show() } - -func DebugWindow() { - log.Println("START gui.ExampleWindow()") - - title := "Debug Window" - node := InitWindow(nil, nil, title, 0) - box := node.box - window := box.Window - log.Println("box =", box) - log.Println("window =", window) - node.AddDebugTab("jcarr Debug") - - window.UiWindow.Show() -} diff --git a/window-debug.go b/window-debug.go index 3afe8e3..69eb7bb 100644 --- a/window-debug.go +++ b/window-debug.go @@ -11,6 +11,20 @@ import ( var names = make([]string, 100) var nodeNames = make([]string, 100) +func DebugWindow() { + log.Println("START gui.DebugWindow()") + + title := "WIT GUI Debug Window" + node := InitWindow(nil, nil, title, 0) + box := node.box + window := box.Window + log.Println("box =", box) + log.Println("window =", window) + node.AddDebugTab("WIT GUI Debug Tab") + + window.UiWindow.Show() +} + // TODO: remove this crap // What does this actually do? // It populates the nodeNames in a map. No, not a map, an array. What is the difference again? @@ -278,31 +292,6 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } -func FindWindow(s string) *GuiWindow { - for name, window := range Data.WindowMap { - if name == s { - return window - } - } - log.Printf("COULD NOT FIND WINDOW", s) - return nil -} - -func FindBox(s string) *GuiBox { - for name, window := range Data.WindowMap { - if name != s { - continue - } - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - return abox - } - log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) - } - log.Println("gui.FindBox() COULD NOT FIND BOX", s) - return nil -} - func dumpBox(s string) { var name string var window *GuiWindow diff --git a/window-template.go b/window-demo.go similarity index 100% rename from window-template.go rename to window-demo.go From 3ad83abc3aa5f33394ddba89764a8b7feb189460 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 05:46:25 -0500 Subject: [PATCH 054/113] DEMO: leave a clean "pure" andlabs/ui tab example Signed-off-by: Jeff Carr --- window-demo-andlabs-ui.go | 84 +++++++++++++++++++++++++++++++++++++++ window-demo.go | 4 +- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 window-demo-andlabs-ui.go diff --git a/window-demo-andlabs-ui.go b/window-demo-andlabs-ui.go new file mode 100644 index 0000000..f7f5606 --- /dev/null +++ b/window-demo-andlabs-ui.go @@ -0,0 +1,84 @@ +package gui + +import "log" +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +// This will create a tab in a window using direct +// calls to andlabs/ui. This can be used to bypass +// the obvuscation added in this package if it is desired +// or needed. +func (n *Node) AddAndlabsUiDemoTab(title string) { + newNode := n.AddTab(title, makeAndlabsUiTab()) + if (Config.DebugNode) { + newNode.Dump() + } + tabSetMargined(newNode.uiTab) +} + +func makeAndlabsUiTab() ui.Control { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + + group := ui.NewGroup("Numbers") + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + spinbox := ui.NewSpinbox(47, 100) + slider := ui.NewSlider(21, 100) + pbar := ui.NewProgressBar() + + spinbox.OnChanged(func(*ui.Spinbox) { + slider.SetValue(spinbox.Value()) + pbar.SetValue(spinbox.Value()) + }) + slider.OnChanged(func(*ui.Slider) { + spinbox.SetValue(slider.Value()) + pbar.SetValue(slider.Value()) + }) + vbox.Append(spinbox, false) + vbox.Append(slider, false) + vbox.Append(pbar, false) + + ip := ui.NewProgressBar() + ip.SetValue(-1) + vbox.Append(ip, false) + + group = ui.NewGroup("Lists") + group.SetMargined(true) + hbox.Append(group, true) + + vbox = ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + cbox := ui.NewCombobox() + cbox.Append("Combobox Item 1") + cbox.Append("Combobox Item 2") + cbox.Append("Combobox Item 3") + vbox.Append(cbox, false) + + ecbox := ui.NewEditableCombobox() + ecbox.Append("Editable Item 1") + ecbox.Append("Editable Item 2") + ecbox.Append("Editable Item 3") + vbox.Append(ecbox, false) + + ecbox.OnChanged(func(*ui.EditableCombobox) { + log.Println("test") + test := ecbox.Text() + log.Println("test=", test) + }) + + rb := ui.NewRadioButtons() + rb.Append("Radio Button 1") + rb.Append("Radio Button 2") + rb.Append("Radio Button 3") + vbox.Append(rb, false) + + return hbox +} diff --git a/window-demo.go b/window-demo.go index 82162dd..8d205b5 100644 --- a/window-demo.go +++ b/window-demo.go @@ -5,14 +5,14 @@ import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" func (n *Node) AddDemoTab(title string) { - newNode := n.AddTab(title, makeWindowTemplate()) + newNode := n.AddTab(title, makeDemoTab()) if (Config.DebugNode) { newNode.Dump() } tabSetMargined(newNode.uiTab) } -func makeWindowTemplate() ui.Control { +func makeDemoTab() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) From 76b371b375fcd98f7d3f20363c17f62ebad1c985 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 06:42:33 -0500 Subject: [PATCH 055/113] EXIT: more accurate window close & exit code Signed-off-by: Jeff Carr --- gui-example/main.go | 40 +++++++++++++++++++++++++++------------- structs.go | 4 +++- window.go | 43 ++++++++++++++++++++++++++++++++----------- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/gui-example/main.go b/gui-example/main.go index c9e8cbd..d391ed4 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -8,26 +8,25 @@ import ( "git.wit.org/wit/gui" ) -func customExit(gw *gui.GuiWindow) { - log.Println("Should Exit Here") - os.Exit(0) -} - func main() { - log.Println("starting my Control Panel") - - gui.Config.Width = 800 - gui.Config.Height = 300 - gui.Config.Exit = customExit + log.Println("Starting my Control Panel") + // This initializes the first window go gui.Main(initGUI) + // This starts a goroutine to demonstrate how to + // inject things into the GUI watchGUI() } func initGUI() { - n := gui.NewWindow("WIT GUI Example Window", 640, 480) - n.AddDemoTab("A Simple Tab Demo") + gui.Config.Title = "WIT GUI Window Demo" + gui.Config.Width = 640 + gui.Config.Height = 480 + gui.Config.Exit = myExit + + node := gui.NewWindow() + node.AddDemoTab("A Simple Tab Demo") } // This demonstrates how to properly interact with the GUI @@ -36,12 +35,27 @@ func initGUI() { func watchGUI() { var i = 1 for { - log.Println("Waiting for customExit()", i) + log.Println("Waiting", i, "seconds") i += 1 time.Sleep(1 * time.Second) if i == 4 { log.Println("Opening a Debug Window via the gui.Queue()") + gui.Config.Width = 800 + gui.Config.Height = 300 + gui.Config.Exit = myDebugExit gui.Queue(gui.DebugWindow) } } } + +func myExit(n *gui.Node) { + log.Println() + log.Println("Entered myExit() on node.Name =", n.Name) + log.Println() + os.Exit(0) +} + +func myDebugExit(n *gui.Node) { + log.Println("Entered myDebugExit() on node.Name =", n.Name) + log.Println("Don't actually os.Exit()") +} diff --git a/structs.go b/structs.go index 80c763d..cf84746 100644 --- a/structs.go +++ b/structs.go @@ -20,13 +20,15 @@ var Data GuiData var Config GuiConfig type GuiConfig struct { + Title string Width int Height int + Exit func(*Node) + Debug bool DebugNode bool DebugTabs bool DebugTable bool - Exit func(*GuiWindow) depth int counter int // used to make unique ID's diff --git a/window.go b/window.go index 4940e35..5a1e8d1 100644 --- a/window.go +++ b/window.go @@ -80,15 +80,17 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { w := node.uiWindow newGuiWindow.UiWindow = w - // newGuiWindow.UiWindow.SetTitle("test") + f := Config.Exit w.OnClosing(func(*ui.Window) bool { - log.Println("gui.InitWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) + if (Config.Debug) { + log.Println("gui.InitWindow() OnClosing()") + } // newGuiWindow.UiWindow.Destroy() - if Config.Exit == nil { + if f == nil { ui.Quit() } else { - // allow a custom exit function - Config.Exit(newGuiWindow) + // use a custom exit function + f(node) } return true }) @@ -299,8 +301,14 @@ func (parent *Node) makeNode(title string, x int, y int) *Node { func (n *Node) uiNewWindow(title string, x int, y int) { w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) + f := Config.Exit w.OnClosing(func(*ui.Window) bool { - log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title) + if (Config.Debug) { + log.Println("ui.Window().OnClosing()") + } + if (f != nil) { + f(n) + } return true }) w.SetMargined(true) @@ -390,18 +398,31 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod return node } -func NewWindow(title string, x int, y int) *Node { +// This routine creates a blank window with a Title and size (W x H) +// +// This routine can not have any arguements due to the nature of how +// it can be passed via the 'andlabs/ui' queue which, because it is +// cross platform, must pass UI changes into the OS threads (that is +// my guess). +func NewWindow() *Node { + title := Config.Title + w := Config.Width + h := Config.Height + var node *Node - node = mapWindow(nil, nil, title, x, y) + node = mapWindow(nil, nil, title, w, h) box := node.box log.Println("gui.NewWindow() title = box.Name =", box.Name) - node.uiNewWindow(box.Name, x, y) + node.uiNewWindow(box.Name, w, h) window := node.uiWindow + f := Config.Exit ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", box.Name) - window.Destroy() + log.Println("createWindow().Destroy() on node.Name =", node.Name) + if (f != nil) { + f(node) + } return true }) From 3fa94aeb014759b7b48454159c482f8c092ac2e2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 06:46:49 -0500 Subject: [PATCH 056/113] REORG: move find() functions into find.go Signed-off-by: Jeff Carr --- debug.go | 59 ------------------------------------- find.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ new-structs.go | 38 ------------------------ 3 files changed, 80 insertions(+), 97 deletions(-) diff --git a/debug.go b/debug.go index e548b98..0b0baa4 100644 --- a/debug.go +++ b/debug.go @@ -2,7 +2,6 @@ package gui import ( "fmt" - "os" "log" "time" @@ -145,29 +144,6 @@ func DebugDataNodeChildren() { } */ -func FindNode(name string) *Node { - if Data.NodeMap == nil { - log.Println("gui.FindNode() gui.Data.NodeMap == nil") - return nil - } - log.Println("gui.FindNode() searching Data.NodeMap:") - for id, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.Width, node.Height, id) - node.Dump() - if (name == node.Name) { - return node - } - newNode := findByName(node, name) - if (newNode != nil) { - return newNode - } - log.Println("gui.FindNode() could not find node name =", name) - os.Exit(-1) - } - log.Println("gui.FindNode() could not find node name =", name) - return nil -} - func (dn *GuiData) ListChildren(dump bool) { if Data.NodeMap == nil { log.Println("gui.Data.ListChildren() Data.NodeMap == nil") @@ -182,38 +158,3 @@ func (dn *GuiData) ListChildren(dump bool) { node.ListChildren(dump) } } - -func (dn *GuiData) findId(id string) *Node { - if Data.NodeMap == nil { - log.Println("gui.Data.findId() map == nil") - return nil - } - // log.Println("Dumping Data.NodeMap:") - for name, node := range Data.NodeMap { - // log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) - if (id == node.id) { - log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name) - return node - } - // TODO: fix // Oct 9 - // node.findId(id) - } - return nil -} - -/* -func DebugNodeChildren() { - if Data.NodeMap == nil { - log.Println("Data.NodeMap == nil") - return - } - log.Println("Dumping Data.NodeMap:") - for name, node := range Data.NodeMap { - log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) - // node.Dump() - node.ListChildren() - // node.SetName("yahoo") - // log.Println("\tData.NodeMap node =", node) - } -} -*/ diff --git a/find.go b/find.go index baf1a45..441f496 100644 --- a/find.go +++ b/find.go @@ -2,6 +2,7 @@ package gui import ( "log" + "os" // "github.com/andlabs/ui" // _ "github.com/andlabs/ui/winmanifest" @@ -33,3 +34,82 @@ func FindBox(s string) *GuiBox { log.Println("gui.FindBox() COULD NOT FIND BOX", s) return nil } + +func FindNode(name string) *Node { + if Data.NodeMap == nil { + log.Println("gui.FindNode() gui.Data.NodeMap == nil") + return nil + } + log.Println("gui.FindNode() searching Data.NodeMap:") + for id, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.Width, node.Height, id) + node.Dump() + if (name == node.Name) { + return node + } + newNode := findByName(node, name) + if (newNode != nil) { + return newNode + } + log.Println("gui.FindNode() could not find node name =", name) + os.Exit(-1) + } + log.Println("gui.FindNode() could not find node name =", name) + return nil +} + +func (dn *GuiData) findId(id string) *Node { + if Data.NodeMap == nil { + log.Println("gui.Data.findId() map == nil") + return nil + } + // log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + // log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + if (id == node.id) { + log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name) + return node + } + // TODO: fix // Oct 9 + // node.findId(id) + } + return nil +} + +func findByIdDFS(node *Node, id string) *Node { + log.Println("findByIdDFS()", id, node) + node.Dump() + if node.id == id { + log.Println("Found node id =", id, node) + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + newNode := findByIdDFS(child, id) + if (newNode != nil) { + return newNode + } + } + } + return nil +} + +func findByName(node *Node, name string) *Node { + log.Println("findByName()", name, node) + node.Dump() + if node.Name == name { + log.Println("findByName() Found node name =", name, node) + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + newNode := findByName(child, name) + if (newNode != nil) { + return newNode + } + } + } + return nil +} diff --git a/new-structs.go b/new-structs.go index d1ed875..7cd6d90 100644 --- a/new-structs.go +++ b/new-structs.go @@ -177,44 +177,6 @@ func (n *Node) ListChildren(dump bool) { return } -func findByIdDFS(node *Node, id string) *Node { - log.Println("findByIdDFS()", id, node) - node.Dump() - if node.id == id { - log.Println("Found node id =", id, node) - return node - } - - if len(node.children) > 0 { - for _, child := range node.children { - newNode := findByIdDFS(child, id) - if (newNode != nil) { - return newNode - } - } - } - return nil -} - -func findByName(node *Node, name string) *Node { - log.Println("findByName()", name, node) - node.Dump() - if node.Name == name { - log.Println("findByName() Found node name =", name, node) - return node - } - - if len(node.children) > 0 { - for _, child := range node.children { - newNode := findByName(child, name) - if (newNode != nil) { - return newNode - } - } - } - return nil -} - // The parent Node needs to be the raw Window // The 'stuff' Node needs to be the contents of the tab // From af1daa80a0e2948ae185eb4c9ea6a30dad6fe5b4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 06:50:27 -0500 Subject: [PATCH 057/113] REORG: move more find() functions into find.go Signed-off-by: Jeff Carr --- find.go | 38 ++++++++++++++++++++++++++++++++++++-- new-structs.go | 19 ------------------- structs.go | 17 ----------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/find.go b/find.go index 441f496..037ce0d 100644 --- a/find.go +++ b/find.go @@ -4,11 +4,45 @@ import ( "log" "os" -// "github.com/andlabs/ui" -// _ "github.com/andlabs/ui/winmanifest" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" // "github.com/davecgh/go-spew/spew" ) +func (n *Node) FindTab() *ui.Tab { + return n.uiTab +} + +func (n *Node) FindControl() *ui.Control { + return n.uiControl +} + +func (n *Node) FindBox() *GuiBox { + return n.box +} + +func (n *Node) FindWindowBox() *GuiBox { + if (n.box == nil) { + panic("SERIOUS ERROR n.box == nil in FindWindowBox()") + } + return n.box +} + +func (w *GuiWindow) FindNode() *Node { + return w.node +} + +func (b *GuiBox) FindNode() *Node { + log.Println("gui.FindNode() on GuiBox") + if b.node != nil { + return b.node + } + Data.ListChildren(true) + b.Dump() + log.Println("gui.FindNode() on GuiBox is nil") + os.Exit(-1) + return nil +} func FindWindow(s string) *GuiWindow { for name, window := range Data.WindowMap { diff --git a/new-structs.go b/new-structs.go index 7cd6d90..d50de32 100644 --- a/new-structs.go +++ b/new-structs.go @@ -106,25 +106,6 @@ func (n *Node) SetName(name string) { return } -func (n *Node) FindTab() *ui.Tab { - return n.uiTab -} - -func (n *Node) FindControl() *ui.Control { - return n.uiControl -} - -func (n *Node) FindBox() *GuiBox { - return n.box -} - -func (n *Node) FindWindowBox() *GuiBox { - if (n.box == nil) { - panic("SERIOUS ERROR n.box == nil in FindWindowBox()") - } - return n.box -} - func (n *Node) Append(child *Node) { // if (n.UiBox == nil) { // return diff --git a/structs.go b/structs.go index cf84746..8a401ca 100644 --- a/structs.go +++ b/structs.go @@ -3,7 +3,6 @@ package gui import ( "image/color" "log" - "os" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -169,22 +168,6 @@ func (b *GuiBox) SetNode(n *Node) { } } -func (w *GuiWindow) FindNode() *Node { - return w.node -} - -func (b *GuiBox) FindNode() *Node { - log.Println("gui.FindNode() on GuiBox") - if b.node != nil { - return b.node - } - Data.ListChildren(true) - b.Dump() - log.Println("gui.FindNode() on GuiBox is nil") - os.Exit(-1) - return nil -} - func (s GuiBox) Append(child ui.Control, x bool) { if s.UiBox == nil { return From a678fcd2adb0df84539cf8f0dcfd8a150a732000 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 06:59:04 -0500 Subject: [PATCH 058/113] MISC: minor cleanup Signed-off-by: Jeff Carr --- gui-example/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gui-example/main.go b/gui-example/main.go index d391ed4..722253a 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -8,17 +8,19 @@ import ( "git.wit.org/wit/gui" ) +// This initializes the first window +// +// Then starts a goroutine to demonstrate how to +// inject things into the GUI func main() { log.Println("Starting my Control Panel") - // This initializes the first window go gui.Main(initGUI) - // This starts a goroutine to demonstrate how to - // inject things into the GUI watchGUI() } +// This initializes the first window func initGUI() { gui.Config.Title = "WIT GUI Window Demo" gui.Config.Width = 640 @@ -31,7 +33,6 @@ func initGUI() { // This demonstrates how to properly interact with the GUI // You can not involke the GUI from external goroutines in most cases. - func watchGUI() { var i = 1 for { From c74e39a9efc1bfb1b895bda54da6c7afbf3371fb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 07:18:17 -0500 Subject: [PATCH 059/113] NODE: TODO: refactor InitWindow to use NewWindow() Signed-off-by: Jeff Carr --- main.go | 4 ---- structs.go | 9 +++++---- window.go | 18 +++++++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 9c8092f..1eada56 100644 --- a/main.go +++ b/main.go @@ -8,10 +8,6 @@ import ( ) func Main(f func()) { - log.Println("Starting gui.Main() (using gtk via andlabs/ui)") - log.Println("Starting gui.Main() (using gtk via andlabs/ui)") - log.Println("Starting gui.Main() (using gtk via andlabs/ui)") - log.Println("Starting gui.Main() (using gtk via andlabs/ui)") log.Println("Starting gui.Main() (using gtk via andlabs/ui)") ui.Main(f) } diff --git a/structs.go b/structs.go index 8a401ca..23a5ca8 100644 --- a/structs.go +++ b/structs.go @@ -24,10 +24,11 @@ type GuiConfig struct { Height int Exit func(*Node) - Debug bool - DebugNode bool - DebugTabs bool - DebugTable bool + Debug bool + DebugNode bool + DebugTabs bool + DebugTable bool + DebugWindow bool depth int counter int // used to make unique ID's diff --git a/window.go b/window.go index 5a1e8d1..1dadad7 100644 --- a/window.go +++ b/window.go @@ -135,7 +135,9 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } } if (box.node == nil) { - Data.ListChildren(true) + if (Config.Debug) { + Data.ListChildren(true) + } log.Println("InitWindow() box has a FUCKING nil node") fn := FindNode("full initTab") log.Println("InitWindow() fn =", fn) @@ -143,7 +145,9 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } if (newGuiWindow.node == nil) { - Data.ListChildren(true) + if (Config.Debug) { + Data.ListChildren(true) + } log.Println("InitWindow() newGuiWindow has a FUCKING nil node") // panic(-1) } @@ -153,8 +157,10 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { box.Dump() panic(-1) } - box.Dump() - box.node.Dump() + if (Config.DebugWindow) { + box.Dump() + box.node.Dump() + } if (box.node != node) { log.Println("InitWindow() box.node != node. Hmmm....") log.Println("InitWindow() box.node != node. Hmmm....") @@ -168,8 +174,7 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { panic(-1) } if (node.uiTab == nil) { - // DebugNodeChildren() - // panic("node.uiTab = nil") + panic("node.uiTab = nil") } return node } @@ -372,7 +377,6 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod return nil } - log.Println("gui.WindowMap START title =", title) var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y From 23e471d9c1383acee57c4cf4b2ab48ca64d92595 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 07:51:17 -0500 Subject: [PATCH 060/113] NODE: finally remove initBlankWindow() Signed-off-by: Jeff Carr --- gui-example/main.go | 1 + new-structs.go | 13 ++++++++++--- window.go | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gui-example/main.go b/gui-example/main.go index 722253a..e1caa6e 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -29,6 +29,7 @@ func initGUI() { node := gui.NewWindow() node.AddDemoTab("A Simple Tab Demo") + node.AddAndlabsUiDemoTab("A Simple andlabs/ui Tab Demo") } // This demonstrates how to properly interact with the GUI diff --git a/new-structs.go b/new-structs.go index d50de32..e86bb53 100644 --- a/new-structs.go +++ b/new-structs.go @@ -172,15 +172,19 @@ func (parent *Node) AddTabNode(title string, b *GuiBox) *Node { var newNode *Node // var newControl ui.Control + /* if (parent.box == nil) { // TODO: fix this to use a blank box - uiC := parent.initBlankWindow() - newNode.uiControl = &uiC + // uiC := parent.initBlankWindow() + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + newNode.uiBox = hbox panic("node.AddTabNode() can not add a tab if the box == nil") } if (parent.uiTab == nil) { panic("node.AddTabNode() can not add a tab if parent.uiTab == nil") } + */ newNode = parent.makeNode(title, 444, 400 + Config.counter) newNode.uiTab = parent.uiTab @@ -206,6 +210,7 @@ func (parent *Node) AddTabNode(title string, b *GuiBox) *Node { } func (parent *Node) AddTab(title string, uiC ui.Control) *Node { + log.Println("gui.Node.AddTab() START name =", title) if parent.uiWindow == nil { parent.Dump() panic("gui.AddTab() ERROR ui.Window == nil") @@ -228,7 +233,9 @@ func (parent *Node) AddTab(title string, uiC ui.Control) *Node { parent.uiWindow.SetMargined(true) if (uiC == nil) { - uiC = parent.initBlankWindow() + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + uiC = hbox } tab.Append(title, uiC) tab.SetMargined(0, true) diff --git a/window.go b/window.go index 1dadad7..73ccad3 100644 --- a/window.go +++ b/window.go @@ -341,12 +341,14 @@ func CreateBlankWindow(title string, x int, y int) *Node { return node } +/* func (n *Node) initBlankWindow() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) return hbox } +*/ func makeBlankNode(title string) *Node { log.Println("gui.makeBlankNode() title =", title) From 26fba883a7fd8d937d1c49e9269f4537c1f01f61 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 08:07:46 -0500 Subject: [PATCH 061/113] NODE: climbing up the rabbit hole more Signed-off-by: Jeff Carr --- main.go | 7 +++++-- table.go | 4 +++- window-debug.go | 7 ++++++- window.go | 13 ++++++++++--- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 1eada56..b8bc288 100644 --- a/main.go +++ b/main.go @@ -26,13 +26,16 @@ func Queue(f func()) { func ExampleWindow() { log.Println("START gui.ExampleWindow()") - title := "Test Window" + Config.Title = "ExampleWindow" + /* node := InitWindow(nil, nil, title, 0) box := node.box window := box.Window log.Println("box =", box) log.Println("window =", window) + */ + node := NewWindow() node.AddDebugTab("jcarr Debug") - window.UiWindow.Show() + // window.UiWindow.Show() } diff --git a/table.go b/table.go index a6bb84e..ff31a68 100644 --- a/table.go +++ b/table.go @@ -98,7 +98,9 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { - node := InitWindow(nil, gw, name, Yaxis) + // node := InitWindow(nil, gw, name, Yaxis) + node := NewWindow() + // node.AddDebugTab("jcarr Debug") return AddTableBox(node.box, name, rowcount, parts) } diff --git a/window-debug.go b/window-debug.go index 69eb7bb..9e5dc1b 100644 --- a/window-debug.go +++ b/window-debug.go @@ -14,15 +14,20 @@ var nodeNames = make([]string, 100) func DebugWindow() { log.Println("START gui.DebugWindow()") + /* title := "WIT GUI Debug Window" node := InitWindow(nil, nil, title, 0) box := node.box window := box.Window log.Println("box =", box) log.Println("window =", window) + */ + + Config.Title = "replace InitWindow()" + node := NewWindow() node.AddDebugTab("WIT GUI Debug Tab") - window.UiWindow.Show() + // window.UiWindow.Show() } // TODO: remove this crap diff --git a/window.go b/window.go index 73ccad3..c2bf34b 100644 --- a/window.go +++ b/window.go @@ -4,7 +4,7 @@ import ( "log" "fmt" "strconv" - "time" +// "time" "github.com/andlabs/ui" @@ -13,21 +13,25 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) +/* func initUI(name string, callback func(*GuiBox) *GuiBox) { ui.Main(func() { log.Println("gui.initUI() inside ui.Main()") - node := InitWindow(nil, nil, "StartNewWindow"+name, 0) + node := NewWindow() + + // node := InitWindow(nil, nil, "StartNewWindow"+name, 0) box := node.box box = callback(box) window := box.Window - node.window = window log.Println("StartNewWindow() box =", box) window.UiWindow.Show() }) } +*/ +/* func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { log.Println("StartNewWindow() ui.Main() Create a new window") @@ -38,6 +42,7 @@ func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiB initUI(name, callback) } } +*/ func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBox(gw.UiWindow, msg1, msg2) @@ -52,6 +57,7 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { // This is this way because on Linux you can have more than one // actual window but that does not appear to work on the MacOS or Windows // +/* func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { log.Println("gui.InitWindow() START") @@ -178,6 +184,7 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { } return node } +*/ func DeleteWindow(name string) { log.Println("gui.DeleteWindow() START name =", name) From 2133a00c6b13994434b52221851dac20537664c7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 08:12:31 -0500 Subject: [PATCH 062/113] NODE: remove lots of deprecated code Signed-off-by: Jeff Carr --- main.go | 9 --- table.go | 3 - window-debug.go | 20 ------ window.go | 169 ------------------------------------------------ 4 files changed, 201 deletions(-) diff --git a/main.go b/main.go index b8bc288..2da4053 100644 --- a/main.go +++ b/main.go @@ -27,15 +27,6 @@ func ExampleWindow() { log.Println("START gui.ExampleWindow()") Config.Title = "ExampleWindow" - /* - node := InitWindow(nil, nil, title, 0) - box := node.box - window := box.Window - log.Println("box =", box) - log.Println("window =", window) - */ node := NewWindow() node.AddDebugTab("jcarr Debug") - - // window.UiWindow.Show() } diff --git a/table.go b/table.go index ff31a68..3ed8c6a 100644 --- a/table.go +++ b/table.go @@ -98,10 +98,7 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { - // node := InitWindow(nil, gw, name, Yaxis) node := NewWindow() - // node.AddDebugTab("jcarr Debug") - return AddTableBox(node.box, name, rowcount, parts) } diff --git a/window-debug.go b/window-debug.go index 9e5dc1b..a70bb1f 100644 --- a/window-debug.go +++ b/window-debug.go @@ -12,22 +12,9 @@ var names = make([]string, 100) var nodeNames = make([]string, 100) func DebugWindow() { - log.Println("START gui.DebugWindow()") - - /* - title := "WIT GUI Debug Window" - node := InitWindow(nil, nil, title, 0) - box := node.box - window := box.Window - log.Println("box =", box) - log.Println("window =", window) - */ - Config.Title = "replace InitWindow()" node := NewWindow() node.AddDebugTab("WIT GUI Debug Tab") - - // window.UiWindow.Show() } // TODO: remove this crap @@ -191,13 +178,6 @@ func makeWindowDebug() ui.Control { Data.DumpNodeMap() }) -/* - n1 = addButton(vbox, "DebugDataNodeChildren()") - n1.OnClicked(func(*ui.Button) { - DebugDataNodeChildren() - }) -*/ - n1 = addButton(vbox, "Data.ListChildren(false)") n1.OnClicked(func(*ui.Button) { Data.ListChildren(false) diff --git a/window.go b/window.go index c2bf34b..69a1613 100644 --- a/window.go +++ b/window.go @@ -4,46 +4,11 @@ import ( "log" "fmt" "strconv" -// "time" "github.com/andlabs/ui" - - // import "regexp" - _ "github.com/andlabs/ui/winmanifest" ) -/* -func initUI(name string, callback func(*GuiBox) *GuiBox) { - ui.Main(func() { - log.Println("gui.initUI() inside ui.Main()") - - node := NewWindow() - - // node := InitWindow(nil, nil, "StartNewWindow"+name, 0) - box := node.box - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) - - window.UiWindow.Show() - }) -} -*/ - -/* -func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { - log.Println("StartNewWindow() ui.Main() Create a new window") - - if bg { - go initUI(name, callback) - time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? - } else { - initUI(name, callback) - } -} -*/ - func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBox(gw.UiWindow, msg1, msg2) } @@ -52,140 +17,6 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBoxError(gw.UiWindow, msg1, msg2) } -// -// This creates a new 'window' (which is just a tab in the window) -// This is this way because on Linux you can have more than one -// actual window but that does not appear to work on the MacOS or Windows -// -/* -func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node { - log.Println("gui.InitWindow() START") - - var box *GuiBox - var node *Node - - if gw == nil { - node = mapWindow(parent, nil, name, Config.Width, Config.Height) - box = node.box - } else { - node = mapWindow(parent, gw.UiWindow, name, Config.Width, Config.Height) - box = node.box - } - - // box.Window = &newGuiWindow - newGuiWindow := box.Window - - // This is the first window. One must create it here - if gw == nil { - log.Println("gui.initWindow() ADDING ui.NewWindow()") - node.uiNewWindow(name, Config.Width, Config.Height) - box.node = node - if (node.box == nil) { - node.box = box - } - w := node.uiWindow - newGuiWindow.UiWindow = w - - f := Config.Exit - w.OnClosing(func(*ui.Window) bool { - if (Config.Debug) { - log.Println("gui.InitWindow() OnClosing()") - } - // newGuiWindow.UiWindow.Destroy() - if f == nil { - ui.Quit() - } else { - // use a custom exit function - f(node) - } - return true - }) - - newGuiWindow.UiTab = ui.NewTab() - newGuiWindow.UiWindow.SetChild(newGuiWindow.UiTab) - newGuiWindow.UiWindow.SetMargined(true) - tmp := 0 - newGuiWindow.TabNumber = &tmp - node.uiTab = newGuiWindow.UiTab - } else { - newGuiWindow.UiWindow = gw.UiWindow - newGuiWindow.UiTab = gw.UiTab - node.uiTab = newGuiWindow.UiTab - } - - newGuiWindow.BoxMap = make(map[string]*GuiBox) - newGuiWindow.EntryMap = make(map[string]*GuiEntry) - // Data.Windows = append(Data.Windows, &newGuiWindow) - - if newGuiWindow.UiTab == nil { - tabnum := 0 - newGuiWindow.TabNumber = &tabnum - } else { - tabnum := newGuiWindow.UiTab.NumPages() - newGuiWindow.TabNumber = &tabnum - if (node.uiTab == nil) { - node.uiTab = newGuiWindow.UiTab - } - } - - Data.WindowMap[newGuiWindow.Name] = newGuiWindow - - if (box.node == nil) { - fn := FindNode("full initTab") - log.Println("InitWindow() fn =", fn) - log.Println("InitWindow() mapping node <=> box") - box.node = fn - if (fn.box == nil) { - log.Println("InitWindow() mapping node <=> box") - fn.box = box - } - } - if (box.node == nil) { - if (Config.Debug) { - Data.ListChildren(true) - } - log.Println("InitWindow() box has a FUCKING nil node") - fn := FindNode("full initTab") - log.Println("InitWindow() fn =", fn) - panic(-1) - } - - if (newGuiWindow.node == nil) { - if (Config.Debug) { - Data.ListChildren(true) - } - log.Println("InitWindow() newGuiWindow has a FUCKING nil node") - // panic(-1) - } - - log.Println("InitWindow() END *GuiWindow =", newGuiWindow) - if (box.node == nil) { - box.Dump() - panic(-1) - } - if (Config.DebugWindow) { - box.Dump() - box.node.Dump() - } - if (box.node != node) { - log.Println("InitWindow() box.node != node. Hmmm....") - log.Println("InitWindow() box.node != node. Hmmm....") - log.Println("InitWindow() box.node != node. Hmmm....") - panic(-1) - } - if (node.box != box) { - log.Println("InitWindow() node.box != box. Hmmm....") - log.Println("InitWindow() node.box != box. Hmmm....") - log.Println("InitWindow() node.box != box. Hmmm....") - panic(-1) - } - if (node.uiTab == nil) { - panic("node.uiTab = nil") - } - return node -} -*/ - func DeleteWindow(name string) { log.Println("gui.DeleteWindow() START name =", name) window := Data.WindowMap[name] From 2ec7fc29b0248fc030473de61d06fcba8e5673dd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 09:07:23 -0500 Subject: [PATCH 063/113] NODE: more rabbits Signed-off-by: Jeff Carr --- main.go | 4 +++- window-debug.go | 8 ++++++-- window.go | 12 ++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 2da4053..70e0e65 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ func Main(f func()) { ui.Main(f) } -// Other goroutines must use this +// Other goroutines must use this to access the GUI // // You can not acess / process the GUI thread directly from // other goroutines. This is due to the nature of how @@ -23,6 +23,7 @@ func Queue(f func()) { ui.QueueMain(f) } +/* func ExampleWindow() { log.Println("START gui.ExampleWindow()") @@ -30,3 +31,4 @@ func ExampleWindow() { node := NewWindow() node.AddDebugTab("jcarr Debug") } +*/ diff --git a/window-debug.go b/window-debug.go index a70bb1f..afe3918 100644 --- a/window-debug.go +++ b/window-debug.go @@ -35,7 +35,9 @@ func makeWindowDebug() ui.Control { cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { - log.Println("range Data.WindowMap() name =", name) + if (Config.Debug) { + log.Println("range Data.WindowMap() name =", name) + } addName(cbox, name) } cbox.SetSelected(0) @@ -153,7 +155,9 @@ func makeWindowDebug() ui.Control { nodeCombo := ui.NewCombobox() for name, node := range Data.NodeMap { - log.Println("range Data.NodeMap() name =", name) + if (Config.Debug) { + log.Println("range Data.NodeMap() name =", name) + } addNodeName(nodeCombo, node.id) } nodeCombo.SetSelected(0) diff --git a/window.go b/window.go index 69a1613..fb142ac 100644 --- a/window.go +++ b/window.go @@ -52,6 +52,7 @@ func DeleteWindow(name string) { } } +/* func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *Node { n := CreateBlankWindow(title, x, y) if (n.box == nil) { @@ -64,7 +65,9 @@ func CreateWindow(title string, tabname string, x int, y int, custom func() ui.C // TODO: run custom() here // Oct 9 return n } +*/ +/* func (n *Node) Add(e Element) *Node { newNode := n.addNode("testingAdd") if(e == Tab) { @@ -72,12 +75,14 @@ func (n *Node) Add(e Element) *Node { } return newNode } +*/ // // Create a new node // if parent == nil, that means it is a new window and needs to be put // in the window map (aka Data.NodeMap) // +/* func (parent *Node) addNode(title string) *Node { var node Node node.Name = title @@ -92,6 +97,7 @@ func (parent *Node) addNode(title string) *Node { parent.Append(&node) return &node } +*/ func makeNode(parent *Node, title string, x int, y int) *Node { var node Node @@ -106,9 +112,9 @@ func makeNode(parent *Node, title string, x int, y int) *Node { // panic("gui.makeNode() START") if (parent == nil) { if (Data.NodeMap[title] != nil) { - log.Println("Duplicate uiNewWindow() name =", title) + log.Println("Duplicate window name =", title) // TODO: just change the 'title' to something unique - panic(fmt.Sprintf("Duplicate uiNewWindow() name = %s\n", title)) + panic(fmt.Sprintf("Duplicate window name = %s\n", title)) return nil } // panic("gui.makeNode() before NodeMap()") @@ -161,6 +167,7 @@ func (n *Node) uiNewWindow(title string, x int, y int) { return } +/* func CreateBlankWindow(title string, x int, y int) *Node { node := mapWindow(nil, nil, title, x, y) box := node.box @@ -178,6 +185,7 @@ func CreateBlankWindow(title string, x int, y int) *Node { box.Window.UiWindow = window return node } +*/ /* func (n *Node) initBlankWindow() ui.Control { From a926aa300e90786ccd101124d31d6662e4788070 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 09:34:31 -0500 Subject: [PATCH 064/113] NODE: minimal debug tab Signed-off-by: Jeff Carr --- new-structs.go | 4 +- window-debug.go | 2 +- window-demo-andlabs-ui.go | 2 +- window-demo.go | 82 ++++++++++++++++++--------------------- 4 files changed, 42 insertions(+), 48 deletions(-) diff --git a/new-structs.go b/new-structs.go index e86bb53..92933ed 100644 --- a/new-structs.go +++ b/new-structs.go @@ -209,7 +209,8 @@ func (parent *Node) AddTabNode(title string, b *GuiBox) *Node { return newNode } -func (parent *Node) AddTab(title string, uiC ui.Control) *Node { +// func (parent *Node) AddTab(title string, uiC ui.Control) *Node { +func (parent *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() START name =", title) if parent.uiWindow == nil { parent.Dump() @@ -243,6 +244,7 @@ func (parent *Node) AddTab(title string, uiC ui.Control) *Node { // panic("gui.AddTab() before makeNode()") newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab + newNode.uiBox = uiC // panic("gui.AddTab() after makeNode()") return newNode } diff --git a/window-debug.go b/window-debug.go index afe3918..4b8abb5 100644 --- a/window-debug.go +++ b/window-debug.go @@ -26,7 +26,7 @@ func addNodeName(c *ui.Combobox, s string) { y = y + 1 } -func makeWindowDebug() ui.Control { +func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) diff --git a/window-demo-andlabs-ui.go b/window-demo-andlabs-ui.go index f7f5606..2c1f6cb 100644 --- a/window-demo-andlabs-ui.go +++ b/window-demo-andlabs-ui.go @@ -16,7 +16,7 @@ func (n *Node) AddAndlabsUiDemoTab(title string) { tabSetMargined(newNode.uiTab) } -func makeAndlabsUiTab() ui.Control { +func makeAndlabsUiTab() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) diff --git a/window-demo.go b/window-demo.go index 8d205b5..7f964ef 100644 --- a/window-demo.go +++ b/window-demo.go @@ -4,19 +4,24 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" +var mybox *ui.Box + func (n *Node) AddDemoTab(title string) { newNode := n.AddTab(title, makeDemoTab()) if (Config.DebugNode) { newNode.Dump() } tabSetMargined(newNode.uiTab) + newNode.Dump() + newNode.ListChildren(false) + addDemoGroup(newNode.uiBox) } -func makeDemoTab() ui.Control { +func makeDemoTab() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) - group := ui.NewGroup("Numbers") + group := ui.NewGroup("DemoEditBox") group.SetMargined(true) hbox.Append(group, true) @@ -24,45 +29,10 @@ func makeDemoTab() ui.Control { vbox.SetPadded(true) group.SetChild(vbox) - spinbox := ui.NewSpinbox(47, 100) - slider := ui.NewSlider(21, 100) - pbar := ui.NewProgressBar() - - spinbox.OnChanged(func(*ui.Spinbox) { - slider.SetValue(spinbox.Value()) - pbar.SetValue(spinbox.Value()) - }) - slider.OnChanged(func(*ui.Slider) { - spinbox.SetValue(slider.Value()) - pbar.SetValue(slider.Value()) - }) - vbox.Append(spinbox, false) - vbox.Append(slider, false) - vbox.Append(pbar, false) - - ip := ui.NewProgressBar() - ip.SetValue(-1) - vbox.Append(ip, false) - - group = ui.NewGroup("Lists") - group.SetMargined(true) - hbox.Append(group, true) - - vbox = ui.NewVerticalBox() - vbox.SetPadded(true) - group.SetChild(vbox) - - cbox := ui.NewCombobox() - cbox.Append("Combobox Item 1") - cbox.Append("Combobox Item 2") - cbox.Append("Combobox Item 3") - vbox.Append(cbox, false) - ecbox := ui.NewEditableCombobox() - ecbox.Append("Editable Item 1") - ecbox.Append("Editable Item 2") - ecbox.Append("Editable Item 3") - vbox.Append(ecbox, false) + ecbox.Append("foo 1") + ecbox.Append("man 2") + ecbox.Append("bar 3") ecbox.OnChanged(func(*ui.EditableCombobox) { log.Println("test") @@ -70,11 +40,33 @@ func makeDemoTab() ui.Control { log.Println("test=", test) }) - rb := ui.NewRadioButtons() - rb.Append("Radio Button 1") - rb.Append("Radio Button 2") - rb.Append("Radio Button 3") - vbox.Append(rb, false) + vbox.Append(ecbox, false) return hbox } + +func addDemoGroup(hbox *ui.Box) { + if (hbox == nil) { + return + } + group := ui.NewGroup("DemoEditBox 2") + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + ecbox := ui.NewEditableCombobox() + ecbox.Append("foo 1") + ecbox.Append("man 2") + ecbox.Append("bar 3") + + ecbox.OnChanged(func(*ui.EditableCombobox) { + log.Println("test") + test := ecbox.Text() + log.Println("test=", test) + }) + + vbox.Append(ecbox, false) +} From 25de1c5cdb22dcada57471ad413e8a5099a342cf Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 25 Oct 2021 09:52:21 -0500 Subject: [PATCH 065/113] NODE: make NewGroup() Signed-off-by: Jeff Carr --- window-debug.go | 4 +++- window-demo.go | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/window-debug.go b/window-debug.go index 4b8abb5..e87d0dc 100644 --- a/window-debug.go +++ b/window-debug.go @@ -2,6 +2,8 @@ package gui import ( "log" + // "fmt" + "strconv" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" @@ -243,7 +245,7 @@ func makeWindowDebug() *ui.Box { log.Println("nodeNames[y] =", nodeNames[y]) node := Data.findId(nodeNames[y]) if (node != nil) { - node.AddDemoTab("added this DemoTab") + node.AddDemoTab("ran gui.AddDemoTab() " + strconv.Itoa(Config.counter)) } }) diff --git a/window-demo.go b/window-demo.go index 7f964ef..92e89e8 100644 --- a/window-demo.go +++ b/window-demo.go @@ -14,7 +14,9 @@ func (n *Node) AddDemoTab(title string) { tabSetMargined(newNode.uiTab) newNode.Dump() newNode.ListChildren(false) - addDemoGroup(newNode.uiBox) + addDemoGroup(newNode, "new group 1") + addDemoGroup(newNode, "new group 2") + addDemoGroup(newNode, "new group 3") } func makeDemoTab() *ui.Box { @@ -45,11 +47,12 @@ func makeDemoTab() *ui.Box { return hbox } -func addDemoGroup(hbox *ui.Box) { +func addDemoGroup(n *Node, title string) { + hbox := n.uiBox if (hbox == nil) { return } - group := ui.NewGroup("DemoEditBox 2") + group := ui.NewGroup(title) group.SetMargined(true) hbox.Append(group, true) From 176cae3a8028f2c53a91b758e238b1dfe390d71a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 27 Oct 2021 11:18:22 -0500 Subject: [PATCH 066/113] REFACTOR: still trying to clean this up Signed-off-by: Jeff Carr --- gui-example/main.go | 2 +- window-debug.go | 11 +++++++++++ window-demo-andlabs-ui.go | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gui-example/main.go b/gui-example/main.go index e1caa6e..2b8cc39 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -29,7 +29,7 @@ func initGUI() { node := gui.NewWindow() node.AddDemoTab("A Simple Tab Demo") - node.AddAndlabsUiDemoTab("A Simple andlabs/ui Tab Demo") + node.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") } // This demonstrates how to properly interact with the GUI diff --git a/window-debug.go b/window-debug.go index e87d0dc..61a7158 100644 --- a/window-debug.go +++ b/window-debug.go @@ -249,6 +249,17 @@ func makeWindowDebug() *ui.Box { } }) + n1 = addButton(vbox, "Node.DemoAndlabsUiTab") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.AddDemoAndlabsUiTab("ran gui.AddDemoAndlabsUiTab() " + strconv.Itoa(Config.counter)) + } + }) + /* ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Numbers") diff --git a/window-demo-andlabs-ui.go b/window-demo-andlabs-ui.go index 2c1f6cb..806dc14 100644 --- a/window-demo-andlabs-ui.go +++ b/window-demo-andlabs-ui.go @@ -8,7 +8,7 @@ import _ "github.com/andlabs/ui/winmanifest" // calls to andlabs/ui. This can be used to bypass // the obvuscation added in this package if it is desired // or needed. -func (n *Node) AddAndlabsUiDemoTab(title string) { +func (n *Node) AddDemoAndlabsUiTab(title string) { newNode := n.AddTab(title, makeAndlabsUiTab()) if (Config.DebugNode) { newNode.Dump() From 2c470f86c96843c30de39a4bf42f8cf895d1f083 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 27 Oct 2021 16:31:54 -0500 Subject: [PATCH 067/113] REFACTOR: moving around things in the rabbit hole Signed-off-by: Jeff Carr --- window-debug.go => debug-window.go | 0 ...andlabs-ui.go => demo-window-andlabs-ui.go | 0 window-demo.go => demo-window.go | 54 ++++++++++++++++++- gui-example/main.go | 13 +++-- new-structs.go | 1 + window.go | 17 +++++- 6 files changed, 79 insertions(+), 6 deletions(-) rename window-debug.go => debug-window.go (100%) rename window-demo-andlabs-ui.go => demo-window-andlabs-ui.go (100%) rename window-demo.go => demo-window.go (58%) diff --git a/window-debug.go b/debug-window.go similarity index 100% rename from window-debug.go rename to debug-window.go diff --git a/window-demo-andlabs-ui.go b/demo-window-andlabs-ui.go similarity index 100% rename from window-demo-andlabs-ui.go rename to demo-window-andlabs-ui.go diff --git a/window-demo.go b/demo-window.go similarity index 58% rename from window-demo.go rename to demo-window.go index 92e89e8..2bde8b4 100644 --- a/window-demo.go +++ b/demo-window.go @@ -16,7 +16,9 @@ func (n *Node) AddDemoTab(title string) { newNode.ListChildren(false) addDemoGroup(newNode, "new group 1") addDemoGroup(newNode, "new group 2") - addDemoGroup(newNode, "new group 3") + + groupNode := newNode.AddGroup("new group 3") + groupNode.AddComboBox("testing", "foo", "man", "blah") } func makeDemoTab() *ui.Box { @@ -73,3 +75,53 @@ func addDemoGroup(n *Node, title string) { vbox.Append(ecbox, false) } + +func (n *Node) AddGroup(title string) *Node { + hbox := n.uiBox + if (hbox == nil) { + return n + } + group := ui.NewGroup(title) + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + newNode := n.AddNode(title) + newNode.uiBox = vbox + return newNode +} + +func (n *Node) GetText(title string) string { + if (n.uiText != nil) { + return n.uiText.Text() + } + return n.Name +} + +func (n *Node) AddComboBox(title string, s ...string) *Node { + box := n.uiBox + if (box == nil) { + return n + } + + ecbox := ui.NewEditableCombobox() + + for id, name := range s { + log.Println("Adding Combobox Entry:", id, name) + ecbox.Append(name) + } + + ecbox.OnChanged(func(*ui.EditableCombobox) { + test := ecbox.Text() + log.Println("text is now:", test) + }) + + box.Append(ecbox, false) + + newNode := n.AddNode(title) + newNode.uiText = ecbox + return newNode +} diff --git a/gui-example/main.go b/gui-example/main.go index 2b8cc39..9fcb971 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -22,14 +22,19 @@ func main() { // This initializes the first window func initGUI() { - gui.Config.Title = "WIT GUI Window Demo" + gui.Config.Title = "WIT GUI Window Demo 1" gui.Config.Width = 640 gui.Config.Height = 480 gui.Config.Exit = myExit + node1 := gui.NewWindow() + node1.AddDemoTab("A Simple Tab Demo") - node := gui.NewWindow() - node.AddDemoTab("A Simple Tab Demo") - node.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") + gui.Config.Title = "WIT GUI Window Demo 2" + gui.Config.Width = 640 + gui.Config.Height = 240 + gui.Config.Exit = myExit + node2 := gui.NewWindow() + node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") } // This demonstrates how to properly interact with the GUI diff --git a/new-structs.go b/new-structs.go index 92933ed..858d50f 100644 --- a/new-structs.go +++ b/new-structs.go @@ -55,6 +55,7 @@ type Node struct { uiWindow *ui.Window uiTab *ui.Tab uiBox *ui.Box + uiText *ui.EditableCombobox } func (n *Node) Parent() *Node { diff --git a/window.go b/window.go index fb142ac..56081d2 100644 --- a/window.go +++ b/window.go @@ -77,12 +77,12 @@ func (n *Node) Add(e Element) *Node { } */ +/* // // Create a new node // if parent == nil, that means it is a new window and needs to be put // in the window map (aka Data.NodeMap) // -/* func (parent *Node) addNode(title string) *Node { var node Node node.Name = title @@ -147,6 +147,21 @@ func (parent *Node) makeNode(title string, x int, y int) *Node { return &node } +func (parent *Node) AddNode(title string) *Node { + var node Node + node.Name = title + node.Width = parent.Width + node.Height = parent.Height + + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + parent.Append(&node) + node.parent = parent + return &node +} + func (n *Node) uiNewWindow(title string, x int, y int) { w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) From 6a477695ef9928ca8bc5ec784f44251955fa0286 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 04:10:48 -0500 Subject: [PATCH 068/113] NODE: almost out of the rabbit hole Signed-off-by: Jeff Carr --- .gitignore | 3 +- cmds/gui-demo/Makefile | 5 ++ cmds/gui-demo/demo-window.go | 17 ++++++ cmds/gui-demo/main.go | 68 ++++++++++++++++++++++ {gui-example => cmds/gui-example}/Makefile | 0 {gui-example => cmds/gui-example}/main.go | 0 debug-window.go | 2 + demo-window.go | 6 +- new-structs.go | 2 +- 9 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 cmds/gui-demo/Makefile create mode 100644 cmds/gui-demo/demo-window.go create mode 100644 cmds/gui-demo/main.go rename {gui-example => cmds/gui-example}/Makefile (100%) rename {gui-example => cmds/gui-example}/main.go (100%) diff --git a/.gitignore b/.gitignore index bb1e72d..1445c95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp -gui-example/gui-example +cmds/gui-example/gui-example +cmds/gui-demo/gui-demo diff --git a/cmds/gui-demo/Makefile b/cmds/gui-demo/Makefile new file mode 100644 index 0000000..2dbc808 --- /dev/null +++ b/cmds/gui-demo/Makefile @@ -0,0 +1,5 @@ +run: build + ./gui-demo + +build: + GO111MODULE="off" go build diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go new file mode 100644 index 0000000..f0cfcce --- /dev/null +++ b/cmds/gui-demo/demo-window.go @@ -0,0 +1,17 @@ +package main + +import "git.wit.org/wit/gui" + +func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + if (gui.Config.Debug) { + newNode.Dump() + } + newNode.ListChildren(false) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff") + + groupNode2 := newNode.AddGroup("group 2") + groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") +} diff --git a/cmds/gui-demo/main.go b/cmds/gui-demo/main.go new file mode 100644 index 0000000..372f2e2 --- /dev/null +++ b/cmds/gui-demo/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "log" + "os" + "time" + + "git.wit.org/wit/gui" +) + +// This initializes the first window +// +// Then starts a goroutine to demonstrate how to +// inject things into the GUI +func main() { + log.Println("Starting my Control Panel") + + go gui.Main(initGUI) + + watchGUI() +} + +// This initializes the first window +func initGUI() { + gui.Config.Title = "WIT GUI Window Demo 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + gui.Config.Exit = myExit + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + + gui.Config.Title = "WIT GUI Window Demo 2" + gui.Config.Width = 640 + gui.Config.Height = 240 + gui.Config.Exit = myExit + node2 := gui.NewWindow() + node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") +} + +// This demonstrates how to properly interact with the GUI +// You can not involke the GUI from external goroutines in most cases. +func watchGUI() { + var i = 1 + for { + log.Println("Waiting", i, "seconds") + i += 1 + time.Sleep(1 * time.Second) + if i == 4 { + log.Println("Opening a Debug Window via the gui.Queue()") + gui.Config.Width = 800 + gui.Config.Height = 300 + gui.Config.Exit = myDebugExit + gui.Queue(gui.DebugWindow) + } + } +} + +func myExit(n *gui.Node) { + log.Println() + log.Println("Entered myExit() on node.Name =", n.Name) + log.Println() + os.Exit(0) +} + +func myDebugExit(n *gui.Node) { + log.Println("Entered myDebugExit() on node.Name =", n.Name) + log.Println("Don't actually os.Exit()") +} diff --git a/gui-example/Makefile b/cmds/gui-example/Makefile similarity index 100% rename from gui-example/Makefile rename to cmds/gui-example/Makefile diff --git a/gui-example/main.go b/cmds/gui-example/main.go similarity index 100% rename from gui-example/main.go rename to cmds/gui-example/main.go diff --git a/debug-window.go b/debug-window.go index 61a7158..278aafb 100644 --- a/debug-window.go +++ b/debug-window.go @@ -238,6 +238,7 @@ func makeWindowDebug() *ui.Box { } }) + /* n1 = addButton(vbox, "Node.DemoTab") n1.OnClicked(func(*ui.Button) { y := nodeCombo.Selected() @@ -248,6 +249,7 @@ func makeWindowDebug() *ui.Box { node.AddDemoTab("ran gui.AddDemoTab() " + strconv.Itoa(Config.counter)) } }) + */ n1 = addButton(vbox, "Node.DemoAndlabsUiTab") n1.OnClicked(func(*ui.Button) { diff --git a/demo-window.go b/demo-window.go index 2bde8b4..144f6ac 100644 --- a/demo-window.go +++ b/demo-window.go @@ -6,6 +6,7 @@ import _ "github.com/andlabs/ui/winmanifest" var mybox *ui.Box +/* func (n *Node) AddDemoTab(title string) { newNode := n.AddTab(title, makeDemoTab()) if (Config.DebugNode) { @@ -16,7 +17,7 @@ func (n *Node) AddDemoTab(title string) { newNode.ListChildren(false) addDemoGroup(newNode, "new group 1") addDemoGroup(newNode, "new group 2") - + groupNode := newNode.AddGroup("new group 3") groupNode.AddComboBox("testing", "foo", "man", "blah") } @@ -75,6 +76,7 @@ func addDemoGroup(n *Node, title string) { vbox.Append(ecbox, false) } +*/ func (n *Node) AddGroup(title string) *Node { hbox := n.uiBox @@ -94,7 +96,7 @@ func (n *Node) AddGroup(title string) *Node { return newNode } -func (n *Node) GetText(title string) string { +func (n *Node) GetText(name string) string { if (n.uiText != nil) { return n.uiText.Text() } diff --git a/new-structs.go b/new-structs.go index 858d50f..8c190a3 100644 --- a/new-structs.go +++ b/new-structs.go @@ -240,12 +240,12 @@ func (parent *Node) AddTab(title string, uiC *ui.Box) *Node { uiC = hbox } tab.Append(title, uiC) - tab.SetMargined(0, true) // panic("gui.AddTab() before makeNode()") newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab newNode.uiBox = uiC // panic("gui.AddTab() after makeNode()") + tabSetMargined(newNode.uiTab) return newNode } From 57f95e9486eac3ff976895ecfaa16182fe56378c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 04:58:54 -0500 Subject: [PATCH 069/113] DOCS: try to start making correct go docs Signed-off-by: Jeff Carr --- demo-window.go | 72 ------------------------------------------------- doc.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ entry.go | 2 +- example_test.go | 45 +++++++++++++++++++++++++++++++ find.go | 2 +- 5 files changed, 119 insertions(+), 74 deletions(-) create mode 100644 doc.go create mode 100644 example_test.go diff --git a/demo-window.go b/demo-window.go index 144f6ac..12cbe73 100644 --- a/demo-window.go +++ b/demo-window.go @@ -6,78 +6,6 @@ import _ "github.com/andlabs/ui/winmanifest" var mybox *ui.Box -/* -func (n *Node) AddDemoTab(title string) { - newNode := n.AddTab(title, makeDemoTab()) - if (Config.DebugNode) { - newNode.Dump() - } - tabSetMargined(newNode.uiTab) - newNode.Dump() - newNode.ListChildren(false) - addDemoGroup(newNode, "new group 1") - addDemoGroup(newNode, "new group 2") - - groupNode := newNode.AddGroup("new group 3") - groupNode.AddComboBox("testing", "foo", "man", "blah") -} - -func makeDemoTab() *ui.Box { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - group := ui.NewGroup("DemoEditBox") - group.SetMargined(true) - hbox.Append(group, true) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - group.SetChild(vbox) - - ecbox := ui.NewEditableCombobox() - ecbox.Append("foo 1") - ecbox.Append("man 2") - ecbox.Append("bar 3") - - ecbox.OnChanged(func(*ui.EditableCombobox) { - log.Println("test") - test := ecbox.Text() - log.Println("test=", test) - }) - - vbox.Append(ecbox, false) - - return hbox -} - -func addDemoGroup(n *Node, title string) { - hbox := n.uiBox - if (hbox == nil) { - return - } - group := ui.NewGroup(title) - group.SetMargined(true) - hbox.Append(group, true) - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - group.SetChild(vbox) - - ecbox := ui.NewEditableCombobox() - ecbox.Append("foo 1") - ecbox.Append("man 2") - ecbox.Append("bar 3") - - ecbox.OnChanged(func(*ui.EditableCombobox) { - log.Println("test") - test := ecbox.Text() - log.Println("test=", test) - }) - - vbox.Append(ecbox, false) -} -*/ - func (n *Node) AddGroup(title string) *Node { hbox := n.uiBox if (hbox == nil) { diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..2b324c9 --- /dev/null +++ b/doc.go @@ -0,0 +1,72 @@ +/* +Package wit/gui implements a abstraction layer for Go visual elements in +a cross platform way. Right now, this abstraction is built on top of +the GUI toolkit 'andlabs/ui' which does the cross platform support. + +A quick overview of the features, some general design guidelines +and principles for how this package should generally work: + + * GUI elements are stored in a tree of nodes + * When in doubt, it's ok to guess. We will return something close. + * It tries to make your code simple + +Quick Start + +This section demonstrates how to quickly get started with spew. See the +sections below for further details on formatting and configuration options. + +To dump a variable with full newlines, indentation, type, and pointer +information use Dump, Fdump, or Sdump: + + package main + + import ( + "git.wit.org/wit/gui" + ) + + func main() { + gui.Main(initGUI) + } + + // This initializes the first window + func initGUI() { + gui.Config.Title = "WIT GUI Window 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + } + + func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + } + +Configuration Options + +Configuration of the GUI is handled by fields in the ConfigType type. For +convenience, all of the top-level functions use a global state available +via the gui.Config global. + +The following configuration options are available: + * Width + When creating a new window, this is the width + + * Height + When creating a new window, this is the height + + * Debug + When 'true' log more output + +GUI Usage + +Errors + +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. +*/ +package gui diff --git a/entry.go b/entry.go index f3abce2..12fc835 100644 --- a/entry.go +++ b/entry.go @@ -53,7 +53,7 @@ func SetText(box *GuiBox, name string, value string) error { } spew.Dump(box.Window.EntryMap) if (box.Window.EntryMap[name] == nil) { - return fmt.Errorf("gui.SetText() ERROR 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()) diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..f65cad1 --- /dev/null +++ b/example_test.go @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package gui_test + +import ( + "git.wit.org/wit/gui" +) + +// This example demonstrates how to create a NewWindow() +// +// Interacting with a GUI in a cross platform fashion adds some +// unusual problems. To obvuscate those, andlabs/ui starts a +// goroutine that interacts with the native gui toolkits +// on the Linux, MacOS, Windows, etc. +// +// Because of this oddity, to initialize a new window, the +// function is not passed any arguements and instead passes +// the information via the Config type. +// +func ExampleNewWindow() { + // Define the name and size + gui.Config.Title = "WIT GUI Window 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + + // Create the Window + gui.NewWindow() + + // Output: + // You get a window +} diff --git a/find.go b/find.go index 037ce0d..9f849e7 100644 --- a/find.go +++ b/find.go @@ -50,7 +50,7 @@ func FindWindow(s string) *GuiWindow { return window } } - log.Printf("COULD NOT FIND WINDOW", s) + log.Printf("COULD NOT FIND WINDOW " + s) return nil } From 5e5df9630e6e446493dfd08cee4db9ff73d13281 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 06:27:27 -0500 Subject: [PATCH 070/113] NODES: indent output based on depth in node tree Signed-off-by: Jeff Carr --- debug-window.go | 14 +++++++------ demo-window.go | 2 +- new-structs.go | 56 +++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/debug-window.go b/debug-window.go index 278aafb..756ebac 100644 --- a/debug-window.go +++ b/debug-window.go @@ -14,17 +14,18 @@ var names = make([]string, 100) var nodeNames = make([]string, 100) func DebugWindow() { - Config.Title = "replace InitWindow()" + Config.Title = "DebugWindow()" node := NewWindow() node.AddDebugTab("WIT GUI Debug Tab") } // TODO: remove this crap // What does this actually do? -// It populates the nodeNames in a map. No, not a map, an array. What is the difference again? -func addNodeName(c *ui.Combobox, s string) { +// It populates the nodeNames in a map. No, not a map, an array. +// What is the difference again? (other than one being in order and a predefined length) +func addNodeName(c *ui.Combobox, s string, id string) { c.Append(s) - nodeNames[y] = s + nodeNames[y] = id y = y + 1 } @@ -153,14 +154,15 @@ func makeWindowDebug() *ui.Box { }) ///////////////////////////////////////////////////// - nodeBox := addGroup(hbox, "range Data.NodeMap") + nodeBox := addGroup(hbox, "Windows:") nodeCombo := ui.NewCombobox() for name, node := range Data.NodeMap { if (Config.Debug) { log.Println("range Data.NodeMap() name =", name) } - addNodeName(nodeCombo, node.id) + tmp := node.id + " (" + name + ")" + addNodeName(nodeCombo, tmp, node.id) } nodeCombo.SetSelected(0) diff --git a/demo-window.go b/demo-window.go index 12cbe73..918b75b 100644 --- a/demo-window.go +++ b/demo-window.go @@ -46,7 +46,7 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { ecbox.OnChanged(func(*ui.EditableCombobox) { test := ecbox.Text() - log.Println("text is now:", test) + log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") }) box.Append(ecbox, false) diff --git a/new-structs.go b/new-structs.go index 8c190a3..9fe0873 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,7 +3,6 @@ package gui import ( "log" "fmt" - // "time" // "github.com/davecgh/go-spew/spew" @@ -125,23 +124,53 @@ func (n *Node) List() { findByIdDFS(n, "test") } +var listChildrenParent *Node +var listChildrenDepth int = 0 + +func indentPrintln(depth int, format string, a ...interface{}) { + var tabs string + for i := 0; i < depth; i++ { + tabs = tabs + "\t" + } + + // newFormat := tabs + strconv.Itoa(depth) + " " + format + newFormat := tabs + format + log.Println(newFormat, a) +} + func (n *Node) ListChildren(dump bool) { - log.Println("\tListChildren() node =", n.id, n.Name, n.Width, n.Height) + indentPrintln(listChildrenDepth, "\t", n.id, n.Width, n.Height, n.Name) if (dump == true) { n.Dump() } if len(n.children) == 0 { - if (n.parent != nil) { - log.Println("\t\t\tparent =",n.parent.id) + if (n.parent == nil) { + } else { + if (Config.DebugNode) { + log.Println("\t\t\tparent =",n.parent.id) + } + if (listChildrenParent != nil) { + if (Config.DebugNode) { + log.Println("\t\t\tlistChildrenParent =",listChildrenParent.id) + } + if (listChildrenParent.id != n.parent.id) { + log.Println("parent.child does not match child.parent") + panic("parent.child does not match child.parent") + } + } + } + if (Config.DebugNode) { + log.Println("\t\t", n.id, "has no children") } - log.Println("\t\t", n.id, "has no children") return } for _, child := range n.children { - log.Println("\t\tListChildren() child =",child.id, child.Name, child.Width, child.Height) + // log.Println("\t\t", child.id, child.Width, child.Height, child.Name) if (child.parent != nil) { - log.Println("\t\t\tparent =",child.parent.id) + if (Config.DebugNode) { + log.Println("\t\t\tparent =",child.parent.id) + } } else { log.Println("\t\t\tno parent") panic("no parent") @@ -149,12 +178,17 @@ func (n *Node) ListChildren(dump bool) { if (dump == true) { child.Dump() } - if (child.children == nil) { - log.Println("\t\t", child.id, "has no children") - } else { - log.Println("\t\t\tHas children:", child.children) + if (Config.DebugNode) { + if (child.children == nil) { + log.Println("\t\t", child.id, "has no children") + } else { + log.Println("\t\t\tHas children:", child.children) + } } + listChildrenParent = n + listChildrenDepth += 1 child.ListChildren(dump) + listChildrenDepth -= 1 } return } From e5763fa3177aeb454b092f09364654117af4e152 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 10:39:33 -0500 Subject: [PATCH 071/113] DOCS: clean up variable names for node.*() functions Signed-off-by: Jeff Carr --- box.go | 13 ++++++------ new-structs.go | 56 +++++++++++++++++--------------------------------- window.go | 10 ++++----- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/box.go b/box.go index 51da1c5..ef7c265 100644 --- a/box.go +++ b/box.go @@ -73,17 +73,18 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() END") } -func (parent *Node) NewBox(axis int, name string) *Node { - if (parent.box == nil) { - panic("gui.Node.NewBox() parent.box == nil") +func (n *Node) NewBox(axis int, name string) *Node { + if (n.box == nil) { + log.Println("box == nil. I can't add a box!") + panic("gui.Node.NewBox() node.box == nil") } newBox := new(GuiBox) - newBox.Window = parent.window + newBox.Window = n.window newBox.Name = name // make a new box & a new node - newNode := parent.makeNode(name, 111, 100 + Config.counter) + newNode := n.makeNode(name, 111, 100 + Config.counter) Config.counter += 1 var uiBox *ui.Box @@ -96,7 +97,7 @@ func (parent *Node) NewBox(axis int, name string) *Node { newBox.UiBox = uiBox newNode.uiBox = uiBox - parent.Append(newNode) + n.Append(newNode) // add(n.box, newBox) return newNode } diff --git a/new-structs.go b/new-structs.go index 9fe0873..5ef3309 100644 --- a/new-structs.go +++ b/new-structs.go @@ -198,54 +198,37 @@ func (n *Node) ListChildren(dump bool) { // // This function should make a new node with the parent and // the 'stuff' Node as a child -func (parent *Node) AddTabNode(title string, b *GuiBox) *Node { - // Ybox := gui.NewBox(box, gui.Yaxis, "Working Stuff") - // var baseControl ui.Control - // baseControl = Ybox.UiBox - // return baseControl - +func (n *Node) AddTabNode(title string, b *GuiBox) *Node { var newNode *Node - // var newControl ui.Control - - /* - if (parent.box == nil) { - // TODO: fix this to use a blank box - // uiC := parent.initBlankWindow() - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - newNode.uiBox = hbox - panic("node.AddTabNode() can not add a tab if the box == nil") - } - if (parent.uiTab == nil) { - panic("node.AddTabNode() can not add a tab if parent.uiTab == nil") - } - */ + parent := n newNode = parent.makeNode(title, 444, 400 + Config.counter) newNode.uiTab = parent.uiTab newNode.box = b - /* - newControl = b.UiBox - newNode.uiTab.Append(title, newControl) - */ + if (Config.DebugNode) { + fmt.Println("") + log.Println("parent:") + parent.Dump() + + fmt.Println("") + log.Println("newNode:") + newNode.Dump() + } + + if (newNode.uiTab == nil) { + log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") + // TODO: try to find the tab or window and make them if need be + return newNode + } newNode.uiTab.Append(title, b.UiBox) - fmt.Println("") - log.Println("parent:") - parent.Dump() - - fmt.Println("") - log.Println("newNode:") - newNode.Dump() - - // panic("node.AddTabNode()") - return newNode } // func (parent *Node) AddTab(title string, uiC ui.Control) *Node { -func (parent *Node) AddTab(title string, uiC *ui.Box) *Node { +func (n *Node) AddTab(title string, uiC *ui.Box) *Node { + parent := n log.Println("gui.Node.AddTab() START name =", title) if parent.uiWindow == nil { parent.Dump() @@ -275,7 +258,6 @@ func (parent *Node) AddTab(title string, uiC *ui.Box) *Node { } tab.Append(title, uiC) - // panic("gui.AddTab() before makeNode()") newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab newNode.uiBox = uiC diff --git a/window.go b/window.go index 56081d2..7415010 100644 --- a/window.go +++ b/window.go @@ -147,18 +147,18 @@ func (parent *Node) makeNode(title string, x int, y int) *Node { return &node } -func (parent *Node) AddNode(title string) *Node { +func (n *Node) AddNode(title string) *Node { var node Node node.Name = title - node.Width = parent.Width - node.Height = parent.Height + node.Width = n.Width + node.Height = n.Height id := Config.prefix + strconv.Itoa(Config.counter) Config.counter += 1 node.id = id - parent.Append(&node) - node.parent = parent + n.Append(&node) + node.parent = n return &node } From 8a87d0cb5956c673fd5b33da994a3f855e9f52f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 19:11:37 -0500 Subject: [PATCH 072/113] CLEAN: rename some functions for consistancy Signed-off-by: Jeff Carr --- cmds/gui-demo/main.go | 2 +- debug-window.go | 29 ++++------------------------- demo-window-andlabs-ui.go | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/cmds/gui-demo/main.go b/cmds/gui-demo/main.go index 372f2e2..8eae878 100644 --- a/cmds/gui-demo/main.go +++ b/cmds/gui-demo/main.go @@ -34,7 +34,7 @@ func initGUI() { gui.Config.Height = 240 gui.Config.Exit = myExit node2 := gui.NewWindow() - node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") + node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") } // This demonstrates how to properly interact with the GUI diff --git a/debug-window.go b/debug-window.go index 756ebac..19f276d 100644 --- a/debug-window.go +++ b/debug-window.go @@ -16,7 +16,7 @@ var nodeNames = make([]string, 100) func DebugWindow() { Config.Title = "DebugWindow()" node := NewWindow() - node.AddDebugTab("WIT GUI Debug Tab") + node.DebugTab("WIT GUI Debug Tab") } // TODO: remove this crap @@ -236,23 +236,10 @@ func makeWindowDebug() *ui.Box { log.Println("nodeNames[y] =", nodeNames[y]) node := Data.findId(nodeNames[y]) if (node != nil) { - node.AddDebugTab("added this DebugTab") + node.DebugTab("added this DebugTab") } }) - /* - n1 = addButton(vbox, "Node.DemoTab") - n1.OnClicked(func(*ui.Button) { - y := nodeCombo.Selected() - log.Println("y =", y) - log.Println("nodeNames[y] =", nodeNames[y]) - node := Data.findId(nodeNames[y]) - if (node != nil) { - node.AddDemoTab("ran gui.AddDemoTab() " + strconv.Itoa(Config.counter)) - } - }) - */ - n1 = addButton(vbox, "Node.DemoAndlabsUiTab") n1.OnClicked(func(*ui.Button) { y := nodeCombo.Selected() @@ -260,18 +247,10 @@ func makeWindowDebug() *ui.Box { log.Println("nodeNames[y] =", nodeNames[y]) node := Data.findId(nodeNames[y]) if (node != nil) { - node.AddDemoAndlabsUiTab("ran gui.AddDemoAndlabsUiTab() " + strconv.Itoa(Config.counter)) + node.DemoAndlabsUiTab("ran gui.AddDemoAndlabsUiTab() " + strconv.Itoa(Config.counter)) } }) -/* - ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Numbers") - pbar := ui.NewProgressBar() - vbox.Append(pbar, false) -*/ - - return hbox } @@ -351,7 +330,7 @@ func addButton(box *ui.Box, name string) *ui.Button { return button } -func (n *Node) AddDebugTab(title string) { +func (n *Node) DebugTab(title string) { newNode := n.AddTab(title, makeWindowDebug()) if (Config.DebugNode) { newNode.Dump() diff --git a/demo-window-andlabs-ui.go b/demo-window-andlabs-ui.go index 806dc14..e11ffe9 100644 --- a/demo-window-andlabs-ui.go +++ b/demo-window-andlabs-ui.go @@ -8,7 +8,7 @@ import _ "github.com/andlabs/ui/winmanifest" // calls to andlabs/ui. This can be used to bypass // the obvuscation added in this package if it is desired // or needed. -func (n *Node) AddDemoAndlabsUiTab(title string) { +func (n *Node) DemoAndlabsUiTab(title string) { newNode := n.AddTab(title, makeAndlabsUiTab()) if (Config.DebugNode) { newNode.Dump() From 15f9f92c62c302b4f8b958e581a7125a62236d5d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 28 Oct 2021 19:47:49 -0500 Subject: [PATCH 073/113] BOX: start node.button() funcs in the rabbit hole Signed-off-by: Jeff Carr --- box.go | 12 ++++++------ button.go | 26 ++++++++++++++++++++++++++ find.go | 7 +++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/box.go b/box.go index ef7c265..9d9833d 100644 --- a/box.go +++ b/box.go @@ -73,18 +73,18 @@ func add(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() END") } -func (n *Node) NewBox(axis int, name string) *Node { - if (n.box == nil) { - log.Println("box == nil. I can't add a box!") - panic("gui.Node.NewBox() node.box == nil") - } - +func (n *Node) AddBox(axis int, name string) *Node { newBox := new(GuiBox) newBox.Window = n.window newBox.Name = name + if (n.box == nil) { + n.box = newBox + } + // make a new box & a new node newNode := n.makeNode(name, 111, 100 + Config.counter) + newNode.box = newBox Config.counter += 1 var uiBox *ui.Box diff --git a/button.go b/button.go index 825b79b..d616178 100644 --- a/button.go +++ b/button.go @@ -50,6 +50,32 @@ func guiButtonClick(button *GuiButton) { } } +func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { + newNode := n.AddBox(Xaxis, "test") + box := newNode.FindBox() + if (box == nil) { + panic("node.CreateButton().FindBox() == nil") + } + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) + + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.UiBox == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } + newB.Box = box + newB.Custom = custom + newB.Values = values + + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newNode +} func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) diff --git a/find.go b/find.go index 9f849e7..e046161 100644 --- a/find.go +++ b/find.go @@ -18,6 +18,13 @@ func (n *Node) FindControl() *ui.Control { } func (n *Node) FindBox() *GuiBox { + if (n.box != nil) { + return n.box + } + if (n.parent != nil) { + p := n.parent + return p.box + } return n.box } From c91f91b0d60890c20245dfae7afe2044cbe72a28 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 30 Oct 2021 17:11:28 -0500 Subject: [PATCH 074/113] NODE: still in the rabbit hole Signed-off-by: Jeff Carr --- button.go | 5 ++++- structs.go | 27 ++++++++++++++------------- window.go | 29 +---------------------------- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/button.go b/button.go index d616178..e1d141c 100644 --- a/button.go +++ b/button.go @@ -51,7 +51,7 @@ func guiButtonClick(button *GuiButton) { } func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { - newNode := n.AddBox(Xaxis, "test") + newNode := n.AddBox(Xaxis, "test CreateButton") box := newNode.FindBox() if (box == nil) { panic("node.CreateButton().FindBox() == nil") @@ -66,6 +66,9 @@ func (n *Node) CreateButton(custom func(*GuiButton), name string, values interfa log.Println("CreateButton() box.Window == nil") // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this panic("maybe print an error and return nil? or make a fake button?") + } else { + // uibox := box.UiBox + // uibox.Append(newUiB, true) } newB.Box = box newB.Custom = custom diff --git a/structs.go b/structs.go index 23a5ca8..13dc2ea 100644 --- a/structs.go +++ b/structs.go @@ -125,23 +125,23 @@ type GuiBox struct { UiBox *ui.Box } -func (gb *GuiBox) Dump() { - log.Println("gui.GuiBox.Dump() Name = ", gb.Name) - log.Println("gui.GuiBox.Dump() Axis = ", gb.Axis) - log.Println("gui.GuiBox.Dump() GuiWindow = ", gb.Window) - log.Println("gui.GuiBox.Dump() node = ", gb.node) - log.Println("gui.GuiBox.Dump() UiBox = ", gb.UiBox) +func (b *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", b.Name) + log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) + log.Println("gui.GuiBox.Dump() node = ", b.node) + log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) } -func (s GuiBox) SetTitle(title string) { +func (b *GuiBox) SetTitle(title string) { log.Println("DID IT!", title) - if s.Window == nil { + if b.Window == nil { return } - if s.Window.UiWindow == nil { + if b.Window.UiWindow == nil { return } - s.Window.UiWindow.SetTitle(title) + b.Window.UiWindow.SetTitle(title) return } @@ -169,11 +169,12 @@ func (b *GuiBox) SetNode(n *Node) { } } -func (s GuiBox) Append(child ui.Control, x bool) { - if s.UiBox == nil { +func (b *GuiBox) Append(child ui.Control, x bool) { + if b.UiBox == nil { + panic("GuiBox.Append() can't work. UiBox == nil") return } - s.UiBox.Append(child, x) + b.UiBox.Append(child, x) } // Note: every mouse click is handled diff --git a/window.go b/window.go index 7415010..610e64f 100644 --- a/window.go +++ b/window.go @@ -183,34 +183,6 @@ func (n *Node) uiNewWindow(title string, x int, y int) { } /* -func CreateBlankWindow(title string, x int, y int) *Node { - node := mapWindow(nil, nil, title, x, y) - box := node.box - log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) - - node.uiNewWindow(box.Name, x, y) - window := node.uiWindow - - ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", box.Name) - window.Destroy() - return true - }) - - box.Window.UiWindow = window - return node -} -*/ - -/* -func (n *Node) initBlankWindow() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - return hbox -} -*/ - func makeBlankNode(title string) *Node { log.Println("gui.makeBlankNode() title =", title) if Data.NodeMap[title] != nil { @@ -226,6 +198,7 @@ func makeBlankNode(title string) *Node { node := makeNode(nil, title, x, y) return node } +*/ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) From 741361c000969e0a0c96c67dca53eea65be5a4d1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 03:50:22 -0500 Subject: [PATCH 075/113] NODE: add a button in the hole that doesn't use the other hole Signed-off-by: Jeff Carr --- area.go | 10 ++--- box.go | 8 ++-- cmds/gui-demo/demo-window.go | 73 ++++++++++++++++++++++++++++++++++++ entry.go | 14 +++---- new-structs.go | 24 +++++++++++- structs.go | 10 ++--- table.go | 9 +++-- 7 files changed, 120 insertions(+), 28 deletions(-) diff --git a/area.go b/area.go index 0cc7531..7c42c6c 100644 --- a/area.go +++ b/area.go @@ -107,10 +107,10 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButton), name string) { +func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") - gw := box.Window + gw := b.Window if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") return @@ -127,10 +127,10 @@ func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButt */ // TODO: allow padded & axis here - box.UiBox.SetPadded(true) + b.UiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - makeGenericArea(box, newText, custom) - box.UiBox.Append(box.Window.Area.UiArea, true) + makeGenericArea(b, newText, custom) + b.UiBox.Append(b.Window.Area.UiArea, true) } diff --git a/box.go b/box.go index 9d9833d..61ee2e7 100644 --- a/box.go +++ b/box.go @@ -102,9 +102,9 @@ func (n *Node) AddBox(axis int, name string) *Node { return newNode } -func NewBox(box *GuiBox, axis int, name string) *GuiBox { +func (b *GuiBox) NewBox(axis int, name string) *GuiBox { log.Println("gui.NewBox() START") - n := box.FindNode() + n := b.FindNode() if (n == nil) { log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") os.Exit(0) @@ -113,7 +113,7 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { } var newbox *GuiBox newbox = new(GuiBox) - newbox.Window = box.Window + newbox.Window = b.Window newbox.Name = name var uiBox *ui.Box @@ -124,7 +124,7 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { } uiBox.SetPadded(true) newbox.UiBox = uiBox - add(box, newbox) + add(b, newbox) // panic("gui.NewBox") return newbox } diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go index f0cfcce..c0e426d 100644 --- a/cmds/gui-demo/demo-window.go +++ b/cmds/gui-demo/demo-window.go @@ -1,7 +1,14 @@ package main +import "log" + import "git.wit.org/wit/gui" +/* +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" +*/ + func addDemoTab(n *gui.Node, title string) { newNode := n.AddTab(title, nil) if (gui.Config.Debug) { @@ -11,7 +18,73 @@ func addDemoTab(n *gui.Node, title string) { groupNode1 := newNode.AddGroup("group 1") groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff") + groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") + + groupNode1.Dump() + /* + b := groupNode1.FindBox() + b.Dump() + */ + // n1, b1 := addButton(groupNode1, "Data.ListChildren(false)") +/* + b1.OnClicked(func(*ui.Button) { + gui.Data.ListChildren(false) + }) +*/ + + //n2, b2 := addButton(groupNode1, "dumpBox(window)") + newNode2 := groupNode1.AppendButton("foo 3 " + "AppendButton()", func(groupNode1 *gui.Node) { + log.Println("Dumping groupNode1") + groupNode1.Dump() + }) + newNode2.Dump() +/* + b2.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + x.Dump(names[x]) + }) + n2.Dump() +*/ groupNode2 := newNode.AddGroup("group 2") groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") } + +/* +func addButton(n *gui.Node, name string) (*gui.Node, *ui.Button) { + // val := &myButtonInfo{} + button := ui.NewButton(name) + // val.uiC = button + + button.OnClicked(func(*ui.Button) { + log.Println("Should do something here") + }) + + // n.Append(button, false) + newNode := n.AppendButton(name + "AppendButton", func() { + log.Println("Should do something here also") + }) + return newNode, button +} +*/ + +/* +type myButtonInfo struct { + Custom func (*gui.GuiButton) + ADD func (*gui.GuiButton) + Name string + Action string + Node *gui.Node +} + +func newMakeButton(n *gui.Node, name string, action string, custom func(*gui.GuiButton)) *gui.Node { + val := &myButtonInfo{} + val.Custom = custom + val.Name = name + val.Node = n + // val.Action = action + return n.CreateButton(custom, name, val) +} +*/ diff --git a/entry.go b/entry.go index 12fc835..b2ef8f4 100644 --- a/entry.go +++ b/entry.go @@ -24,21 +24,17 @@ func (n *Node) NewLabel(text string) *Node { return newNode } -func GetText(box *GuiBox, name string) string { - if (box == nil) { - log.Println("gui.GetText() ERROR box == nil") - return "" - } - if (box.Window.EntryMap == nil) { +func (b *GuiBox) GetText(name string) string { + if (b.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) { + spew.Dump(b.Window.EntryMap) + if (b.Window.EntryMap[name] == nil) { log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") return "" } - e := box.Window.EntryMap[name] + e := b.Window.EntryMap[name] log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) log.Println("gui.GetText() END") return e.UiEntry.Text() diff --git a/new-structs.go b/new-structs.go index 5ef3309..915f881 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,6 +3,7 @@ package gui import ( "log" "fmt" + "reflect" // "github.com/davecgh/go-spew/spew" @@ -50,7 +51,8 @@ type Node struct { window *GuiWindow box *GuiBox - uiControl *ui.Control + uiControl *ui.Control + uiButton *ui.Button uiWindow *ui.Window uiTab *ui.Tab uiBox *ui.Box @@ -85,6 +87,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() uiTab = ", n.uiTab) log.Println("gui.Node.Dump() uiBox = ", n.uiBox) log.Println("gui.Node.Dump() uiControl = ", n.uiControl) + log.Println("gui.Node.Dump() uiButton = ", n.uiButton) if (n.id == "") { panic("gui.Node.Dump() id == nil") } @@ -120,6 +123,25 @@ func (n *Node) Append(child *Node) { // time.Sleep(3 * time.Second) } +func (n *Node) AppendButton(name string, custom func(*Node)) *Node { + if (n.uiBox == nil) { + log.Println("gui.Node.AppendButton() filed node.UiBox == nil") + return n + } + button := ui.NewButton(name) + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + n.uiBox.Append(button, false) + n.uiButton = button + button.OnClicked(func(*ui.Button) { + log.Println("gui.AppendButton() Button Clicked. Running custom()") + custom(n) + }) + // panic("AppendButton") + // time.Sleep(3 * time.Second) + return n +} + func (n *Node) List() { findByIdDFS(n, "test") } diff --git a/structs.go b/structs.go index 13dc2ea..c15f4b7 100644 --- a/structs.go +++ b/structs.go @@ -105,11 +105,11 @@ type GuiWindow struct { UiTab *ui.Tab // if this != nil, the window is 'tabbed' } -func (gw *GuiWindow) Dump() { - log.Println("gui.GuiWindow.Dump() Name = ", gw.Name) - log.Println("gui.GuiWindow.Dump() node = ", gw.node) - log.Println("gui.GuiWindow.Dump() Width = ", gw.Width) - log.Println("gui.GuiWindow.Dump() Height = ", gw.Height) +func (w *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", w.Name) + log.Println("gui.GuiWindow.Dump() node = ", w.node) + log.Println("gui.GuiWindow.Dump() Width = ", w.Width) + log.Println("gui.GuiWindow.Dump() Height = ", w.Height) } // GuiBox is any type of ui.Hbox or ui.Vbox diff --git a/table.go b/table.go index 3ed8c6a..92ae871 100644 --- a/table.go +++ b/table.go @@ -99,10 +99,11 @@ func InitColumns(mh *TableData, parts []TableColumnData) { func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { node := NewWindow() - return AddTableBox(node.box, name, rowcount, parts) + b := node.box + return b.AddTableBox(name, rowcount, parts) } -func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData { +func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData) mh.RowCount = rowcount @@ -141,9 +142,9 @@ func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData // is this needed? // gw.BoxMap[name] = box - mh.Box = box + mh.Box = b - box.UiBox.Append(table, true) + b.UiBox.Append(table, true) return mh } From d57f74ff45ab4f0302f591f7a7752574ccb1e4a0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 04:06:46 -0500 Subject: [PATCH 076/113] NODE: make node entries for the buttons Signed-off-by: Jeff Carr --- cmds/gui-demo/demo-window.go | 75 +++++------------------------------- new-structs.go | 12 ++++-- 2 files changed, 18 insertions(+), 69 deletions(-) diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go index c0e426d..fd8e8f4 100644 --- a/cmds/gui-demo/demo-window.go +++ b/cmds/gui-demo/demo-window.go @@ -4,10 +4,10 @@ import "log" import "git.wit.org/wit/gui" -/* -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" -*/ +func demoClick (n *gui.Node) { + log.Println("demoClick() Dumping node:") + n.Dump() +} func addDemoTab(n *gui.Node, title string) { newNode := n.AddTab(title, nil) @@ -21,70 +21,13 @@ func addDemoTab(n *gui.Node, title string) { groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") groupNode1.Dump() - /* - b := groupNode1.FindBox() - b.Dump() - */ - // n1, b1 := addButton(groupNode1, "Data.ListChildren(false)") -/* - b1.OnClicked(func(*ui.Button) { - gui.Data.ListChildren(false) - }) -*/ - //n2, b2 := addButton(groupNode1, "dumpBox(window)") - newNode2 := groupNode1.AppendButton("foo 3 " + "AppendButton()", func(groupNode1 *gui.Node) { - log.Println("Dumping groupNode1") - groupNode1.Dump() - }) - newNode2.Dump() -/* - b2.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("names[x] =", names[x]) - x.Dump(names[x]) - }) - n2.Dump() -*/ + butNode1 := groupNode1.AddButton("button1", demoClick) + butNode1.Dump() + + butNode2 := groupNode1.AddButton("button2", demoClick) + butNode2.Dump() groupNode2 := newNode.AddGroup("group 2") groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") } - -/* -func addButton(n *gui.Node, name string) (*gui.Node, *ui.Button) { - // val := &myButtonInfo{} - button := ui.NewButton(name) - // val.uiC = button - - button.OnClicked(func(*ui.Button) { - log.Println("Should do something here") - }) - - // n.Append(button, false) - newNode := n.AppendButton(name + "AppendButton", func() { - log.Println("Should do something here also") - }) - return newNode, button -} -*/ - -/* -type myButtonInfo struct { - Custom func (*gui.GuiButton) - ADD func (*gui.GuiButton) - Name string - Action string - Node *gui.Node -} - -func newMakeButton(n *gui.Node, name string, action string, custom func(*gui.GuiButton)) *gui.Node { - val := &myButtonInfo{} - val.Custom = custom - val.Name = name - val.Node = n - // val.Action = action - return n.CreateButton(custom, name, val) -} -*/ diff --git a/new-structs.go b/new-structs.go index 915f881..9e1ae3d 100644 --- a/new-structs.go +++ b/new-structs.go @@ -50,6 +50,7 @@ type Node struct { window *GuiWindow box *GuiBox + custom func(*Node) uiControl *ui.Control uiButton *ui.Button @@ -123,7 +124,7 @@ func (n *Node) Append(child *Node) { // time.Sleep(3 * time.Second) } -func (n *Node) AppendButton(name string, custom func(*Node)) *Node { +func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { log.Println("gui.Node.AppendButton() filed node.UiBox == nil") return n @@ -133,13 +134,18 @@ func (n *Node) AppendButton(name string, custom func(*Node)) *Node { log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) n.uiBox.Append(button, false) n.uiButton = button + + newNode := n.makeNode(name, 888, 888 + Config.counter) + newNode.uiButton = button + newNode.custom = custom + button.OnClicked(func(*ui.Button) { log.Println("gui.AppendButton() Button Clicked. Running custom()") - custom(n) + custom(newNode) }) // panic("AppendButton") // time.Sleep(3 * time.Second) - return n + return newNode } func (n *Node) List() { From 5ad39c8df99662c707dc05f9e98a11545e2c5b2b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 04:13:14 -0500 Subject: [PATCH 077/113] NODE: remove old code Signed-off-by: Jeff Carr --- window.go | 65 ------------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/window.go b/window.go index 610e64f..8598ec4 100644 --- a/window.go +++ b/window.go @@ -52,53 +52,6 @@ func DeleteWindow(name string) { } } -/* -func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *Node { - n := CreateBlankWindow(title, x, y) - if (n.box == nil) { - log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") - log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") - log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") - log.Println("SERIOUS ERROR n.box == nil in CreateWindow()") - } - n.AddTab(title, custom()) - // TODO: run custom() here // Oct 9 - return n -} -*/ - -/* -func (n *Node) Add(e Element) *Node { - newNode := n.addNode("testingAdd") - if(e == Tab) { - log.Println("gui.Add() SHOULD ADD element =", e.String()) - } - return newNode -} -*/ - -/* -// -// Create a new node -// if parent == nil, that means it is a new window and needs to be put -// in the window map (aka Data.NodeMap) -// -func (parent *Node) addNode(title string) *Node { - var node Node - node.Name = title - node.Width = parent.Width - node.Height = parent.Height - node.parent = parent - - id := Config.prefix + strconv.Itoa(Config.counter) - Config.counter += 1 - node.id = id - - parent.Append(&node) - return &node -} -*/ - func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title @@ -182,24 +135,6 @@ func (n *Node) uiNewWindow(title string, x int, y int) { return } -/* -func makeBlankNode(title string) *Node { - log.Println("gui.makeBlankNode() title =", title) - if Data.NodeMap[title] != nil { - log.Println("gui.makeBlankNode() already exists title =", title) - title = title + Config.prefix + strconv.Itoa(Config.counter) - Config.counter += 1 - } - if Data.NodeMap[title] != nil { - panic("gui.makeBlankNode() already exists") - return nil - } - - node := makeNode(nil, title, x, y) - return node -} -*/ - func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) if Data.WindowMap[title] != nil { From 73006c8b5e413e511ce2b9df0158d16b79d615c2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 05:19:51 -0500 Subject: [PATCH 078/113] NODE: switch more around Signed-off-by: Jeff Carr --- button.go | 27 +++++++++++++++++++++++++++ new-structs.go | 27 +-------------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/button.go b/button.go index e1d141c..8ad0a3b 100644 --- a/button.go +++ b/button.go @@ -1,10 +1,12 @@ package gui import "log" +import "reflect" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" + // This is the default mouse click handler // Every mouse click that hasn't been assigned to // something specific will fall into this routine @@ -50,6 +52,30 @@ func guiButtonClick(button *GuiButton) { } } +func (n *Node) AddButton(name string, custom func(*Node)) *Node { + if (n.uiBox == nil) { + log.Println("gui.Node.AppendButton() filed node.UiBox == nil") + return n + } + button := ui.NewButton(name) + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + n.uiBox.Append(button, false) + n.uiButton = button + + newNode := n.makeNode(name, 888, 888 + Config.counter) + newNode.uiButton = button + newNode.custom = custom + + button.OnClicked(func(*ui.Button) { + log.Println("gui.AppendButton() Button Clicked. Running custom()") + custom(newNode) + }) + // panic("AppendButton") + // time.Sleep(3 * time.Second) + return newNode +} + func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { newNode := n.AddBox(Xaxis, "test CreateButton") box := newNode.FindBox() @@ -79,6 +105,7 @@ func (n *Node) CreateButton(custom func(*GuiButton), name string, values interfa box.Append(newB.B, false) return newNode } + func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) diff --git a/new-structs.go b/new-structs.go index 9e1ae3d..8c1f300 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,7 +3,7 @@ package gui import ( "log" "fmt" - "reflect" +// "reflect" // "github.com/davecgh/go-spew/spew" @@ -124,30 +124,6 @@ func (n *Node) Append(child *Node) { // time.Sleep(3 * time.Second) } -func (n *Node) AddButton(name string, custom func(*Node)) *Node { - if (n.uiBox == nil) { - log.Println("gui.Node.AppendButton() filed node.UiBox == nil") - return n - } - button := ui.NewButton(name) - log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) - log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) - n.uiBox.Append(button, false) - n.uiButton = button - - newNode := n.makeNode(name, 888, 888 + Config.counter) - newNode.uiButton = button - newNode.custom = custom - - button.OnClicked(func(*ui.Button) { - log.Println("gui.AppendButton() Button Clicked. Running custom()") - custom(newNode) - }) - // panic("AppendButton") - // time.Sleep(3 * time.Second) - return newNode -} - func (n *Node) List() { findByIdDFS(n, "test") } @@ -254,7 +230,6 @@ func (n *Node) AddTabNode(title string, b *GuiBox) *Node { return newNode } -// func (parent *Node) AddTab(title string, uiC ui.Control) *Node { func (n *Node) AddTab(title string, uiC *ui.Box) *Node { parent := n log.Println("gui.Node.AddTab() START name =", title) From c80f805bff056f59368a1080d21a7c72bed04a14 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 07:06:10 -0500 Subject: [PATCH 079/113] NODE: migrate more of my personal gui app Signed-off-by: Jeff Carr --- box.go | 37 +++++++++++ cmds/gui-example/demo-window.go | 105 ++++++++++++++++++++++++++++++++ cmds/gui-example/main.go | 4 +- cmds/gui-example/os.go | 99 ++++++++++++++++++++++++++++++ demo-window.go | 34 +---------- 5 files changed, 244 insertions(+), 35 deletions(-) create mode 100644 cmds/gui-example/demo-window.go create mode 100644 cmds/gui-example/os.go diff --git a/box.go b/box.go index 61ee2e7..7a61f55 100644 --- a/box.go +++ b/box.go @@ -185,3 +185,40 @@ func VerticalBreak(box *GuiBox) { tmp := ui.NewVerticalSeparator() box.UiBox.Append(tmp, false) } + +func (n *Node) AddComboBox(title string, s ...string) *Node { + box := n.uiBox + if (box == nil) { + return n + } + + ecbox := ui.NewEditableCombobox() + + for id, name := range s { + log.Println("Adding Combobox Entry:", id, name) + ecbox.Append(name) + } + + ecbox.OnChanged(func(*ui.EditableCombobox) { + test := ecbox.Text() + log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") + }) + + box.Append(ecbox, false) + + newNode := n.AddNode(title) + newNode.uiText = ecbox + return newNode +} + +func (n *Node) OnChanged(f func()) { + f() +} + +func (n *Node) GetText() string { + if (n.uiText == nil) { + return "" + } + ecbox := n.uiText + return ecbox.Text() +} diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go new file mode 100644 index 0000000..993900d --- /dev/null +++ b/cmds/gui-example/demo-window.go @@ -0,0 +1,105 @@ +package main + +import "log" +import "reflect" + +import "git.wit.org/wit/gui" + +import "github.com/davecgh/go-spew/spew" + +func demoClick (n *gui.Node) { + log.Println("demoClick() Dumping node:") + n.Dump() +} + +var username = "jcarr" +var hostname = "fire" + +func newClick (n *gui.Node) { + var tmp []string + junk := "ssh -v " + username + "@" + hostname + log.Println("junk = " , junk) + xterm(junk) + log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) + // spew.Dump(tmp) +} + +func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + if (gui.Config.Debug) { + newNode.Dump() + } + newNode.ListChildren(false) + + groupNode1 := newNode.AddGroup("group 1") + cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") + cbNode.OnChanged(func () { + username = cbNode.GetText() + }) + groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") + + groupNode1.Dump() + + butNode1 := groupNode1.AddButton("button1", demoClick) + butNode1.Dump() + + butNode2 := groupNode1.AddButton("button2", newClick) + butNode2.Dump() + + groupNode2 := newNode.AddGroup("group 2") + groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + + gNode := newNode.AddGroup("domU") + makeSSHbutton(gNode, "hugo@www", "www.wit.org") + makeSSHbutton(gNode, "check.lab", "check.lab.wit.org") + makeSSHbutton(gNode, "gobuild.lab", "gobuild.lab.wit.org") + makeSSHbutton(gNode, "gobuild2.lab", "gobuild2.lab.wit.org") + +/////////////////////////////// Column DNS //////////////////////////////// + gNode = newNode.AddGroup("dns") + makeSSHbutton(gNode, "bind.wit.org", "bind.wit.org") + makeSSHbutton(gNode, "ns1.wit.com", "ns1.wit.com") + makeSSHbutton(gNode, "ns2.wit.com", "ns2.wit.com") + makeSSHbutton(gNode, "coredns", "coredns.lab.wit.org") + +/////////////////////////////// PHYS 530 ////////////////////////////////// + gNode = newNode.AddGroup("phys 530") + // makeXtermButton(gNode, "openwrt", "SUBDOMAIN", "ssh -4 -v root@openwrt") + gNode.AddButton("openwrt", func (*gui.Node) { + stuff := "ssh -4 -v root@openwrt" + xterm(stuff) + }) + makeSSHbutton (gNode, "mirrors", "mirrors.wit.org") + makeSSHbutton (gNode, "node004", "node004.lab.wit.org") + makeSSHbutton (gNode, "lenovo-z70", "lenovo-z70.lab.wit.org") + +/////////////////////////////// PHYS 522 ////////////////////////////////// + gNode = newNode.AddGroup("phys 522") + // makeXtermButton(gNode, "openwrt2", "SUBDOMAIN", "ssh -4 -v root@openwrt2") + gNode.AddButton("openwrt2", func (*gui.Node) { + stuff := "ssh -4 -v root@openwrt2" + xterm(stuff) + }) + makeSSHbutton (gNode, "fire.lab", "fire.lab.wit.org") + makeSSHbutton (gNode, "predator", "predator.lab.wit.org") + +/////////////////////////////// FLOAT ///////////////////////////////////// + gNode = newNode.AddGroup("float") + makeSSHbutton(gNode, "root@asus-n501vw", "asus-n501vw.lab.wit.org") +} + +func makeSSHbutton (n *gui.Node, name string, hostname string) { + bNode := n.AddButton(name, func (*gui.Node) { + var tmp []string + if (username == "") { + username = "root" + } + junk := "ssh -v " + username + "@" + hostname + log.Println("junk = " , junk) + log.Println("username = '" + username + "'") + xterm(junk) + log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) + spew.Dump(tmp) + }) + bNode.Dump() +} diff --git a/cmds/gui-example/main.go b/cmds/gui-example/main.go index 9fcb971..8eae878 100644 --- a/cmds/gui-example/main.go +++ b/cmds/gui-example/main.go @@ -27,14 +27,14 @@ func initGUI() { gui.Config.Height = 480 gui.Config.Exit = myExit node1 := gui.NewWindow() - node1.AddDemoTab("A Simple Tab Demo") + addDemoTab(node1, "A Simple Tab Demo") gui.Config.Title = "WIT GUI Window Demo 2" gui.Config.Width = 640 gui.Config.Height = 240 gui.Config.Exit = myExit node2 := gui.NewWindow() - node2.AddDemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") + node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") } // This demonstrates how to properly interact with the GUI diff --git a/cmds/gui-example/os.go b/cmds/gui-example/os.go new file mode 100644 index 0000000..ce5db8d --- /dev/null +++ b/cmds/gui-example/os.go @@ -0,0 +1,99 @@ +package main + +import "log" +import "strings" +import "os" +import "os/exec" +import "io/ioutil" +import "errors" +// import "bufio" + +// import "github.com/davecgh/go-spew/spew" + +/* +import "time" +import "runtime" +import "runtime/debug" +import "runtime/pprof" + +import "git.wit.org/wit/gui" +import "git.wit.org/wit/shell" +import "github.com/gobuffalo/packr" +*/ + +func runSimpleCommand(s string) { + cmd := strings.TrimSpace(s) // this is like 'chomp' in perl + cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl + cmdArgs := strings.Fields(cmd) + runLinuxCommand(cmdArgs) +} + +var geom string = "120x30+500+500" + +func xterm(cmd string) { + var tmp []string + var argsXterm = []string{"nohup", "xterm", "-geometry", geom} + tmp = append(argsXterm, "-hold", "-e", cmd) + log.Println("xterm cmd=", cmd) + go runCommand(tmp) +} + +func runCommand(cmdArgs []string) { + log.Println("runCommand() START", cmdArgs) + process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + // process := exec.Command("xterm", "-e", "ping localhost") + log.Println("runCommand() process.Start()") + process.Start() + log.Println("runCommand() process.Wait()") + err := process.Wait() + lookupError(err) + log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED") + log.Println("runCommand() OTHERWISE INFORM THE USER") + log.Println("runCommand() END", cmdArgs) +} + +func lookupError(err error) { + var ( + ee *exec.ExitError + pe *os.PathError + ) + + if errors.As(err, &ee) { + log.Println("ran, but non-zero exit code =", ee.ExitCode()) // ran, but non-zero exit code + } else if errors.As(err, &pe) { + log.Printf("os.PathError = %v", pe) // "no such file ...", "permission denied" etc. + } else if err != nil { + log.Printf("something really bad happened general err = %v", err) // something really bad happened! + if exitError, ok := err.(*exec.ExitError); ok { + log.Printf("exitError.ExitCode() is %d\n", exitError.ExitCode()) + } + } else { + log.Println("success! // ran without error (exit code zero)") + } +} + +func runLinuxCommand(cmdArgs []string) (string, error) { + process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + + process.Stdin = os.Stdin + process.Stderr = os.Stderr + + stdOut, err := process.StdoutPipe() + if err != nil { + return "", err + } + + if err := process.Start(); err != nil { + return "", err + } + + bytes, err := ioutil.ReadAll(stdOut) + if err != nil { + return "", err + } + err = process.Wait() + lookupError(err) + + log.Println(string(bytes)) + return string(bytes), err +} diff --git a/demo-window.go b/demo-window.go index 918b75b..751a3cc 100644 --- a/demo-window.go +++ b/demo-window.go @@ -1,6 +1,6 @@ package gui -import "log" +// import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -23,35 +23,3 @@ func (n *Node) AddGroup(title string) *Node { newNode.uiBox = vbox return newNode } - -func (n *Node) GetText(name string) string { - if (n.uiText != nil) { - return n.uiText.Text() - } - return n.Name -} - -func (n *Node) AddComboBox(title string, s ...string) *Node { - box := n.uiBox - if (box == nil) { - return n - } - - ecbox := ui.NewEditableCombobox() - - for id, name := range s { - log.Println("Adding Combobox Entry:", id, name) - ecbox.Append(name) - } - - ecbox.OnChanged(func(*ui.EditableCombobox) { - test := ecbox.Text() - log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") - }) - - box.Append(ecbox, false) - - newNode := n.AddNode(title) - newNode.uiText = ecbox - return newNode -} From f72c88dafe534e8a9c0b2001da08a3fbd26de80e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 12:20:20 -0500 Subject: [PATCH 080/113] NODE: walking Signed-off-by: Jeff Carr --- entry.go | 13 +++++++++++++ window.go | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/entry.go b/entry.go index b2ef8f4..c24fe50 100644 --- a/entry.go +++ b/entry.go @@ -40,6 +40,19 @@ func (b *GuiBox) GetText(name string) string { return e.UiEntry.Text() } +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 + } + return nil +} + func SetText(box *GuiBox, name string, value string) error { if (box == nil) { return fmt.Errorf("gui.SetText() ERROR box == nil") diff --git a/window.go b/window.go index 8598ec4..40c4443 100644 --- a/window.go +++ b/window.go @@ -77,9 +77,9 @@ func makeNode(parent *Node, title string, x int, y int) *Node { // panic("gui.makeNode() after NodeMap()") return &node } else { - panic("gui.makeNode() before Append()") + // panic("gui.makeNode() before Append()") parent.Append(&node) - panic("gui.makeNode() after Append()") + // panic("gui.makeNode() after Append()") } node.parent = parent return &node From f8766de9a0d80b38e008da25f470f98544603f02 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 12:57:54 -0500 Subject: [PATCH 081/113] NODE: resurrect 'ssh' window Signed-off-by: Jeff Carr --- demo-window.go | 3 +++ entry.go | 4 ++-- new-structs.go | 3 ++- window.go | 19 +++++++++++-------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/demo-window.go b/demo-window.go index 751a3cc..16566c4 100644 --- a/demo-window.go +++ b/demo-window.go @@ -7,6 +7,9 @@ import _ "github.com/andlabs/ui/winmanifest" var mybox *ui.Box func (n *Node) AddGroup(title string) *Node { + if (n == nil) { + return nil + } hbox := n.uiBox if (hbox == nil) { return n diff --git a/entry.go b/entry.go index c24fe50..c10b7d0 100644 --- a/entry.go +++ b/entry.go @@ -42,11 +42,11 @@ func (b *GuiBox) GetText(name string) string { func (n *Node) SetText(value string) error { log.Println("gui.SetText() value =", value) - if (n.uiText == nil) { + if (n.uiText != nil) { n.uiText.SetText(value) return nil } - if (n.uiButton == nil) { + if (n.uiButton != nil) { n.uiButton.SetText(value) return nil } diff --git a/new-structs.go b/new-structs.go index 8c1f300..4f9989e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -235,7 +235,8 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() START name =", title) if parent.uiWindow == nil { parent.Dump() - panic("gui.AddTab() ERROR ui.Window == nil") + log.Println("gui.Node.AddTab() ERROR ui.Window == nil") + return nil } if parent.box == nil { parent.Dump() diff --git a/window.go b/window.go index 40c4443..403638e 100644 --- a/window.go +++ b/window.go @@ -184,23 +184,26 @@ func NewWindow() *Node { w := Config.Width h := Config.Height - var node *Node - node = mapWindow(nil, nil, title, w, h) - box := node.box + var n *Node + n = mapWindow(nil, nil, title, w, h) + box := n.box log.Println("gui.NewWindow() title = box.Name =", box.Name) - node.uiNewWindow(box.Name, w, h) - window := node.uiWindow + n.uiNewWindow(box.Name, w, h) + window := n.uiWindow f := Config.Exit ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy() on node.Name =", node.Name) + log.Println("createWindow().Destroy() on node.Name =", n.Name) if (f != nil) { - f(node) + f(n) } return true }) box.Window.UiWindow = window - return node + if(n.uiWindow == nil) { + panic("node.uiWindow == nil. This should never happen") + } + return n } From f7ead697d376f73c386b771771b80e09ec58870d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 14:21:36 -0500 Subject: [PATCH 082/113] REFACTOR: refactor everything to gui.Node struct Signed-off-by: Jeff Carr --- .gitignore | 3 +- area.go | 10 +- box.go | 110 +++++++- button.go | 56 ++++ cmds/gui-demo/Makefile | 5 + cmds/gui-demo/demo-window.go | 33 +++ cmds/gui-demo/main.go | 68 +++++ {gui-example => cmds/gui-example}/Makefile | 0 cmds/gui-example/demo-window.go | 105 +++++++ cmds/gui-example/main.go | 68 +++++ cmds/gui-example/os.go | 99 +++++++ window-debug.go => debug-window.go | 193 ++++++++++--- debug.go | 66 ++++- ...w-template.go => demo-window-andlabs-ui.go | 14 +- demo-window.go | 28 ++ doc.go | 72 +++++ entry.go | 40 ++- example_test.go | 45 +++ find.go | 156 +++++++++++ gui-example/main.go | 43 --- gui.go | 8 + main.go | 28 +- new-structs.go | 249 ++++++++++++++++- structs.go | 173 +++++------- table.go | 12 +- tableCallbacks.go | 3 +- window.go | 260 ++++++++---------- 27 files changed, 1543 insertions(+), 404 deletions(-) create mode 100644 cmds/gui-demo/Makefile create mode 100644 cmds/gui-demo/demo-window.go create mode 100644 cmds/gui-demo/main.go rename {gui-example => cmds/gui-example}/Makefile (100%) create mode 100644 cmds/gui-example/demo-window.go create mode 100644 cmds/gui-example/main.go create mode 100644 cmds/gui-example/os.go rename window-debug.go => debug-window.go (53%) rename window-template.go => demo-window-andlabs-ui.go (80%) create mode 100644 demo-window.go create mode 100644 doc.go create mode 100644 example_test.go create mode 100644 find.go delete mode 100644 gui-example/main.go diff --git a/.gitignore b/.gitignore index bb1e72d..1445c95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.swp -gui-example/gui-example +cmds/gui-example/gui-example +cmds/gui-demo/gui-demo diff --git a/area.go b/area.go index 0cc7531..7c42c6c 100644 --- a/area.go +++ b/area.go @@ -107,10 +107,10 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButton), name string) { +func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") - gw := box.Window + gw := b.Window if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") return @@ -127,10 +127,10 @@ func ShowTextBox(box *GuiBox, newText *ui.AttributedString, custom func(*GuiButt */ // TODO: allow padded & axis here - box.UiBox.SetPadded(true) + b.UiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - makeGenericArea(box, newText, custom) - box.UiBox.Append(box.Window.Area.UiArea, true) + makeGenericArea(b, newText, custom) + b.UiBox.Append(b.Window.Area.UiArea, true) } diff --git a/box.go b/box.go index 2640742..7a61f55 100644 --- a/box.go +++ b/box.go @@ -1,6 +1,7 @@ package gui import "log" +import "os" // import "reflect" import "github.com/andlabs/ui" @@ -34,6 +35,7 @@ func add(box *GuiBox, newbox *GuiBox) { newbox.Window.BoxMap["MAINBOX"] = newbox log.Println("gui.add() END") + panic("gui.add() MAINBOX gui.add() END") return } else { log.Println("\tgui.add() ERROR DONT KNOW HOW TO ADD TO A RAW WINDOW YET") @@ -41,33 +43,77 @@ func add(box *GuiBox, newbox *GuiBox) { } log.Println("\tgui.add() ERROR DON'T KNOW HOW TO add to Window as MAINBOX DONE") log.Println("gui.add() END") + panic("gui.add() gui.add() END") return } log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) // copy the box settings over newbox.Window = box.Window - if (box.UiBox == nil) { - log.Println("\tgui.add() ERROR box.UiBox == nil") - panic("crap") + if (box.node == nil) { + box.Dump() + panic("gui.add() ERROR box.node == nil") } + if (newbox.UiBox == nil) { - log.Println("\tgui.add() ERROR newbox.UiBox == nil") - panic("crap") + panic("gui.add() ERROR newbox.UiBox == nil") + } + + if (box.UiBox == nil) { + box.Dump() + // panic("gui.add() ERROR box.UiBox == nil") + return + // TODO: fix this whole add() function // Oct 9 } - // log.Println("\tgui.add() newbox.UiBox == ", newbox.UiBox.GetParent()) - // spew.Dump(newbox.UiBox) box.UiBox.Append(newbox.UiBox, false) + box.Dump() + panic("gui.add()") // add the newbox to the Window.BoxMap[] box.Window.BoxMap[newbox.Name] = newbox log.Println("gui.add() END") } -func NewBox(box *GuiBox, axis int, name string) *GuiBox { - log.Println("VerticalBox START") +func (n *Node) AddBox(axis int, name string) *Node { + newBox := new(GuiBox) + newBox.Window = n.window + newBox.Name = name + + if (n.box == nil) { + n.box = newBox + } + + // make a new box & a new node + newNode := n.makeNode(name, 111, 100 + Config.counter) + newNode.box = newBox + Config.counter += 1 + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newBox.UiBox = uiBox + newNode.uiBox = uiBox + + n.Append(newNode) + // add(n.box, newBox) + return newNode +} + +func (b *GuiBox) NewBox(axis int, name string) *GuiBox { + log.Println("gui.NewBox() START") + n := b.FindNode() + if (n == nil) { + log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") + os.Exit(0) + } else { + log.Println("gui.NewBox() node =", n.Name) + } var newbox *GuiBox newbox = new(GuiBox) - newbox.Window = box.Window + newbox.Window = b.Window newbox.Name = name var uiBox *ui.Box @@ -78,13 +124,18 @@ func NewBox(box *GuiBox, axis int, name string) *GuiBox { } uiBox.SetPadded(true) newbox.UiBox = uiBox - add(box, newbox) + add(b, newbox) + // panic("gui.NewBox") return newbox } func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { log.Println("HardBox() START axis =", axis) + if (gw.node == nil) { + gw.Dump() + panic("gui.HardBox() gw.node == nil") + } // add a Vertical Seperator if there is already a box // Is this right? box := gw.BoxMap["MAINBOX"] @@ -134,3 +185,40 @@ func VerticalBreak(box *GuiBox) { tmp := ui.NewVerticalSeparator() box.UiBox.Append(tmp, false) } + +func (n *Node) AddComboBox(title string, s ...string) *Node { + box := n.uiBox + if (box == nil) { + return n + } + + ecbox := ui.NewEditableCombobox() + + for id, name := range s { + log.Println("Adding Combobox Entry:", id, name) + ecbox.Append(name) + } + + ecbox.OnChanged(func(*ui.EditableCombobox) { + test := ecbox.Text() + log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") + }) + + box.Append(ecbox, false) + + newNode := n.AddNode(title) + newNode.uiText = ecbox + return newNode +} + +func (n *Node) OnChanged(f func()) { + f() +} + +func (n *Node) GetText() string { + if (n.uiText == nil) { + return "" + } + ecbox := n.uiText + return ecbox.Text() +} diff --git a/button.go b/button.go index 825b79b..8ad0a3b 100644 --- a/button.go +++ b/button.go @@ -1,10 +1,12 @@ package gui import "log" +import "reflect" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" + // This is the default mouse click handler // Every mouse click that hasn't been assigned to // something specific will fall into this routine @@ -50,6 +52,60 @@ func guiButtonClick(button *GuiButton) { } } +func (n *Node) AddButton(name string, custom func(*Node)) *Node { + if (n.uiBox == nil) { + log.Println("gui.Node.AppendButton() filed node.UiBox == nil") + return n + } + button := ui.NewButton(name) + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + n.uiBox.Append(button, false) + n.uiButton = button + + newNode := n.makeNode(name, 888, 888 + Config.counter) + newNode.uiButton = button + newNode.custom = custom + + button.OnClicked(func(*ui.Button) { + log.Println("gui.AppendButton() Button Clicked. Running custom()") + custom(newNode) + }) + // panic("AppendButton") + // time.Sleep(3 * time.Second) + return newNode +} + +func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { + newNode := n.AddBox(Xaxis, "test CreateButton") + box := newNode.FindBox() + if (box == nil) { + panic("node.CreateButton().FindBox() == nil") + } + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) + + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.UiBox == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } else { + // uibox := box.UiBox + // uibox.Append(newUiB, true) + } + newB.Box = box + newB.Custom = custom + newB.Values = values + + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newNode +} + func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { newUiB := ui.NewButton(name) newUiB.OnClicked(defaultButtonClick) diff --git a/cmds/gui-demo/Makefile b/cmds/gui-demo/Makefile new file mode 100644 index 0000000..2dbc808 --- /dev/null +++ b/cmds/gui-demo/Makefile @@ -0,0 +1,5 @@ +run: build + ./gui-demo + +build: + GO111MODULE="off" go build diff --git a/cmds/gui-demo/demo-window.go b/cmds/gui-demo/demo-window.go new file mode 100644 index 0000000..fd8e8f4 --- /dev/null +++ b/cmds/gui-demo/demo-window.go @@ -0,0 +1,33 @@ +package main + +import "log" + +import "git.wit.org/wit/gui" + +func demoClick (n *gui.Node) { + log.Println("demoClick() Dumping node:") + n.Dump() +} + +func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + if (gui.Config.Debug) { + newNode.Dump() + } + newNode.ListChildren(false) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo1", "foo", "bar", "stuff") + groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") + + groupNode1.Dump() + + butNode1 := groupNode1.AddButton("button1", demoClick) + butNode1.Dump() + + butNode2 := groupNode1.AddButton("button2", demoClick) + butNode2.Dump() + + groupNode2 := newNode.AddGroup("group 2") + groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") +} diff --git a/cmds/gui-demo/main.go b/cmds/gui-demo/main.go new file mode 100644 index 0000000..8eae878 --- /dev/null +++ b/cmds/gui-demo/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "log" + "os" + "time" + + "git.wit.org/wit/gui" +) + +// This initializes the first window +// +// Then starts a goroutine to demonstrate how to +// inject things into the GUI +func main() { + log.Println("Starting my Control Panel") + + go gui.Main(initGUI) + + watchGUI() +} + +// This initializes the first window +func initGUI() { + gui.Config.Title = "WIT GUI Window Demo 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + gui.Config.Exit = myExit + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + + gui.Config.Title = "WIT GUI Window Demo 2" + gui.Config.Width = 640 + gui.Config.Height = 240 + gui.Config.Exit = myExit + node2 := gui.NewWindow() + node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") +} + +// This demonstrates how to properly interact with the GUI +// You can not involke the GUI from external goroutines in most cases. +func watchGUI() { + var i = 1 + for { + log.Println("Waiting", i, "seconds") + i += 1 + time.Sleep(1 * time.Second) + if i == 4 { + log.Println("Opening a Debug Window via the gui.Queue()") + gui.Config.Width = 800 + gui.Config.Height = 300 + gui.Config.Exit = myDebugExit + gui.Queue(gui.DebugWindow) + } + } +} + +func myExit(n *gui.Node) { + log.Println() + log.Println("Entered myExit() on node.Name =", n.Name) + log.Println() + os.Exit(0) +} + +func myDebugExit(n *gui.Node) { + log.Println("Entered myDebugExit() on node.Name =", n.Name) + log.Println("Don't actually os.Exit()") +} diff --git a/gui-example/Makefile b/cmds/gui-example/Makefile similarity index 100% rename from gui-example/Makefile rename to cmds/gui-example/Makefile diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go new file mode 100644 index 0000000..993900d --- /dev/null +++ b/cmds/gui-example/demo-window.go @@ -0,0 +1,105 @@ +package main + +import "log" +import "reflect" + +import "git.wit.org/wit/gui" + +import "github.com/davecgh/go-spew/spew" + +func demoClick (n *gui.Node) { + log.Println("demoClick() Dumping node:") + n.Dump() +} + +var username = "jcarr" +var hostname = "fire" + +func newClick (n *gui.Node) { + var tmp []string + junk := "ssh -v " + username + "@" + hostname + log.Println("junk = " , junk) + xterm(junk) + log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) + // spew.Dump(tmp) +} + +func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + if (gui.Config.Debug) { + newNode.Dump() + } + newNode.ListChildren(false) + + groupNode1 := newNode.AddGroup("group 1") + cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") + cbNode.OnChanged(func () { + username = cbNode.GetText() + }) + groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") + + groupNode1.Dump() + + butNode1 := groupNode1.AddButton("button1", demoClick) + butNode1.Dump() + + butNode2 := groupNode1.AddButton("button2", newClick) + butNode2.Dump() + + groupNode2 := newNode.AddGroup("group 2") + groupNode2.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + + gNode := newNode.AddGroup("domU") + makeSSHbutton(gNode, "hugo@www", "www.wit.org") + makeSSHbutton(gNode, "check.lab", "check.lab.wit.org") + makeSSHbutton(gNode, "gobuild.lab", "gobuild.lab.wit.org") + makeSSHbutton(gNode, "gobuild2.lab", "gobuild2.lab.wit.org") + +/////////////////////////////// Column DNS //////////////////////////////// + gNode = newNode.AddGroup("dns") + makeSSHbutton(gNode, "bind.wit.org", "bind.wit.org") + makeSSHbutton(gNode, "ns1.wit.com", "ns1.wit.com") + makeSSHbutton(gNode, "ns2.wit.com", "ns2.wit.com") + makeSSHbutton(gNode, "coredns", "coredns.lab.wit.org") + +/////////////////////////////// PHYS 530 ////////////////////////////////// + gNode = newNode.AddGroup("phys 530") + // makeXtermButton(gNode, "openwrt", "SUBDOMAIN", "ssh -4 -v root@openwrt") + gNode.AddButton("openwrt", func (*gui.Node) { + stuff := "ssh -4 -v root@openwrt" + xterm(stuff) + }) + makeSSHbutton (gNode, "mirrors", "mirrors.wit.org") + makeSSHbutton (gNode, "node004", "node004.lab.wit.org") + makeSSHbutton (gNode, "lenovo-z70", "lenovo-z70.lab.wit.org") + +/////////////////////////////// PHYS 522 ////////////////////////////////// + gNode = newNode.AddGroup("phys 522") + // makeXtermButton(gNode, "openwrt2", "SUBDOMAIN", "ssh -4 -v root@openwrt2") + gNode.AddButton("openwrt2", func (*gui.Node) { + stuff := "ssh -4 -v root@openwrt2" + xterm(stuff) + }) + makeSSHbutton (gNode, "fire.lab", "fire.lab.wit.org") + makeSSHbutton (gNode, "predator", "predator.lab.wit.org") + +/////////////////////////////// FLOAT ///////////////////////////////////// + gNode = newNode.AddGroup("float") + makeSSHbutton(gNode, "root@asus-n501vw", "asus-n501vw.lab.wit.org") +} + +func makeSSHbutton (n *gui.Node, name string, hostname string) { + bNode := n.AddButton(name, func (*gui.Node) { + var tmp []string + if (username == "") { + username = "root" + } + junk := "ssh -v " + username + "@" + hostname + log.Println("junk = " , junk) + log.Println("username = '" + username + "'") + xterm(junk) + log.Println("tmp = " , reflect.ValueOf(tmp).Kind()) + spew.Dump(tmp) + }) + bNode.Dump() +} diff --git a/cmds/gui-example/main.go b/cmds/gui-example/main.go new file mode 100644 index 0000000..8eae878 --- /dev/null +++ b/cmds/gui-example/main.go @@ -0,0 +1,68 @@ +package main + +import ( + "log" + "os" + "time" + + "git.wit.org/wit/gui" +) + +// This initializes the first window +// +// Then starts a goroutine to demonstrate how to +// inject things into the GUI +func main() { + log.Println("Starting my Control Panel") + + go gui.Main(initGUI) + + watchGUI() +} + +// This initializes the first window +func initGUI() { + gui.Config.Title = "WIT GUI Window Demo 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + gui.Config.Exit = myExit + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + + gui.Config.Title = "WIT GUI Window Demo 2" + gui.Config.Width = 640 + gui.Config.Height = 240 + gui.Config.Exit = myExit + node2 := gui.NewWindow() + node2.DemoAndlabsUiTab("A Simple andlabs/ui Tab Demo") +} + +// This demonstrates how to properly interact with the GUI +// You can not involke the GUI from external goroutines in most cases. +func watchGUI() { + var i = 1 + for { + log.Println("Waiting", i, "seconds") + i += 1 + time.Sleep(1 * time.Second) + if i == 4 { + log.Println("Opening a Debug Window via the gui.Queue()") + gui.Config.Width = 800 + gui.Config.Height = 300 + gui.Config.Exit = myDebugExit + gui.Queue(gui.DebugWindow) + } + } +} + +func myExit(n *gui.Node) { + log.Println() + log.Println("Entered myExit() on node.Name =", n.Name) + log.Println() + os.Exit(0) +} + +func myDebugExit(n *gui.Node) { + log.Println("Entered myDebugExit() on node.Name =", n.Name) + log.Println("Don't actually os.Exit()") +} diff --git a/cmds/gui-example/os.go b/cmds/gui-example/os.go new file mode 100644 index 0000000..ce5db8d --- /dev/null +++ b/cmds/gui-example/os.go @@ -0,0 +1,99 @@ +package main + +import "log" +import "strings" +import "os" +import "os/exec" +import "io/ioutil" +import "errors" +// import "bufio" + +// import "github.com/davecgh/go-spew/spew" + +/* +import "time" +import "runtime" +import "runtime/debug" +import "runtime/pprof" + +import "git.wit.org/wit/gui" +import "git.wit.org/wit/shell" +import "github.com/gobuffalo/packr" +*/ + +func runSimpleCommand(s string) { + cmd := strings.TrimSpace(s) // this is like 'chomp' in perl + cmd = strings.TrimSuffix(cmd, "\n") // this is like 'chomp' in perl + cmdArgs := strings.Fields(cmd) + runLinuxCommand(cmdArgs) +} + +var geom string = "120x30+500+500" + +func xterm(cmd string) { + var tmp []string + var argsXterm = []string{"nohup", "xterm", "-geometry", geom} + tmp = append(argsXterm, "-hold", "-e", cmd) + log.Println("xterm cmd=", cmd) + go runCommand(tmp) +} + +func runCommand(cmdArgs []string) { + log.Println("runCommand() START", cmdArgs) + process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + // process := exec.Command("xterm", "-e", "ping localhost") + log.Println("runCommand() process.Start()") + process.Start() + log.Println("runCommand() process.Wait()") + err := process.Wait() + lookupError(err) + log.Println("runCommand() NEED TO CHECK THE TIME HERE TO SEE IF THIS WORKED") + log.Println("runCommand() OTHERWISE INFORM THE USER") + log.Println("runCommand() END", cmdArgs) +} + +func lookupError(err error) { + var ( + ee *exec.ExitError + pe *os.PathError + ) + + if errors.As(err, &ee) { + log.Println("ran, but non-zero exit code =", ee.ExitCode()) // ran, but non-zero exit code + } else if errors.As(err, &pe) { + log.Printf("os.PathError = %v", pe) // "no such file ...", "permission denied" etc. + } else if err != nil { + log.Printf("something really bad happened general err = %v", err) // something really bad happened! + if exitError, ok := err.(*exec.ExitError); ok { + log.Printf("exitError.ExitCode() is %d\n", exitError.ExitCode()) + } + } else { + log.Println("success! // ran without error (exit code zero)") + } +} + +func runLinuxCommand(cmdArgs []string) (string, error) { + process := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...) + + process.Stdin = os.Stdin + process.Stderr = os.Stderr + + stdOut, err := process.StdoutPipe() + if err != nil { + return "", err + } + + if err := process.Start(); err != nil { + return "", err + } + + bytes, err := ioutil.ReadAll(stdOut) + if err != nil { + return "", err + } + err = process.Wait() + lookupError(err) + + log.Println(string(bytes)) + return string(bytes), err +} diff --git a/window-debug.go b/debug-window.go similarity index 53% rename from window-debug.go rename to debug-window.go index 704ef7b..19f276d 100644 --- a/window-debug.go +++ b/debug-window.go @@ -2,6 +2,8 @@ package gui import ( "log" + // "fmt" + "strconv" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" @@ -9,22 +11,36 @@ import ( ) var names = make([]string, 100) +var nodeNames = make([]string, 100) -func makeWindowDebug() ui.Control { +func DebugWindow() { + Config.Title = "DebugWindow()" + node := NewWindow() + node.DebugTab("WIT GUI Debug Tab") +} + +// TODO: remove this crap +// What does this actually do? +// It populates the nodeNames in a map. No, not a map, an array. +// What is the difference again? (other than one being in order and a predefined length) +func addNodeName(c *ui.Combobox, s string, id string) { + c.Append(s) + nodeNames[y] = id + y = y + 1 +} + +func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "Numbers") - pbar := ui.NewProgressBar() - vbox.Append(pbar, false) - - ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Window") + vbox := addGroup(hbox, "range Data.WindowMap") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap { - log.Println("range Data.WindowMap() name =", name) + if (Config.Debug) { + log.Println("range Data.WindowMap() name =", name) + } addName(cbox, name) } cbox.SetSelected(0) @@ -122,6 +138,11 @@ func makeWindowDebug() ui.Control { ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Global Debug") + dump3 := addButton(vbox, "Dump Windows") + dump3.OnClicked(func(*ui.Button) { + DumpWindows() + }) + dump2 := addButton(vbox, "Dump Boxes") dump2.OnClicked(func(*ui.Button) { DumpBoxes() @@ -132,11 +153,112 @@ func makeWindowDebug() ui.Control { DumpMap() }) + ///////////////////////////////////////////////////// + nodeBox := addGroup(hbox, "Windows:") + nodeCombo := ui.NewCombobox() + + for name, node := range Data.NodeMap { + if (Config.Debug) { + log.Println("range Data.NodeMap() name =", name) + } + tmp := node.id + " (" + name + ")" + addNodeName(nodeCombo, tmp, node.id) + } + nodeCombo.SetSelected(0) + + nodeBox.Append(nodeCombo, false) + + nodeCombo.OnSelected(func(*ui.Combobox) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.Dump() + } + }) + + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Node Debug") + + n1 := addButton(vbox, "Data.DumpNodeMap()") + n1.OnClicked(func(*ui.Button) { + Data.DumpNodeMap() + }) + + n1 = addButton(vbox, "Data.ListChildren(false)") + n1.OnClicked(func(*ui.Button) { + Data.ListChildren(false) + }) + + n1 = addButton(vbox, "Data.ListChildren(true)") + n1.OnClicked(func(*ui.Button) { + Data.ListChildren(true) + }) + + n1 = addButton(vbox, "Node.Dump()") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.Dump() + } + }) + + n1 = addButton(vbox, "Node.ListChildren(false)") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.ListChildren(false) + } + }) + + n1 = addButton(vbox, "Node.ListChildren(true)") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.ListChildren(true) + } + }) + + n1 = addButton(vbox, "Node.AddDebugTab") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.DebugTab("added this DebugTab") + } + }) + + n1 = addButton(vbox, "Node.DemoAndlabsUiTab") + n1.OnClicked(func(*ui.Button) { + y := nodeCombo.Selected() + log.Println("y =", y) + log.Println("nodeNames[y] =", nodeNames[y]) + node := Data.findId(nodeNames[y]) + if (node != nil) { + node.DemoAndlabsUiTab("ran gui.AddDemoAndlabsUiTab() " + strconv.Itoa(Config.counter)) + } + }) + return hbox } +// TODO: remove this crap var x int = 0 +var y int = 0 +// TODO: remove this crap func addName(c *ui.Combobox, s string) { c.Append(s) names[x] = s @@ -155,33 +277,11 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } -func FindWindow(s string) *GuiWindow { - for name, window := range Data.WindowMap { - if name == s { - return window - } - } - log.Printf("COULD NOT FIND WINDOW", s) - return nil -} - -func FindBox(s string) *GuiBox { - for name, window := range Data.WindowMap { - if name != s { - continue - } - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - return abox - } - log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) - } - log.Println("gui.FindBox() COULD NOT FIND BOX", s) - return nil -} - func dumpBox(s string) { - for name, window := range Data.WindowMap { + var name string + var window *GuiWindow + + for name, window = range Data.WindowMap { if name != s { continue } @@ -198,6 +298,7 @@ func dumpBox(s string) { log.Println("gui.dumpBox() BoxMap START") for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + abox.Dump() if name == "MAINBOX" { if Config.Debug { scs := spew.ConfigState{MaxDepth: 1} @@ -228,3 +329,27 @@ func addButton(box *ui.Box, name string) *ui.Button { box.Append(button, false) return button } + +func (n *Node) DebugTab(title string) { + newNode := n.AddTab(title, makeWindowDebug()) + if (Config.DebugNode) { + newNode.Dump() + } + tabSetMargined(newNode.uiTab) +} + +// This sets _all_ the tabs to Margin = true +// +// TODO: do proper tab tracking (will be complicated). low priority +func tabSetMargined(tab *ui.Tab) { + if (Config.DebugTabs) { + log.Println("tabSetMargined() IGNORE THIS") + } + c := tab.NumPages() + for i := 0; i < c; i++ { + if (Config.DebugTabs) { + log.Println("tabSetMargined() i =", i) + } + tab.SetMargined(i, true) + } +} diff --git a/debug.go b/debug.go index 8c1e947..0b0baa4 100644 --- a/debug.go +++ b/debug.go @@ -8,14 +8,13 @@ import ( "github.com/davecgh/go-spew/spew" ) -// import "reflect" - -// import "github.com/andlabs/ui" -// import _ "github.com/andlabs/ui/winmanifest" - -// -// Dump out debugging information every 4 seconds +// WatchGUI() opens a goroutine // +// From that goroutine, it dumps out debugging information every 4 seconds +/* + TODO: add configuration triggers on what to dump out + TODO: allow this to be sent to /var/log, syslogd, systemd's journalctl, etc +*/ func WatchGUI() { count := 0 @@ -32,6 +31,12 @@ func WatchGUI() { } } +func DumpWindows() { + for name, _ := range Data.WindowMap { + log.Println("gui.DumpWindows() window =", name) + } +} + func DumpMap() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) @@ -106,3 +111,50 @@ func addTableTab() { log.Println("Sleep for 1 second, then try to add new tabs") time.Sleep(1 * time.Second) } + +func (dn *GuiData) DumpNodeMap() { + log.Println("DebugDataNodeMap():") + for name, node := range dn.NodeMap { + log.Println("\tNode =", node.id, node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + } else { + log.Println("\t\tHas children:", node.children) + } + // node.SetName("yahoo") + // log.Println("\tData.NodeMap node =", node) + } +} + +/* +func DebugDataNodeChildren() { + if Data.NodeMap == nil { + log.Println("DebugDataNodeChildren() NodeMap == nil") + return + } + log.Println("DebugDataNodeChildren():") + for name, node := range Data.NodeMap { + log.Println("\tNode name =", node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + break + } + log.Println("\t\tHas children:", node.children) + } +} +*/ + +func (dn *GuiData) ListChildren(dump bool) { + if Data.NodeMap == nil { + log.Println("gui.Data.ListChildren() Data.NodeMap == nil") + return + } + log.Println("gui.Data.ListChildren() Data.NodeMap:") + for name, node := range Data.NodeMap { + log.Println("\tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) + if (dump == true) { + node.Dump() + } + node.ListChildren(dump) + } +} diff --git a/window-template.go b/demo-window-andlabs-ui.go similarity index 80% rename from window-template.go rename to demo-window-andlabs-ui.go index c3e30ef..e11ffe9 100644 --- a/window-template.go +++ b/demo-window-andlabs-ui.go @@ -4,7 +4,19 @@ import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -func makeWindowTemplate() ui.Control { +// This will create a tab in a window using direct +// calls to andlabs/ui. This can be used to bypass +// the obvuscation added in this package if it is desired +// or needed. +func (n *Node) DemoAndlabsUiTab(title string) { + newNode := n.AddTab(title, makeAndlabsUiTab()) + if (Config.DebugNode) { + newNode.Dump() + } + tabSetMargined(newNode.uiTab) +} + +func makeAndlabsUiTab() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) diff --git a/demo-window.go b/demo-window.go new file mode 100644 index 0000000..16566c4 --- /dev/null +++ b/demo-window.go @@ -0,0 +1,28 @@ +package gui + +// import "log" +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +var mybox *ui.Box + +func (n *Node) AddGroup(title string) *Node { + if (n == nil) { + return nil + } + hbox := n.uiBox + if (hbox == nil) { + return n + } + group := ui.NewGroup(title) + group.SetMargined(true) + hbox.Append(group, true) + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + group.SetChild(vbox) + + newNode := n.AddNode(title) + newNode.uiBox = vbox + return newNode +} diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..2b324c9 --- /dev/null +++ b/doc.go @@ -0,0 +1,72 @@ +/* +Package wit/gui implements a abstraction layer for Go visual elements in +a cross platform way. Right now, this abstraction is built on top of +the GUI toolkit 'andlabs/ui' which does the cross platform support. + +A quick overview of the features, some general design guidelines +and principles for how this package should generally work: + + * GUI elements are stored in a tree of nodes + * When in doubt, it's ok to guess. We will return something close. + * It tries to make your code simple + +Quick Start + +This section demonstrates how to quickly get started with spew. See the +sections below for further details on formatting and configuration options. + +To dump a variable with full newlines, indentation, type, and pointer +information use Dump, Fdump, or Sdump: + + package main + + import ( + "git.wit.org/wit/gui" + ) + + func main() { + gui.Main(initGUI) + } + + // This initializes the first window + func initGUI() { + gui.Config.Title = "WIT GUI Window 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + } + + func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") + } + +Configuration Options + +Configuration of the GUI is handled by fields in the ConfigType type. For +convenience, all of the top-level functions use a global state available +via the gui.Config global. + +The following configuration options are available: + * Width + When creating a new window, this is the width + + * Height + When creating a new window, this is the height + + * Debug + When 'true' log more output + +GUI Usage + +Errors + +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. +*/ +package gui diff --git a/entry.go b/entry.go index d7f31c9..c10b7d0 100644 --- a/entry.go +++ b/entry.go @@ -13,26 +13,46 @@ func NewLabel(box *GuiBox, text string) { box.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) { +func (n *Node) NewLabel(text string) *Node { + // make new node here + // n.Append(ui.NewLabel(text), false) + newNode := makeNode(n, text, 333, 334) + newNode.Dump() + // panic("node.NewLabel()") + + n.Append(newNode) + return newNode +} + +func (b *GuiBox) GetText(name string) string { + if (b.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) { + spew.Dump(b.Window.EntryMap) + if (b.Window.EntryMap[name] == nil) { log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") return "" } - e := box.Window.EntryMap[name] + e := b.Window.EntryMap[name] log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) log.Println("gui.GetText() END") return e.UiEntry.Text() } +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 + } + return nil +} + func SetText(box *GuiBox, name string, value string) error { if (box == nil) { return fmt.Errorf("gui.SetText() ERROR box == nil") @@ -42,7 +62,7 @@ func SetText(box *GuiBox, name string, value string) error { } spew.Dump(box.Window.EntryMap) if (box.Window.EntryMap[name] == nil) { - return fmt.Errorf("gui.SetText() ERROR 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()) diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..f65cad1 --- /dev/null +++ b/example_test.go @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013-2016 Dave Collins + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +package gui_test + +import ( + "git.wit.org/wit/gui" +) + +// This example demonstrates how to create a NewWindow() +// +// Interacting with a GUI in a cross platform fashion adds some +// unusual problems. To obvuscate those, andlabs/ui starts a +// goroutine that interacts with the native gui toolkits +// on the Linux, MacOS, Windows, etc. +// +// Because of this oddity, to initialize a new window, the +// function is not passed any arguements and instead passes +// the information via the Config type. +// +func ExampleNewWindow() { + // Define the name and size + gui.Config.Title = "WIT GUI Window 1" + gui.Config.Width = 640 + gui.Config.Height = 480 + + // Create the Window + gui.NewWindow() + + // Output: + // You get a window +} diff --git a/find.go b/find.go new file mode 100644 index 0000000..e046161 --- /dev/null +++ b/find.go @@ -0,0 +1,156 @@ +package gui + +import ( + "log" + "os" + + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" +// "github.com/davecgh/go-spew/spew" +) + +func (n *Node) FindTab() *ui.Tab { + return n.uiTab +} + +func (n *Node) FindControl() *ui.Control { + return n.uiControl +} + +func (n *Node) FindBox() *GuiBox { + if (n.box != nil) { + return n.box + } + if (n.parent != nil) { + p := n.parent + return p.box + } + return n.box +} + +func (n *Node) FindWindowBox() *GuiBox { + if (n.box == nil) { + panic("SERIOUS ERROR n.box == nil in FindWindowBox()") + } + return n.box +} + +func (w *GuiWindow) FindNode() *Node { + return w.node +} + +func (b *GuiBox) FindNode() *Node { + log.Println("gui.FindNode() on GuiBox") + if b.node != nil { + return b.node + } + Data.ListChildren(true) + b.Dump() + log.Println("gui.FindNode() on GuiBox is nil") + os.Exit(-1) + return nil +} + +func FindWindow(s string) *GuiWindow { + for name, window := range Data.WindowMap { + if name == s { + return window + } + } + log.Printf("COULD NOT FIND WINDOW " + s) + return nil +} + +func FindBox(s string) *GuiBox { + for name, window := range Data.WindowMap { + if name != s { + continue + } + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + return abox + } + log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) + } + log.Println("gui.FindBox() COULD NOT FIND BOX", s) + return nil +} + +func FindNode(name string) *Node { + if Data.NodeMap == nil { + log.Println("gui.FindNode() gui.Data.NodeMap == nil") + return nil + } + log.Println("gui.FindNode() searching Data.NodeMap:") + for id, node := range Data.NodeMap { + log.Println("\tData.NodeMap name =", node.Width, node.Height, id) + node.Dump() + if (name == node.Name) { + return node + } + newNode := findByName(node, name) + if (newNode != nil) { + return newNode + } + log.Println("gui.FindNode() could not find node name =", name) + os.Exit(-1) + } + log.Println("gui.FindNode() could not find node name =", name) + return nil +} + +func (dn *GuiData) findId(id string) *Node { + if Data.NodeMap == nil { + log.Println("gui.Data.findId() map == nil") + return nil + } + // log.Println("Dumping Data.NodeMap:") + for name, node := range Data.NodeMap { + // log.Println("\tData.NodeMap name =", node.id, node.Width, node.Height, name) + if (id == node.id) { + log.Println("\tgui.Data.findId() found node =", node.id, node.Width, node.Height, name) + return node + } + // TODO: fix // Oct 9 + // node.findId(id) + } + return nil +} + +func findByIdDFS(node *Node, id string) *Node { + log.Println("findByIdDFS()", id, node) + node.Dump() + if node.id == id { + log.Println("Found node id =", id, node) + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + newNode := findByIdDFS(child, id) + if (newNode != nil) { + return newNode + } + } + } + return nil +} + +func findByName(node *Node, name string) *Node { + log.Println("findByName()", name, node) + node.Dump() + if node.Name == name { + log.Println("findByName() Found node name =", name, node) + return node + } + + if len(node.children) > 0 { + for _, child := range node.children { + newNode := findByName(child, name) + if (newNode != nil) { + return newNode + } + } + } + return nil +} diff --git a/gui-example/main.go b/gui-example/main.go deleted file mode 100644 index 1ff286d..0000000 --- a/gui-example/main.go +++ /dev/null @@ -1,43 +0,0 @@ -package main - -import ( - "log" - "os" - "time" - - "git.wit.org/wit/gui" -) - -func customExit(gw *gui.GuiWindow) { - log.Println("Should Exit Here") - os.Exit(0) -} - -func main() { - log.Println("starting my Control Panel") - - gui.Config.Width = 800 - gui.Config.Height = 300 - gui.Config.Exit = customExit - - go gui.Main(initGUI) - - watchGUI() -} - -func initGUI() { - gui.NewWindow("jcarr start", 640, 480) -} - -func watchGUI() { - var i = 1 - for { - log.Println("Waiting for customExit()", i) - i += 1 - time.Sleep(time.Second) - if i == 3 { - log.Println("Sending ExampleWindow to gui.Queue()") - gui.Queue(gui.DebugWindow) - } - } -} diff --git a/gui.go b/gui.go index 97e3c24..4174133 100644 --- a/gui.go +++ b/gui.go @@ -18,6 +18,14 @@ func init() { Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.WindowMap = make(map[string]*GuiWindow) + Data.NodeMap = make(map[string]*Node) + + Data.NodeSlice = make([]*Node, 0) + + Config.counter = 0 + Config.prefix = "wit" + Config.DebugNode = false + Config.DebugTabs = false } func GuiInit() { diff --git a/main.go b/main.go index 09d105f..70e0e65 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ func Main(f func()) { ui.Main(f) } -// Other goroutines must use this +// Other goroutines must use this to access the GUI // // You can not acess / process the GUI thread directly from // other goroutines. This is due to the nature of how @@ -23,28 +23,12 @@ func Queue(f func()) { ui.QueueMain(f) } +/* func ExampleWindow() { log.Println("START gui.ExampleWindow()") - title := "Test Window" - box := InitWindow(nil, title, 0) - window := box.Window - log.Println("box =", box) - log.Println("window =", window) - box.AddDebugTab("jcarr Debug") - - window.UiWindow.Show() -} - -func DebugWindow() { - log.Println("START gui.ExampleWindow()") - - title := "Debug Window" - box := InitWindow(nil, title, 0) - window := box.Window - log.Println("box =", box) - log.Println("window =", window) - box.AddDebugTab("jcarr Debug") - - window.UiWindow.Show() + Config.Title = "ExampleWindow" + node := NewWindow() + node.AddDebugTab("jcarr Debug") } +*/ diff --git a/new-structs.go b/new-structs.go index 0fa326a..4f9989e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -2,12 +2,42 @@ package gui import ( "log" + "fmt" +// "reflect" + + // "github.com/davecgh/go-spew/spew" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" ) +type Element int + // https://ieftimov.com/post/golang-datastructures-trees/ +const ( + Unknown Element = iota + Window + Tab + Box + Label + Combo +) + +func (s Element) String() string { + switch s { + case Window: + return "window" + case Tab: + return "tab" + case Box: + return "box" + case Label: + return "label" + case Combo: + return "combo" + } + return "unknown" +} type Node struct { id string @@ -15,32 +45,227 @@ type Node struct { Width int Height int - uiType *ui.Control + parent *Node children []*Node + + window *GuiWindow + box *GuiBox + custom func(*Node) + + uiControl *ui.Control + uiButton *ui.Button + uiWindow *ui.Window + uiTab *ui.Tab + uiBox *ui.Box + uiText *ui.EditableCombobox } -func (n Node) SetName(name string) { +func (n *Node) Parent() *Node { + return n.parent +} + +func (n *Node) Window() *Node { + return n.parent +} + +func (n *Node) Dump() { + log.Println("gui.Node.Dump() id = ", n.id) + log.Println("gui.Node.Dump() Name = ", n.Name) + log.Println("gui.Node.Dump() Width = ", n.Width) + log.Println("gui.Node.Dump() Height = ", n.Height) + + if (n.parent == nil) { + log.Println("gui.Node.Dump() parent = nil") + } else { + log.Println("gui.Node.Dump() parent = ", n.parent.id) + } + log.Println("gui.Node.Dump() children = ", n.children) + + log.Println("gui.Node.Dump() window = ", n.window) + log.Println("gui.Node.Dump() box = ", n.box) + + log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) + log.Println("gui.Node.Dump() uiTab = ", n.uiTab) + log.Println("gui.Node.Dump() uiBox = ", n.uiBox) + log.Println("gui.Node.Dump() uiControl = ", n.uiControl) + log.Println("gui.Node.Dump() uiButton = ", n.uiButton) + if (n.id == "") { + panic("gui.Node.Dump() id == nil") + } +} + + +func (n *Node) SetBox(box *GuiBox) { + n.box = box +} + +func (n *Node) SetName(name string) { // n.uiType.SetName(name) - log.Println("n.uiType =", n.uiType) + if (n.uiWindow != nil) { + log.Println("node is a window. setting title =", name) + n.uiWindow.SetTitle(name) + return + } + log.Println("*ui.Control =", n.uiControl) return } -func (n Node) Append(child Node) { +func (n *Node) Append(child *Node) { // if (n.UiBox == nil) { // return // } - // n.uiType.Append(child, x) + n.children = append(n.children, child) + if (Config.Debug) { + log.Println("child node:") + child.Dump() + log.Println("parent node:") + n.Dump() + } + // time.Sleep(3 * time.Second) } -func findByIdDFS(node *Node, id string) *Node { - if node.id == id { - return node +func (n *Node) List() { + findByIdDFS(n, "test") +} + +var listChildrenParent *Node +var listChildrenDepth int = 0 + +func indentPrintln(depth int, format string, a ...interface{}) { + var tabs string + for i := 0; i < depth; i++ { + tabs = tabs + "\t" } - if len(node.children) > 0 { - for _, child := range node.children { - findByIdDFS(child, id) + // newFormat := tabs + strconv.Itoa(depth) + " " + format + newFormat := tabs + format + log.Println(newFormat, a) +} + +func (n *Node) ListChildren(dump bool) { + indentPrintln(listChildrenDepth, "\t", n.id, n.Width, n.Height, n.Name) + + if (dump == true) { + n.Dump() + } + if len(n.children) == 0 { + if (n.parent == nil) { + } else { + if (Config.DebugNode) { + log.Println("\t\t\tparent =",n.parent.id) + } + if (listChildrenParent != nil) { + if (Config.DebugNode) { + log.Println("\t\t\tlistChildrenParent =",listChildrenParent.id) + } + if (listChildrenParent.id != n.parent.id) { + log.Println("parent.child does not match child.parent") + panic("parent.child does not match child.parent") + } + } } + if (Config.DebugNode) { + log.Println("\t\t", n.id, "has no children") + } + return } - return nil + for _, child := range n.children { + // log.Println("\t\t", child.id, child.Width, child.Height, child.Name) + if (child.parent != nil) { + if (Config.DebugNode) { + log.Println("\t\t\tparent =",child.parent.id) + } + } else { + log.Println("\t\t\tno parent") + panic("no parent") + } + if (dump == true) { + child.Dump() + } + if (Config.DebugNode) { + if (child.children == nil) { + log.Println("\t\t", child.id, "has no children") + } else { + log.Println("\t\t\tHas children:", child.children) + } + } + listChildrenParent = n + listChildrenDepth += 1 + child.ListChildren(dump) + listChildrenDepth -= 1 + } + return +} + +// The parent Node needs to be the raw Window +// The 'stuff' Node needs to be the contents of the tab +// +// This function should make a new node with the parent and +// the 'stuff' Node as a child +func (n *Node) AddTabNode(title string, b *GuiBox) *Node { + var newNode *Node + parent := n + + newNode = parent.makeNode(title, 444, 400 + Config.counter) + newNode.uiTab = parent.uiTab + newNode.box = b + + if (Config.DebugNode) { + fmt.Println("") + log.Println("parent:") + parent.Dump() + + fmt.Println("") + log.Println("newNode:") + newNode.Dump() + } + + if (newNode.uiTab == nil) { + log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") + // TODO: try to find the tab or window and make them if need be + return newNode + } + newNode.uiTab.Append(title, b.UiBox) + + return newNode +} + +func (n *Node) AddTab(title string, uiC *ui.Box) *Node { + parent := n + log.Println("gui.Node.AddTab() START name =", title) + if parent.uiWindow == nil { + parent.Dump() + log.Println("gui.Node.AddTab() ERROR ui.Window == nil") + return nil + } + if parent.box == nil { + parent.Dump() + panic("gui.AddTab() ERROR box == nil") + } + if parent.uiTab == nil { + inittab := ui.NewTab() // no, not that 'inittab' + parent.uiWindow.SetChild(inittab) + parent.uiWindow.SetMargined(true) + parent.uiTab = inittab + + // parent.Dump() + // panic("gui.AddTab() ERROR uiTab == nil") + } + + tab := parent.uiTab + parent.uiWindow.SetMargined(true) + + if (uiC == nil) { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + uiC = hbox + } + tab.Append(title, uiC) + + newNode := parent.makeNode(title, 555, 600 + Config.counter) + newNode.uiTab = tab + newNode.uiBox = uiC + // panic("gui.AddTab() after makeNode()") + tabSetMargined(newNode.uiTab) + return newNode } diff --git a/structs.go b/structs.go index ad3307b..c15f4b7 100644 --- a/structs.go +++ b/structs.go @@ -19,11 +19,20 @@ var Data GuiData var Config GuiConfig type GuiConfig struct { + Title string Width int Height int - Debug bool - DebugTable bool - Exit func(*GuiWindow) + Exit func(*Node) + + Debug bool + DebugNode bool + DebugTabs bool + DebugTable bool + DebugWindow bool + + depth int + counter int // used to make unique ID's + prefix string } type GuiData struct { @@ -35,7 +44,10 @@ type GuiData struct { AllEntries []*GuiEntry WindowMap map[string]*GuiWindow - // Windows []*GuiWindow + // Store access to everything via binary tree's + NodeMap map[string]*Node + NodeArray []*Node + NodeSlice []*Node // A map of all buttons everywhere on all // windows, all tabs, across all goroutines @@ -45,7 +57,6 @@ type GuiData struct { // andlabs/ui & andlabs/libui work AllButtons []*GuiButton buttonMap map[*ui.Button]*GuiButton - Nodes *Node } type GuiTab struct { @@ -87,11 +98,20 @@ type GuiWindow struct { EntryMap map[string]*GuiEntry Area *GuiArea + node *Node + // andlabs/ui abstraction mapping UiWindow *ui.Window UiTab *ui.Tab // if this != nil, the window is 'tabbed' } +func (w *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", w.Name) + log.Println("gui.GuiWindow.Dump() node = ", w.node) + log.Println("gui.GuiWindow.Dump() Width = ", w.Width) + log.Println("gui.GuiWindow.Dump() Height = ", w.Height) +} + // GuiBox is any type of ui.Hbox or ui.Vbox // There can be lots of these for each GuiWindow type GuiBox struct { @@ -99,121 +119,62 @@ type GuiBox struct { Axis int // does it add items to the X or Y axis Window *GuiWindow // the parent Window + node *Node + // andlabs/ui abstraction mapping UiBox *ui.Box } -func (s GuiBox) SetTitle(title string) { +func (b *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", b.Name) + log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) + log.Println("gui.GuiBox.Dump() node = ", b.node) + log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) +} + +func (b *GuiBox) SetTitle(title string) { log.Println("DID IT!", title) - if s.Window == nil { + if b.Window == nil { return } - if s.Window.UiWindow == nil { + if b.Window.UiWindow == nil { return } - s.Window.UiWindow.SetTitle(title) + b.Window.UiWindow.SetTitle(title) return } -func (s GuiBox) Append(child ui.Control, x bool) { - if s.UiBox == nil { +func (w *GuiWindow) SetNode(n *Node) { + if (w.node != nil) { + w.Dump() + panic("gui.SetNode() Error not nil") + } + w.node = n + if (w.node == nil) { + w.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) SetNode(n *Node) { + if (b.node != nil) { + b.Dump() + panic("gui.SetNode() Error not nil") + } + b.node = n + if (b.node == nil) { + b.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) Append(child ui.Control, x bool) { + if b.UiBox == nil { + panic("GuiBox.Append() can't work. UiBox == nil") return } - s.UiBox.Append(child, x) -} - -/* -func (w GuiWindow) InitWindow(title string) *GuiBox { - if w.UiWindow == nil { - log.Println("gui.InitBox() THIS SHOULD NEVER HAPPEN. Window doesn't exist", w) - return nil - } - tab := ui.NewTab() - w.UiWindow.SetChild(tab) - w.UiWindow.SetMargined(true) - - tab.Append(title, InitBlankWindow()) - tab.SetMargined(0, true) - - w.UiTab = tab - return nil -} -*/ - -func (s GuiBox) InitTab(title string, custom func() ui.Control) *ui.Tab { - if s.Window == nil { - return nil - } - if s.Window.UiWindow == nil { - return nil - } - - window := s.Window.UiWindow - tab := ui.NewTab() - window.SetChild(tab) - window.SetMargined(true) - - tab.Append(title, custom()) - tab.SetMargined(0, true) - // tab.SetMargined(1, true) - - s.Window.UiTab = tab - return tab -} - -func (s GuiBox) AddTab(title string, custom ui.Control) *ui.Tab { - if s.Window == nil { - return nil - } - if s.Window.UiTab == nil { - return nil - } - - tab := s.Window.UiTab - - tab.Append(title, custom) - return tab -} - -func (s GuiBox) AddTab2(title string, custom ui.Control) *ui.Tab { - if s.Window == nil { - return nil - } - if s.Window.UiTab == nil { - return nil - } - - tab := s.Window.UiTab - tab.Append(title, custom) - return tab -} - -func (s GuiBox) AddBoxTab(title string) *GuiBox { - uiTab := s.AddTab2(title, InitBlankWindow()) - tabSetMargined(uiTab) - - var box *GuiBox - box = HardBox(s.Window, Xaxis, "jcarrAddBoxTab") - box.Window.UiTab = uiTab - return box -} - -func (s GuiBox) AddDemoTab(title string) { - uiTab := s.AddTab(title, makeWindowTemplate()) - tabSetMargined(uiTab) -} - -func (s GuiBox) AddDebugTab(title string) { - uiTab := s.AddTab(title, makeWindowDebug()) - tabSetMargined(uiTab) -} - -func tabSetMargined(tab *ui.Tab) { - c := tab.NumPages() - for i := 0; i < c; i++ { - log.Println("tabSetMargined() i =", i) - // tab.SetMargined(i, true) - } + b.UiBox.Append(child, x) } // Note: every mouse click is handled diff --git a/table.go b/table.go index 87e69b2..92ae871 100644 --- a/table.go +++ b/table.go @@ -98,12 +98,12 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { - box := InitWindow(gw, name, Yaxis) - - return AddTableBox(box, name, rowcount, parts) + node := NewWindow() + b := node.box + return b.AddTableBox(name, rowcount, parts) } -func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData) *TableData { +func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData) mh.RowCount = rowcount @@ -142,9 +142,9 @@ func AddTableBox(box *GuiBox, name string, rowcount int, parts []TableColumnData // is this needed? // gw.BoxMap[name] = box - mh.Box = box + mh.Box = b - box.UiBox.Append(table, true) + b.UiBox.Append(table, true) return mh } diff --git a/tableCallbacks.go b/tableCallbacks.go index 966f173..6eefd8d 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -30,7 +30,8 @@ func (mh *TableData) ColumnTypes(m *ui.TableModel) []ui.TableValue { } // TODO: Figure out why this is being called 1000 times a second (10 times for each row & column) -// Nevermind this TODO. Who gives a shit. This is a really smart way to treat the OS toolkits +// +// Nevermind that TODO. Who gives a shit. This is a really smart way to treat the OS toolkits func (mh *TableData) CellValue(m *ui.TableModel, row, column int) ui.TableValue { if (Config.DebugTable) { log.Println("CellValue() row, column =", row, column) diff --git a/window.go b/window.go index 2b615b5..403638e 100644 --- a/window.go +++ b/window.go @@ -2,40 +2,13 @@ package gui import ( "log" + "fmt" "strconv" - "time" "github.com/andlabs/ui" - - // import "regexp" - _ "github.com/andlabs/ui/winmanifest" ) -func initUI(name string, callback func(*GuiBox) *GuiBox) { - ui.Main(func() { - log.Println("gui.initUI() inside ui.Main()") - - box := InitWindow(nil, "StartNewWindow"+name, 0) - box = callback(box) - window := box.Window - log.Println("StartNewWindow() box =", box) - - window.UiWindow.Show() - }) -} - -func StartNewWindow(bg bool, name string, axis int, callback func(*GuiBox) *GuiBox) { - log.Println("StartNewWindow() ui.Main() Create a new window") - - if bg { - go initUI(name, callback) - time.Sleep(500 * time.Millisecond) // this might make it more stable on windows? - } else { - initUI(name, callback) - } -} - func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBox(gw.UiWindow, msg1, msg2) } @@ -44,71 +17,6 @@ func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { ui.MsgBoxError(gw.UiWindow, msg1, msg2) } -// -// This creates a new 'window' (which is just a tab in the window) -// This is this way because on Linux you can have more than one -// actual window but that does not appear to work on the MacOS or Windows -// -func InitWindow(gw *GuiWindow, name string, axis int) *GuiBox { - log.Println("InitGuiWindow() START") - - var box *GuiBox - if gw == nil { - box = mapWindow(nil, name, Config.Height, Config.Width) - } else { - box = mapWindow(gw.UiWindow, name, Config.Height, Config.Width) - } - - // box.Window = &newGuiWindow - newGuiWindow := box.Window - - // This is the first window. One must create it here - if gw == nil { - log.Println("initWindow() ADDING ui.NewWindow()") - newGuiWindow.UiWindow = ui.NewWindow(name, int(newGuiWindow.Height), int(newGuiWindow.Width), true) - newGuiWindow.UiWindow.SetBorderless(false) - - // newGuiWindow.UiWindow.SetTitle("test") - newGuiWindow.UiWindow.OnClosing(func(*ui.Window) bool { - log.Println("initTabWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow) - // newGuiWindow.UiWindow.Destroy() - if Config.Exit == nil { - ui.Quit() - } else { - // allow a custom exit function - Config.Exit(newGuiWindow) - } - return true - }) - - newGuiWindow.UiTab = ui.NewTab() - newGuiWindow.UiWindow.SetChild(newGuiWindow.UiTab) - newGuiWindow.UiWindow.SetMargined(true) - tmp := 0 - newGuiWindow.TabNumber = &tmp - } else { - newGuiWindow.UiWindow = gw.UiWindow - newGuiWindow.UiTab = gw.UiTab - } - - newGuiWindow.BoxMap = make(map[string]*GuiBox) - newGuiWindow.EntryMap = make(map[string]*GuiEntry) - // Data.Windows = append(Data.Windows, &newGuiWindow) - - if newGuiWindow.UiTab == nil { - tabnum := 0 - newGuiWindow.TabNumber = &tabnum - } else { - tabnum := newGuiWindow.UiTab.NumPages() - newGuiWindow.TabNumber = &tabnum - } - - Data.WindowMap[newGuiWindow.Name] = newGuiWindow - - log.Println("InitGuiWindow() END *GuiWindow =", newGuiWindow) - return box -} - func DeleteWindow(name string) { log.Println("gui.DeleteWindow() START name =", name) window := Data.WindowMap[name] @@ -144,57 +52,102 @@ func DeleteWindow(name string) { } } -func CreateWindow(title string, tabname string, x int, y int, custom func() ui.Control) *GuiBox { - box := CreateBlankWindow(title, x, y) - box.InitTab(title, custom) - return box +func makeNode(parent *Node, title string, x int, y int) *Node { + var node Node + node.Name = title + node.Width = x + node.Height = y + + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + // panic("gui.makeNode() START") + if (parent == nil) { + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate window name =", title) + // TODO: just change the 'title' to something unique + panic(fmt.Sprintf("Duplicate window name = %s\n", title)) + return nil + } + // panic("gui.makeNode() before NodeMap()") + Data.NodeMap[title] = &node + Data.NodeArray = append(Data.NodeArray, &node) + Data.NodeSlice = append(Data.NodeSlice, &node) + // panic("gui.makeNode() after NodeMap()") + return &node + } else { + // panic("gui.makeNode() before Append()") + parent.Append(&node) + // panic("gui.makeNode() after Append()") + } + node.parent = parent + return &node } -func CreateBlankWindow(title string, x int, y int) *GuiBox { - box := mapWindow(nil, title, x, y) - log.Println("gui.CreateBlankWindow() title = box.Name =", box.Name) +func (parent *Node) makeNode(title string, x int, y int) *Node { + var node Node + node.Name = title + node.Width = x + node.Height = y - window := ui.NewWindow(box.Name, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", box.Name) + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + parent.Append(&node) + node.parent = parent + return &node +} + +func (n *Node) AddNode(title string) *Node { + var node Node + node.Name = title + node.Width = n.Width + node.Height = n.Height + + id := Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + node.id = id + + n.Append(&node) + node.parent = n + return &node +} + +func (n *Node) uiNewWindow(title string, x int, y int) { + w := ui.NewWindow(title, x, y, false) + w.SetBorderless(false) + f := Config.Exit + w.OnClosing(func(*ui.Window) bool { + if (Config.Debug) { + log.Println("ui.Window().OnClosing()") + } + if (f != nil) { + f(n) + } return true }) - ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", box.Name) - window.Destroy() - return true - }) - - window.SetMargined(true) - window.Show() - - box.Window.UiWindow = window - return box + w.SetMargined(true) + w.Show() + n.uiWindow = w + // w.node = &node + return } -func InitBlankWindow() ui.Control { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - - return hbox -} - -var master = 0 - -func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { +func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) - master = master + 1 - title = title + " jcarr " + strconv.Itoa(master) + title = title + Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 } if Data.WindowMap[title] != nil { log.Println("Data.WindowMap[title] already exists title =", title) panic("Data.WindowMap[newGuiWindow.Name] already exists") return nil } - log.Println("gui.WindowMap START title =", title) + var newGuiWindow GuiWindow newGuiWindow.Width = x newGuiWindow.Height = y @@ -210,30 +163,47 @@ func mapWindow(window *ui.Window, title string, x int, y int) *GuiBox { box.Window = &newGuiWindow box.Name = title + node := makeNode(parent, title, x, y) + node.box = &box + node.uiWindow = window + box.node = node + newGuiWindow.BoxMap["jcarrInitTest"] = &box - return &box + return node } -func NewWindow(title string, x int, y int) *GuiBox { - box := mapWindow(nil, title, x, y) +// This routine creates a blank window with a Title and size (W x H) +// +// This routine can not have any arguements due to the nature of how +// it can be passed via the 'andlabs/ui' queue which, because it is +// cross platform, must pass UI changes into the OS threads (that is +// my guess). +func NewWindow() *Node { + title := Config.Title + w := Config.Width + h := Config.Height + + var n *Node + n = mapWindow(nil, nil, title, w, h) + box := n.box log.Println("gui.NewWindow() title = box.Name =", box.Name) - window := ui.NewWindow(box.Name, x, y, false) - window.SetBorderless(false) - window.OnClosing(func(*ui.Window) bool { - log.Println("createWindow().OnClosing()", box.Name) - return true - }) - ui.OnShouldQuit(func() bool { - log.Println("createWindow().Destroy()", box.Name) - window.Destroy() - return true - }) + n.uiNewWindow(box.Name, w, h) + window := n.uiWindow - window.SetMargined(true) - window.Show() + f := Config.Exit + ui.OnShouldQuit(func() bool { + log.Println("createWindow().Destroy() on node.Name =", n.Name) + if (f != nil) { + f(n) + } + return true + }) box.Window.UiWindow = window - return box + if(n.uiWindow == nil) { + panic("node.uiWindow == nil. This should never happen") + } + return n } From e7bcb14d6ccb8dca8daedd7989e8479dabc124b3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 15:46:31 -0500 Subject: [PATCH 083/113] TEXT: fix OnChanged() handling --- box.go | 18 +++++++++++++++--- cmds/gui-example/demo-window.go | 4 ++-- new-structs.go | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/box.go b/box.go index 7a61f55..cf215d7 100644 --- a/box.go +++ b/box.go @@ -187,12 +187,16 @@ func VerticalBreak(box *GuiBox) { } func (n *Node) AddComboBox(title string, s ...string) *Node { + newNode := n.AddNode(title) box := n.uiBox if (box == nil) { return n } ecbox := ui.NewEditableCombobox() + newNode.uiText = ecbox + // newNode.Dump() + // log.Println("ecbox", ecbox) for id, name := range s { log.Println("Adding Combobox Entry:", id, name) @@ -201,19 +205,27 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { ecbox.OnChanged(func(*ui.EditableCombobox) { test := ecbox.Text() - log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") + log.Println("node.Name = '" + newNode.Name + "' text for '" + title + "' is now: '" + test + "'") + if (newNode.OnChanged == nil) { + log.Println("Not doing custom OnChanged since OnChanged == nil") + newNode.Dump() + } else { + newNode.OnChanged() + } }) box.Append(ecbox, false) - newNode := n.AddNode(title) - newNode.uiText = ecbox + // newNode.Dump() + // panic("junk") return newNode } +/* func (n *Node) OnChanged(f func()) { f() } +*/ func (n *Node) GetText() string { if (n.uiText == nil) { diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go index 993900d..f01c1a9 100644 --- a/cmds/gui-example/demo-window.go +++ b/cmds/gui-example/demo-window.go @@ -33,9 +33,9 @@ func addDemoTab(n *gui.Node, title string) { groupNode1 := newNode.AddGroup("group 1") cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") - cbNode.OnChanged(func () { + cbNode.OnChanged = func () { username = cbNode.GetText() - }) + } groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") groupNode1.Dump() diff --git a/new-structs.go b/new-structs.go index 4f9989e..b75fe0b 100644 --- a/new-structs.go +++ b/new-structs.go @@ -44,6 +44,7 @@ type Node struct { Name string Width int Height int + OnChanged func () parent *Node children []*Node @@ -73,6 +74,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() Name = ", n.Name) log.Println("gui.Node.Dump() Width = ", n.Width) log.Println("gui.Node.Dump() Height = ", n.Height) + log.Println("gui.Node.Dump() OnChanged = ", n.OnChanged) if (n.parent == nil) { log.Println("gui.Node.Dump() parent = nil") @@ -89,6 +91,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() uiBox = ", n.uiBox) log.Println("gui.Node.Dump() uiControl = ", n.uiControl) log.Println("gui.Node.Dump() uiButton = ", n.uiButton) + log.Println("gui.Node.Dump() uiText = ", n.uiText) if (n.id == "") { panic("gui.Node.Dump() id == nil") } From b90d7b96c3fa22a26044729300b6a6b0440398f4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 19:39:57 -0500 Subject: [PATCH 084/113] BOX: start removing GuiBox Signed-off-by: Jeff Carr --- button.go | 5 +++++ tableCallbacks.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/button.go b/button.go index 8ad0a3b..4d4e1d0 100644 --- a/button.go +++ b/button.go @@ -19,6 +19,7 @@ import _ "github.com/andlabs/ui/winmanifest" // There is a []GuiButton which has all the buttons. We search // for the button and then call the function below // +/* func defaultButtonClick(button *ui.Button) { log.Println("gui.defaultButtonClick() LOOK FOR BUTTON button =", button) for key, foo := range Data.AllButtons { @@ -51,6 +52,7 @@ func guiButtonClick(button *GuiButton) { log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil") } } +*/ func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { @@ -60,6 +62,7 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { button := ui.NewButton(name) log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + // true == expand, false == make normal size button n.uiBox.Append(button, false) n.uiButton = button @@ -76,6 +79,7 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return newNode } +/* func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { newNode := n.AddBox(Xaxis, "test CreateButton") box := newNode.FindBox() @@ -127,6 +131,7 @@ func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values inte box.Append(newB.B, false) return newB } +*/ func CreateFontButton(box *GuiBox, action string) *GuiButton { // create a 'fake' button entry for the mouse clicks diff --git a/tableCallbacks.go b/tableCallbacks.go index 6eefd8d..9f4b786 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -97,7 +97,8 @@ func defaultSetCellValue(mh *TableData, row int, column int) { button := mh.Rows[row].HumanData[humanID].Button if (button != nil) { - guiButtonClick(button) + // TODO: fixme. removed on Oct 31 2021 + // guiButtonClick(button) return } log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE") From e74b054bebb3a36333d81e1a78a0a30cd080be0d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 19:52:18 -0500 Subject: [PATCH 085/113] BOX: remove GuiBox Signed-off-by: Jeff Carr --- box.go | 6 ++++-- find.go | 4 ++++ new-structs.go | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/box.go b/box.go index cf215d7..90dcb39 100644 --- a/box.go +++ b/box.go @@ -1,7 +1,7 @@ package gui import "log" -import "os" +// import "os" // import "reflect" import "github.com/andlabs/ui" @@ -102,12 +102,13 @@ func (n *Node) AddBox(axis int, name string) *Node { return newNode } +/* func (b *GuiBox) NewBox(axis int, name string) *GuiBox { log.Println("gui.NewBox() START") n := b.FindNode() if (n == nil) { log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") - os.Exit(0) + panic("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") } else { log.Println("gui.NewBox() node =", n.Name) } @@ -128,6 +129,7 @@ func (b *GuiBox) NewBox(axis int, name string) *GuiBox { // panic("gui.NewBox") return newbox } +*/ func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { log.Println("HardBox() START axis =", axis) diff --git a/find.go b/find.go index e046161..7323596 100644 --- a/find.go +++ b/find.go @@ -17,6 +17,7 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } +/* func (n *Node) FindBox() *GuiBox { if (n.box != nil) { return n.box @@ -34,11 +35,13 @@ func (n *Node) FindWindowBox() *GuiBox { } return n.box } +*/ func (w *GuiWindow) FindNode() *Node { return w.node } +/* func (b *GuiBox) FindNode() *Node { log.Println("gui.FindNode() on GuiBox") if b.node != nil { @@ -50,6 +53,7 @@ func (b *GuiBox) FindNode() *Node { os.Exit(-1) return nil } +*/ func FindWindow(s string) *GuiWindow { for name, window := range Data.WindowMap { diff --git a/new-structs.go b/new-structs.go index b75fe0b..109b4af 100644 --- a/new-structs.go +++ b/new-structs.go @@ -97,10 +97,11 @@ func (n *Node) Dump() { } } - +/* func (n *Node) SetBox(box *GuiBox) { n.box = box } +*/ func (n *Node) SetName(name string) { // n.uiType.SetName(name) From f9c6083be406d517a614383c614864468f97d26a Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 20:07:26 -0500 Subject: [PATCH 086/113] BOX: keep removing GuiBox Signed-off-by: Jeff Carr --- area.go | 20 +++++------ button.go | 98 +++----------------------------------------------- find.go | 49 ------------------------- new-structs.go | 1 + 4 files changed, 16 insertions(+), 152 deletions(-) diff --git a/area.go b/area.go index 7c42c6c..d25bd74 100644 --- a/area.go +++ b/area.go @@ -7,19 +7,19 @@ import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) { +func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButton)) { // make this button just to get the default font (but don't display the button) // There should be another way to do this (?) var newB *GuiButton - newB = CreateFontButton(gb, "AREA") - newB.Box = gb + newB = CreateFontButton(n, "AREA") + // newB.Box = gb newB.Custom = custom - gw := gb.Window + gw := n.window // initialize the GuiArea{} gw.Area = new(GuiArea) gw.Area.Button = newB - gw.Area.Box = gb + // gw.Area.Box = gb gw.Area.UiAttrstr = newText gw.Area.UiArea = ui.NewArea(gw.Area) @@ -107,10 +107,10 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { +func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") - gw := b.Window + gw := n.Window if (gw == nil) { log.Println("ShowTextBox() ERROR gw = nil") return @@ -127,10 +127,10 @@ func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButto */ // TODO: allow padded & axis here - b.UiBox.SetPadded(true) + n.uiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - makeGenericArea(b, newText, custom) - b.UiBox.Append(b.Window.Area.UiArea, true) + makeGenericArea(n, newText, custom) + n.uiBox.Append(n.area.UiArea, true) } diff --git a/button.go b/button.go index 4d4e1d0..8135962 100644 --- a/button.go +++ b/button.go @@ -19,40 +19,6 @@ import _ "github.com/andlabs/ui/winmanifest" // There is a []GuiButton which has all the buttons. We search // for the button and then call the function below // -/* -func defaultButtonClick(button *ui.Button) { - log.Println("gui.defaultButtonClick() LOOK FOR BUTTON button =", button) - for key, foo := range Data.AllButtons { - if (Config.Debug) { - log.Println("gui.defaultButtonClick() Data.AllButtons =", key, foo) - // spew.Dump(foo) - } - if Data.AllButtons[key].B == button { - log.Println("\tgui.defaultButtonClick() BUTTON MATCHED") - guiButtonClick(Data.AllButtons[key]) - return - } - } - log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND") - if (Config.Debug) { - panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.Button") - } -} - -func guiButtonClick(button *GuiButton) { - log.Println("\tgui.guiButtonClick() button.Name =", button.Name) - if button.Custom != nil { - log.Println("\tgui.guiButtonClick() DOING CUSTOM FUNCTION") - button.Custom(button) - return - } - if (Data.MouseClick != nil) { - Data.MouseClick(button) - } else { - log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil") - } -} -*/ func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { @@ -79,66 +45,12 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return newNode } -/* -func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { - newNode := n.AddBox(Xaxis, "test CreateButton") - box := newNode.FindBox() - if (box == nil) { - panic("node.CreateButton().FindBox() == nil") - } - newUiB := ui.NewButton(name) - newUiB.OnClicked(defaultButtonClick) - - var newB *GuiButton - newB = new(GuiButton) - newB.B = newUiB - if (box.UiBox == nil) { - log.Println("CreateButton() box.Window == nil") - // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this - panic("maybe print an error and return nil? or make a fake button?") - } else { - // uibox := box.UiBox - // uibox.Append(newUiB, true) - } - newB.Box = box - newB.Custom = custom - newB.Values = values - - Data.AllButtons = append(Data.AllButtons, newB) - - box.Append(newB.B, false) - return newNode -} - -func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { - newUiB := ui.NewButton(name) - newUiB.OnClicked(defaultButtonClick) - - var newB *GuiButton - newB = new(GuiButton) - newB.B = newUiB - if (box.Window == nil) { - log.Println("CreateButton() box.Window == nil") - // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this - panic("maybe print an error and return nil? or make a fake button?") - } - newB.Box = box - newB.Custom = custom - newB.Values = values - - Data.AllButtons = append(Data.AllButtons, newB) - - box.Append(newB.B, false) - return newB -} -*/ - -func CreateFontButton(box *GuiBox, action string) *GuiButton { +func CreateFontButton(n *Node, action string) *GuiButton { // create a 'fake' button entry for the mouse clicks var newGB GuiButton newGB.Name = "FONT" newGB.FB = ui.NewFontButton() - newGB.Box = box + newGB.Box = n.box Data.AllButtons = append(Data.AllButtons, &newGB) newGB.FB.OnChanged(func (*ui.FontButton) { @@ -150,12 +62,12 @@ func CreateFontButton(box *GuiBox, action string) *GuiButton { return &newGB } -func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { +func CreateColorButton(n *Node, custom func(*GuiButton), name string, values interface {}) *GuiButton { // create a 'fake' button entry for the mouse clicks var newCB GuiButton newCB.Name = name newCB.CB = ui.NewColorButton() - newCB.Box = box + newCB.Box = n.box newCB.Custom = custom newCB.Values = values @@ -171,6 +83,6 @@ func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values Data.MouseClick(&newCB) } }) - box.Append(newCB.CB, false) + n.box.Append(newCB.CB, false) return &newCB } diff --git a/find.go b/find.go index 7323596..619ba36 100644 --- a/find.go +++ b/find.go @@ -17,44 +17,10 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } -/* -func (n *Node) FindBox() *GuiBox { - if (n.box != nil) { - return n.box - } - if (n.parent != nil) { - p := n.parent - return p.box - } - return n.box -} - -func (n *Node) FindWindowBox() *GuiBox { - if (n.box == nil) { - panic("SERIOUS ERROR n.box == nil in FindWindowBox()") - } - return n.box -} -*/ - func (w *GuiWindow) FindNode() *Node { return w.node } -/* -func (b *GuiBox) FindNode() *Node { - log.Println("gui.FindNode() on GuiBox") - if b.node != nil { - return b.node - } - Data.ListChildren(true) - b.Dump() - log.Println("gui.FindNode() on GuiBox is nil") - os.Exit(-1) - return nil -} -*/ - func FindWindow(s string) *GuiWindow { for name, window := range Data.WindowMap { if name == s { @@ -65,21 +31,6 @@ func FindWindow(s string) *GuiWindow { return nil } -func FindBox(s string) *GuiBox { - for name, window := range Data.WindowMap { - if name != s { - continue - } - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - return abox - } - log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) - } - log.Println("gui.FindBox() COULD NOT FIND BOX", s) - return nil -} - func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") diff --git a/new-structs.go b/new-structs.go index 109b4af..8097fbc 100644 --- a/new-structs.go +++ b/new-structs.go @@ -51,6 +51,7 @@ type Node struct { window *GuiWindow box *GuiBox + area *GuiArea custom func(*Node) uiControl *ui.Control From ad3a95575023da4e7324e9ca05ceccf0f714a40f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 20:22:36 -0500 Subject: [PATCH 087/113] BOX: remove GuiBox Signed-off-by: Jeff Carr --- structs.go | 1 + table.go | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/structs.go b/structs.go index c15f4b7..b298f43 100644 --- a/structs.go +++ b/structs.go @@ -256,6 +256,7 @@ type TableData struct { Human [20]HumanMap Box *GuiBox + n *Node lastRow int lastColumn int diff --git a/table.go b/table.go index 92ae871..a149450 100644 --- a/table.go +++ b/table.go @@ -98,12 +98,11 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { - node := NewWindow() - b := node.box - return b.AddTableBox(name, rowcount, parts) + n := NewWindow() + return n.AddTableBox(name, rowcount, parts) } -func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { +func (n *Node) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData) mh.RowCount = rowcount @@ -142,9 +141,10 @@ func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) // is this needed? // gw.BoxMap[name] = box - mh.Box = b + // mh.Box = b + mh.n = n - b.UiBox.Append(table, true) + n.uiBox.Append(table, true) return mh } From bd37df38205ba1a51ac61c253e770babf97cc276 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 20:36:05 -0500 Subject: [PATCH 088/113] BOX: keep removing GuiBox Signed-off-by: Jeff Carr --- box.go | 36 ++++------------------- entry.go | 89 ++------------------------------------------------------ 2 files changed, 7 insertions(+), 118 deletions(-) diff --git a/box.go b/box.go index 90dcb39..7e4d691 100644 --- a/box.go +++ b/box.go @@ -13,7 +13,8 @@ import _ "github.com/andlabs/ui/winmanifest" // add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box // add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' // add(box, newbox, name) // add 'newbox' to 'box' and call it 'name' -func add(box *GuiBox, newbox *GuiBox) { +/* +func add2(box *GuiBox, newbox *GuiBox) { log.Println("gui.add() START box =", box) log.Println("gui.add() START newbox =", newbox) if (box == nil) { @@ -72,6 +73,7 @@ func add(box *GuiBox, newbox *GuiBox) { box.Window.BoxMap[newbox.Name] = newbox log.Println("gui.add() END") } +*/ func (n *Node) AddBox(axis int, name string) *Node { newBox := new(GuiBox) @@ -102,35 +104,6 @@ func (n *Node) AddBox(axis int, name string) *Node { return newNode } -/* -func (b *GuiBox) NewBox(axis int, name string) *GuiBox { - log.Println("gui.NewBox() START") - n := b.FindNode() - if (n == nil) { - log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") - panic("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") - } else { - log.Println("gui.NewBox() node =", n.Name) - } - var newbox *GuiBox - newbox = new(GuiBox) - newbox.Window = b.Window - newbox.Name = name - - var uiBox *ui.Box - if (axis == Xaxis) { - uiBox = ui.NewHorizontalBox() - } else { - uiBox = ui.NewVerticalBox() - } - uiBox.SetPadded(true) - newbox.UiBox = uiBox - add(b, newbox) - // panic("gui.NewBox") - return newbox -} -*/ - func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { log.Println("HardBox() START axis =", axis) @@ -164,7 +137,8 @@ func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { newbox.UiBox = uiBox newbox.Name = name - add(gw.BoxMap["MAINBOX"], newbox) + // TODO: removed Oct 31 + // add(gw.BoxMap["MAINBOX"], newbox) log.Println("HardBox END") return newbox diff --git a/entry.go b/entry.go index c10b7d0..e2e85c3 100644 --- a/entry.go +++ b/entry.go @@ -1,18 +1,14 @@ package gui import "log" -import "fmt" +// import "fmt" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" -import "github.com/davecgh/go-spew/spew" +// import "github.com/davecgh/go-spew/spew" // functions for handling text entry boxes -func NewLabel(box *GuiBox, text string) { - box.Append(ui.NewLabel(text), false) -} - func (n *Node) NewLabel(text string) *Node { // make new node here // n.Append(ui.NewLabel(text), false) @@ -24,22 +20,6 @@ func (n *Node) NewLabel(text string) *Node { return newNode } -func (b *GuiBox) GetText(name string) string { - if (b.Window.EntryMap == nil) { - log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil") - return "" - } - spew.Dump(b.Window.EntryMap) - if (b.Window.EntryMap[name] == nil) { - log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") - return "" - } - e := b.Window.EntryMap[name] - log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) - log.Println("gui.GetText() END") - return e.UiEntry.Text() -} - func (n *Node) SetText(value string) error { log.Println("gui.SetText() value =", value) if (n.uiText != nil) { @@ -53,71 +33,6 @@ func (n *Node) SetText(value string) error { return nil } -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 { - hboxN := ui.NewHorizontalBox() - hboxN.SetPadded(true) - hboxN.Append(ui.NewLabel(a), false) - - e := defaultMakeEntry(startValue, edit, action) - hboxN.Append(e.UiEntry, true) - - box.UiBox.Append(hboxN, true) - - 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 -} - func defaultEntryChange(e *ui.Entry) { for key, em := range Data.AllEntries { if (Config.Debug) { From df1978e6a86ca6918172afa609d0a6fcad4105d4 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 20:52:19 -0500 Subject: [PATCH 089/113] BOX: more removals of GuiBox Signed-off-by: Jeff Carr --- area.go | 9 --- box.go | 159 ------------------------------------------------- new-structs.go | 18 ++---- window.go | 16 ++--- 4 files changed, 15 insertions(+), 187 deletions(-) diff --git a/area.go b/area.go index d25bd74..2cf3d18 100644 --- a/area.go +++ b/area.go @@ -117,15 +117,6 @@ func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton) } log.Println("ShowTextBox() START gw =", gw) - /* - var newbox *GuiBox - newbox = new(GuiBox) - newbox.Window = gw - newbox.Name = name - hbox := ui.NewVerticalBox() - newbox.UiBox = hbox - */ - // TODO: allow padded & axis here n.uiBox.SetPadded(true) diff --git a/box.go b/box.go index 7e4d691..5953f54 100644 --- a/box.go +++ b/box.go @@ -9,159 +9,6 @@ import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" -// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX' -// add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box -// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' -// add(box, newbox, name) // add 'newbox' to 'box' and call it 'name' -/* -func add2(box *GuiBox, newbox *GuiBox) { - log.Println("gui.add() START box =", box) - log.Println("gui.add() START newbox =", newbox) - if (box == nil) { - log.Println("\tgui.add() add to Window as MAINBOX") - if (newbox.Window.UiTab != nil) { - // create a new tab here - // add the box to it as MAINBOX - log.Println("\tgui.add() add to Window as a UiTab") - // TODO: allow passing where to append - // newbox.Window.UiTab.InsertAt(newbox.Name, 0, newbox.UiBox) - newbox.Window.UiTab.Append(newbox.Name, newbox.UiBox) - // newbox.Window.UiTab.SetMargined(0, true) - - // TODO: figure out how to make a new Tab/Window/Box here - // window := InitGuiWindow(Data.Config, newbox.Name, gw.MakeWindow, gw.UiWindow, gw.UiTab) - // window.UiTab.Delete(0) - // window.MakeWindow(window) - // newbox.Window = window - - newbox.Window.BoxMap["MAINBOX"] = newbox - log.Println("gui.add() END") - panic("gui.add() MAINBOX gui.add() END") - return - } else { - log.Println("\tgui.add() ERROR DONT KNOW HOW TO ADD TO A RAW WINDOW YET") - // add this to the window - } - log.Println("\tgui.add() ERROR DON'T KNOW HOW TO add to Window as MAINBOX DONE") - log.Println("gui.add() END") - panic("gui.add() gui.add() END") - return - } - log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) - // copy the box settings over - newbox.Window = box.Window - if (box.node == nil) { - box.Dump() - panic("gui.add() ERROR box.node == nil") - } - - if (newbox.UiBox == nil) { - panic("gui.add() ERROR newbox.UiBox == nil") - } - - if (box.UiBox == nil) { - box.Dump() - // panic("gui.add() ERROR box.UiBox == nil") - return - // TODO: fix this whole add() function // Oct 9 - } - box.UiBox.Append(newbox.UiBox, false) - box.Dump() - panic("gui.add()") - - // add the newbox to the Window.BoxMap[] - box.Window.BoxMap[newbox.Name] = newbox - log.Println("gui.add() END") -} -*/ - -func (n *Node) AddBox(axis int, name string) *Node { - newBox := new(GuiBox) - newBox.Window = n.window - newBox.Name = name - - if (n.box == nil) { - n.box = newBox - } - - // make a new box & a new node - newNode := n.makeNode(name, 111, 100 + Config.counter) - newNode.box = newBox - Config.counter += 1 - - var uiBox *ui.Box - if (axis == Xaxis) { - uiBox = ui.NewHorizontalBox() - } else { - uiBox = ui.NewVerticalBox() - } - uiBox.SetPadded(true) - newBox.UiBox = uiBox - newNode.uiBox = uiBox - - n.Append(newNode) - // add(n.box, newBox) - return newNode -} - -func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { - log.Println("HardBox() START axis =", axis) - - if (gw.node == nil) { - gw.Dump() - panic("gui.HardBox() gw.node == nil") - } - // add a Vertical Seperator if there is already a box - // Is this right? - box := gw.BoxMap["MAINBOX"] - if (box != nil) { - if (axis == Xaxis) { - VerticalBreak(box) - } else { - HorizontalBreak(box) - } - } - - // make the new vbox - var uiBox *ui.Box - if (axis == Xaxis) { - uiBox = ui.NewHorizontalBox() - } else { - uiBox = ui.NewVerticalBox() - } - uiBox.SetPadded(true) - - // Init a new GuiBox - newbox := new(GuiBox) - newbox.Window = gw - newbox.UiBox = uiBox - newbox.Name = name - - // TODO: removed Oct 31 - // add(gw.BoxMap["MAINBOX"], newbox) - - log.Println("HardBox END") - return newbox -} - -func HorizontalBreak(box *GuiBox) { - log.Println("VerticalSeparator added to box =", box.Name) - tmp := ui.NewHorizontalSeparator() - if (box == nil) { - return - } - if (box.UiBox == nil) { - return - } - box.UiBox.Append(tmp, false) -} - -func VerticalBreak(box *GuiBox) { - log.Println("VerticalSeparator added to box =", box.Name) - tmp := ui.NewVerticalSeparator() - box.UiBox.Append(tmp, false) -} - func (n *Node) AddComboBox(title string, s ...string) *Node { newNode := n.AddNode(title) box := n.uiBox @@ -197,12 +44,6 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { return newNode } -/* -func (n *Node) OnChanged(f func()) { - f() -} -*/ - func (n *Node) GetText() string { if (n.uiText == nil) { return "" diff --git a/new-structs.go b/new-structs.go index 8097fbc..d821a3f 100644 --- a/new-structs.go +++ b/new-structs.go @@ -98,12 +98,6 @@ func (n *Node) Dump() { } } -/* -func (n *Node) SetBox(box *GuiBox) { - n.box = box -} -*/ - func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.uiWindow != nil) { @@ -207,13 +201,13 @@ func (n *Node) ListChildren(dump bool) { // // This function should make a new node with the parent and // the 'stuff' Node as a child -func (n *Node) AddTabNode(title string, b *GuiBox) *Node { +func (n *Node) AddTabNode(title string) *Node { var newNode *Node parent := n newNode = parent.makeNode(title, 444, 400 + Config.counter) newNode.uiTab = parent.uiTab - newNode.box = b + // newNode.box = b if (Config.DebugNode) { fmt.Println("") @@ -225,12 +219,12 @@ func (n *Node) AddTabNode(title string, b *GuiBox) *Node { newNode.Dump() } - if (newNode.uiTab == nil) { + if (newNode.uiTab != nil) { log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") // TODO: try to find the tab or window and make them if need be - return newNode + // newNode.uiTab.Append(title, b.UiBox) + panic("newNode.uiTab") } - newNode.uiTab.Append(title, b.UiBox) return newNode } @@ -245,7 +239,7 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { } if parent.box == nil { parent.Dump() - panic("gui.AddTab() ERROR box == nil") + // panic("gui.AddTab() ERROR box == nil") } if parent.uiTab == nil { inittab := ui.NewTab() // no, not that 'inittab' diff --git a/window.go b/window.go index 403638e..8b5f9a5 100644 --- a/window.go +++ b/window.go @@ -159,16 +159,18 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + /* var box GuiBox box.Window = &newGuiWindow box.Name = title + */ node := makeNode(parent, title, x, y) - node.box = &box node.uiWindow = window - box.node = node + // node.box = &box + // box.node = node - newGuiWindow.BoxMap["jcarrInitTest"] = &box + // newGuiWindow.BoxMap["jcarrInitTest"] = &box return node } @@ -186,10 +188,10 @@ func NewWindow() *Node { var n *Node n = mapWindow(nil, nil, title, w, h) - box := n.box - log.Println("gui.NewWindow() title = box.Name =", box.Name) +// box := n.box +// log.Println("gui.NewWindow() title = box.Name =", box.Name) - n.uiNewWindow(box.Name, w, h) + n.uiNewWindow(title, w, h) window := n.uiWindow f := Config.Exit @@ -201,7 +203,7 @@ func NewWindow() *Node { return true }) - box.Window.UiWindow = window + n.uiWindow = window if(n.uiWindow == nil) { panic("node.uiWindow == nil. This should never happen") } From d6980daa81bcb3c12acf5c3fad92e1ed3f5bf48d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 21:07:36 -0500 Subject: [PATCH 090/113] BOX: kill GuiBox Signed-off-by: Jeff Carr --- button.go | 6 +++--- debug-window.go | 2 ++ debug.go | 6 +++++- new-structs.go | 5 +++-- structs.go | 16 +++++++++++----- window.go | 11 ----------- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/button.go b/button.go index 8135962..5017f7a 100644 --- a/button.go +++ b/button.go @@ -50,7 +50,7 @@ func CreateFontButton(n *Node, action string) *GuiButton { var newGB GuiButton newGB.Name = "FONT" newGB.FB = ui.NewFontButton() - newGB.Box = n.box + // newGB.Box = n.box Data.AllButtons = append(Data.AllButtons, &newGB) newGB.FB.OnChanged(func (*ui.FontButton) { @@ -67,7 +67,7 @@ func CreateColorButton(n *Node, custom func(*GuiButton), name string, values int var newCB GuiButton newCB.Name = name newCB.CB = ui.NewColorButton() - newCB.Box = n.box + // newCB.Box = n.box newCB.Custom = custom newCB.Values = values @@ -83,6 +83,6 @@ func CreateColorButton(n *Node, custom func(*GuiButton), name string, values int Data.MouseClick(&newCB) } }) - n.box.Append(newCB.CB, false) + n.uiBox.Append(newCB.CB, false) return &newCB } diff --git a/debug-window.go b/debug-window.go index 19f276d..f058a1e 100644 --- a/debug-window.go +++ b/debug-window.go @@ -295,6 +295,7 @@ func dumpBox(s string) { // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + /* log.Println("gui.dumpBox() BoxMap START") for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) @@ -307,6 +308,7 @@ func dumpBox(s string) { } } log.Println("gui.dumpBox() BoxMap END") + */ if window.UiTab != nil { pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) diff --git a/debug.go b/debug.go index 0b0baa4..d0e814f 100644 --- a/debug.go +++ b/debug.go @@ -40,10 +40,12 @@ func DumpWindows() { func DumpMap() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) - log.Println("gui.DumpBoxes() BOXES:", name) + log.Println("gui.DumpBoxes() window:", window) + /* for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) } + */ } } @@ -59,6 +61,7 @@ func DumpBoxes() { // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + /* for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if name == "MAINBOX" { @@ -68,6 +71,7 @@ func DumpBoxes() { } } } + */ if window.UiTab != nil { // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) diff --git a/new-structs.go b/new-structs.go index d821a3f..bba6347 100644 --- a/new-structs.go +++ b/new-structs.go @@ -50,7 +50,6 @@ type Node struct { children []*Node window *GuiWindow - box *GuiBox area *GuiArea custom func(*Node) @@ -85,7 +84,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() children = ", n.children) log.Println("gui.Node.Dump() window = ", n.window) - log.Println("gui.Node.Dump() box = ", n.box) + // log.Println("gui.Node.Dump() box = ", n.box) log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) log.Println("gui.Node.Dump() uiTab = ", n.uiTab) @@ -237,10 +236,12 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() ERROR ui.Window == nil") return nil } + /* if parent.box == nil { parent.Dump() // panic("gui.AddTab() ERROR box == nil") } + */ if parent.uiTab == nil { inittab := ui.NewTab() // no, not that 'inittab' parent.uiWindow.SetChild(inittab) diff --git a/structs.go b/structs.go index b298f43..c31b021 100644 --- a/structs.go +++ b/structs.go @@ -94,7 +94,7 @@ type GuiWindow struct { // MakeWindow func(*GuiBox) *GuiBox // the components of the window - BoxMap map[string]*GuiBox + // BoxMap map[string]*GuiBox EntryMap map[string]*GuiEntry Area *GuiArea @@ -112,6 +112,7 @@ func (w *GuiWindow) Dump() { log.Println("gui.GuiWindow.Dump() Height = ", w.Height) } +/* // GuiBox is any type of ui.Hbox or ui.Vbox // There can be lots of these for each GuiWindow type GuiBox struct { @@ -124,7 +125,9 @@ type GuiBox struct { // andlabs/ui abstraction mapping UiBox *ui.Box } +*/ +/* func (b *GuiBox) Dump() { log.Println("gui.GuiBox.Dump() Name = ", b.Name) log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) @@ -144,6 +147,7 @@ func (b *GuiBox) SetTitle(title string) { b.Window.UiWindow.SetTitle(title) return } +*/ func (w *GuiWindow) SetNode(n *Node) { if (w.node != nil) { @@ -157,6 +161,7 @@ func (w *GuiWindow) SetNode(n *Node) { } } +/* func (b *GuiBox) SetNode(n *Node) { if (b.node != nil) { b.Dump() @@ -176,6 +181,7 @@ func (b *GuiBox) Append(child ui.Control, x bool) { } b.UiBox.Append(child, x) } +*/ // Note: every mouse click is handled // as a 'Button' regardless of where @@ -183,7 +189,7 @@ func (b *GuiBox) Append(child ui.Control, x bool) { // call this 'GuiMouseClick' type GuiButton struct { Name string // field for human readable name - Box *GuiBox // what box the button click was in + // box2 *GuiBox // what box the button click was in // a callback function for the main application Custom func(*GuiButton) @@ -204,7 +210,7 @@ type GuiEntry struct { Normalize func(string) string // function to 'normalize' the data B *GuiButton - Box *GuiBox + // Box *GuiBox // andlabs/ui abstraction mapping UiEntry *ui.Entry @@ -217,7 +223,7 @@ type GuiEntry struct { // type GuiArea struct { Button *GuiButton // what button handles mouse events - Box *GuiBox + // Box *GuiBox UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -255,7 +261,7 @@ type TableData struct { Cells [20]CellData Human [20]HumanMap - Box *GuiBox + // Box *GuiBox n *Node lastRow int diff --git a/window.go b/window.go index 8b5f9a5..6b2a114 100644 --- a/window.go +++ b/window.go @@ -154,23 +154,12 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod newGuiWindow.Name = title newGuiWindow.UiWindow = window - newGuiWindow.BoxMap = make(map[string]*GuiBox) newGuiWindow.EntryMap = make(map[string]*GuiEntry) Data.WindowMap[newGuiWindow.Name] = &newGuiWindow - /* - var box GuiBox - box.Window = &newGuiWindow - box.Name = title - */ - node := makeNode(parent, title, x, y) node.uiWindow = window - // node.box = &box - // box.node = node - - // newGuiWindow.BoxMap["jcarrInitTest"] = &box return node } From db6c60decc7966730771ffdd649fac159f1988c3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 21:46:30 -0500 Subject: [PATCH 091/113] REFACTOR: remove GuiWindow & GuiBox Signed-off-by: Jeff Carr --- area.go | 14 ++++---- debug-window.go | 93 ++++--------------------------------------------- debug.go | 12 +++---- find.go | 12 ++----- gui.go | 2 +- new-structs.go | 12 ++++--- structs.go | 75 ++++----------------------------------- table.go | 2 +- window.go | 34 ++++++------------ 9 files changed, 45 insertions(+), 211 deletions(-) diff --git a/area.go b/area.go index 2cf3d18..4fb05ec 100644 --- a/area.go +++ b/area.go @@ -12,22 +12,24 @@ func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButt // There should be another way to do this (?) var newB *GuiButton newB = CreateFontButton(n, "AREA") - // newB.Box = gb newB.Custom = custom +/* gw := n.window // initialize the GuiArea{} - gw.Area = new(GuiArea) gw.Area.Button = newB +*/ + area := new(GuiArea) + // gw.Area.Box = gb - gw.Area.UiAttrstr = newText - gw.Area.UiArea = ui.NewArea(gw.Area) + n.uiAttrstr = newText + n.uiArea = ui.NewArea(area) if (Config.Debug) { - spew.Dump(gw.Area.UiArea) + spew.Dump(n.uiArea) log.Println("DEBUGGING", Config.Debug) } else { - log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button) + log.Println("NOT DEBUGGING AREA mhAH.Button =", n.uiButton) } } diff --git a/debug-window.go b/debug-window.go index f058a1e..0849f71 100644 --- a/debug-window.go +++ b/debug-window.go @@ -7,7 +7,7 @@ import ( "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" - "github.com/davecgh/go-spew/spew" +// "github.com/davecgh/go-spew/spew" ) var names = make([]string, 100) @@ -33,6 +33,7 @@ func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) +/* ///////////////////////////////////////////////////// vbox := addGroup(hbox, "range Data.WindowMap") cbox := ui.NewCombobox() @@ -44,7 +45,6 @@ func makeWindowDebug() *ui.Box { addName(cbox, name) } cbox.SetSelected(0) - vbox.Append(cbox, false) cbox.OnSelected(func(*ui.Combobox) { @@ -65,76 +65,6 @@ func makeWindowDebug() *ui.Box { dumpBox(names[x]) }) - b2 := addButton(vbox, "SetMargined(tab)") - b2.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("FindWindow; names[x] =", names[x]) - gw := FindWindow(names[x]) - if gw == nil { - return - } - if gw.UiTab == nil { - return - } - if gw.TabNumber == nil { - return - } - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(gw) - log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab) - log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber) - gw.UiTab.SetMargined(*gw.TabNumber, true) - }) - - b3 := addButton(vbox, "Hide(tab)") - b3.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("FindWindow; names[x] =", names[x]) - gw := FindWindow(names[x]) - if gw == nil { - return - } - if gw.UiTab == nil { - return - } - gw.UiTab.Hide() - }) - - b4 := addButton(vbox, "Show(tab)") - b4.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("FindWindow; names[x] =", names[x]) - gw := FindWindow(names[x]) - if gw == nil { - return - } - if gw.UiTab == nil { - return - } - gw.UiTab.Show() - }) - - b5 := addButton(vbox, "Delete(tab)") - b5.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("FindWindow; names[x] =", names[x]) - gw := FindWindow(names[x]) - if gw == nil { - return - } - if gw.UiTab == nil { - return - } - if gw.TabNumber == nil { - return - } - gw.UiTab.Delete(*gw.TabNumber) - }) - ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Global Debug") @@ -152,6 +82,7 @@ func makeWindowDebug() *ui.Box { dump1.OnClicked(func(*ui.Button) { DumpMap() }) +*/ ///////////////////////////////////////////////////// nodeBox := addGroup(hbox, "Windows:") @@ -179,7 +110,7 @@ func makeWindowDebug() *ui.Box { }) ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Node Debug") + vbox := addGroup(hbox, "Node Debug") n1 := addButton(vbox, "Data.DumpNodeMap()") n1.OnClicked(func(*ui.Button) { @@ -277,6 +208,7 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } +/* func dumpBox(s string) { var name string var window *GuiWindow @@ -295,20 +227,6 @@ func dumpBox(s string) { // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) - /* - log.Println("gui.dumpBox() BoxMap START") - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - abox.Dump() - if name == "MAINBOX" { - if Config.Debug { - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(abox.UiBox) - } - } - } - log.Println("gui.dumpBox() BoxMap END") - */ if window.UiTab != nil { pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) @@ -320,6 +238,7 @@ func dumpBox(s string) { } } } +*/ func addButton(box *ui.Box, name string) *ui.Button { button := ui.NewButton(name) diff --git a/debug.go b/debug.go index d0e814f..2caf6d0 100644 --- a/debug.go +++ b/debug.go @@ -5,7 +5,7 @@ import ( "log" "time" - "github.com/davecgh/go-spew/spew" + // "github.com/davecgh/go-spew/spew" ) // WatchGUI() opens a goroutine @@ -22,7 +22,7 @@ func WatchGUI() { if count > 20 { log.Println("Sleep() in watchGUI()") if Config.Debug { - DumpBoxes() + // DumpBoxes() } count = 0 } @@ -31,6 +31,7 @@ func WatchGUI() { } } +/* func DumpWindows() { for name, _ := range Data.WindowMap { log.Println("gui.DumpWindows() window =", name) @@ -41,11 +42,9 @@ func DumpMap() { for name, window := range Data.WindowMap { log.Println("gui.DumpBoxes() MAP: ", name) log.Println("gui.DumpBoxes() window:", window) - /* for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) } - */ } } @@ -61,7 +60,6 @@ func DumpBoxes() { // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) - /* for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) if name == "MAINBOX" { @@ -71,7 +69,6 @@ func DumpBoxes() { } } } - */ if window.UiTab != nil { // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) @@ -89,7 +86,6 @@ func DumpBoxes() { } } } - /* for i, window := range Data.Windows { if (window.TabNumber == nil) { log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") @@ -97,8 +93,8 @@ func DumpBoxes() { log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) } } - */ } +*/ func addTableTab() { var parts []TableColumnData diff --git a/find.go b/find.go index 619ba36..5eb0854 100644 --- a/find.go +++ b/find.go @@ -17,19 +17,11 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } +/* func (w *GuiWindow) FindNode() *Node { return w.node } - -func FindWindow(s string) *GuiWindow { - for name, window := range Data.WindowMap { - if name == s { - return window - } - } - log.Printf("COULD NOT FIND WINDOW " + s) - return nil -} +*/ func FindNode(name string) *Node { if Data.NodeMap == nil { diff --git a/gui.go b/gui.go index 4174133..bb7e0e5 100644 --- a/gui.go +++ b/gui.go @@ -17,7 +17,7 @@ func init() { log.Println("gui.init() has been run") Data.buttonMap = make(map[*ui.Button]*GuiButton) - Data.WindowMap = make(map[string]*GuiWindow) + // Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) Data.NodeSlice = make([]*Node, 0) diff --git a/new-structs.go b/new-structs.go index bba6347..32d34aa 100644 --- a/new-structs.go +++ b/new-structs.go @@ -49,16 +49,18 @@ type Node struct { parent *Node children []*Node - window *GuiWindow + // window *GuiWindow area *GuiArea custom func(*Node) uiControl *ui.Control uiButton *ui.Button uiWindow *ui.Window - uiTab *ui.Tab - uiBox *ui.Box - uiText *ui.EditableCombobox + uiAttrstr *ui.AttributedString + uiTab *ui.Tab + uiBox *ui.Box + uiArea *ui.Area + uiText *ui.EditableCombobox } func (n *Node) Parent() *Node { @@ -83,7 +85,7 @@ func (n *Node) Dump() { } log.Println("gui.Node.Dump() children = ", n.children) - log.Println("gui.Node.Dump() window = ", n.window) + // log.Println("gui.Node.Dump() window = ", n.window) // log.Println("gui.Node.Dump() box = ", n.box) log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) diff --git a/structs.go b/structs.go index c31b021..9a47e44 100644 --- a/structs.go +++ b/structs.go @@ -2,7 +2,7 @@ package gui import ( "image/color" - "log" +// "log" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -42,7 +42,7 @@ type GuiData struct { // A map of all the entry boxes AllEntries []*GuiEntry - WindowMap map[string]*GuiWindow + // WindowMap map[string]*GuiWindow // Store access to everything via binary tree's NodeMap map[string]*Node @@ -62,7 +62,7 @@ type GuiData struct { type GuiTab struct { Name string // field for human readable name Number int // the andlabs/ui tab index - Window *GuiWindow // the parent Window + // Window *GuiWindow // the parent Window } // @@ -83,6 +83,7 @@ type GuiTab struct { // This struct keeps track of what is in the window so you // can destroy and replace it with something else // +/* type GuiWindow struct { Name string // field for human readable name Width int @@ -90,11 +91,7 @@ type GuiWindow struct { Axis int // does it add items to the X or Y axis TabNumber *int // the andlabs/ui tab index - // the callback function to make the window contents - // MakeWindow func(*GuiBox) *GuiBox - // the components of the window - // BoxMap map[string]*GuiBox EntryMap map[string]*GuiEntry Area *GuiArea @@ -104,7 +101,9 @@ type GuiWindow struct { UiWindow *ui.Window UiTab *ui.Tab // if this != nil, the window is 'tabbed' } +*/ +/* func (w *GuiWindow) Dump() { log.Println("gui.GuiWindow.Dump() Name = ", w.Name) log.Println("gui.GuiWindow.Dump() node = ", w.node) @@ -112,43 +111,6 @@ func (w *GuiWindow) Dump() { log.Println("gui.GuiWindow.Dump() Height = ", w.Height) } -/* -// GuiBox is any type of ui.Hbox or ui.Vbox -// There can be lots of these for each GuiWindow -type GuiBox struct { - Name string // field for human readable name - Axis int // does it add items to the X or Y axis - Window *GuiWindow // the parent Window - - node *Node - - // andlabs/ui abstraction mapping - UiBox *ui.Box -} -*/ - -/* -func (b *GuiBox) Dump() { - log.Println("gui.GuiBox.Dump() Name = ", b.Name) - log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) - log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) - log.Println("gui.GuiBox.Dump() node = ", b.node) - log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) -} - -func (b *GuiBox) SetTitle(title string) { - log.Println("DID IT!", title) - if b.Window == nil { - return - } - if b.Window.UiWindow == nil { - return - } - b.Window.UiWindow.SetTitle(title) - return -} -*/ - func (w *GuiWindow) SetNode(n *Node) { if (w.node != nil) { w.Dump() @@ -160,27 +122,6 @@ func (w *GuiWindow) SetNode(n *Node) { panic("gui.SetNode() node == nil") } } - -/* -func (b *GuiBox) SetNode(n *Node) { - if (b.node != nil) { - b.Dump() - panic("gui.SetNode() Error not nil") - } - b.node = n - if (b.node == nil) { - b.Dump() - panic("gui.SetNode() node == nil") - } -} - -func (b *GuiBox) Append(child ui.Control, x bool) { - if b.UiBox == nil { - panic("GuiBox.Append() can't work. UiBox == nil") - return - } - b.UiBox.Append(child, x) -} */ // Note: every mouse click is handled @@ -189,7 +130,6 @@ func (b *GuiBox) Append(child ui.Control, x bool) { // call this 'GuiMouseClick' type GuiButton struct { Name string // field for human readable name - // box2 *GuiBox // what box the button click was in // a callback function for the main application Custom func(*GuiButton) @@ -210,7 +150,6 @@ type GuiEntry struct { Normalize func(string) string // function to 'normalize' the data B *GuiButton - // Box *GuiBox // andlabs/ui abstraction mapping UiEntry *ui.Entry @@ -223,7 +162,6 @@ type GuiEntry struct { // type GuiArea struct { Button *GuiButton // what button handles mouse events - // Box *GuiBox UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -261,7 +199,6 @@ type TableData struct { Cells [20]CellData Human [20]HumanMap - // Box *GuiBox n *Node lastRow int diff --git a/table.go b/table.go index a149450..378cab2 100644 --- a/table.go +++ b/table.go @@ -97,7 +97,7 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } } -func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { +func AddTableTab(name string, rowcount int, parts []TableColumnData) *TableData { n := NewWindow() return n.AddTableBox(name, rowcount, parts) } diff --git a/window.go b/window.go index 6b2a114..c554d9c 100644 --- a/window.go +++ b/window.go @@ -9,14 +9,19 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { - ui.MsgBox(gw.UiWindow, msg1, msg2) +func (n *Node) MessageWindow2(msg1 string, msg2 string) (*Node) { + ui.MsgBox(n.uiWindow, msg1, msg2) + // TODO: make new node + return n } -func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { - ui.MsgBoxError(gw.UiWindow, msg1, msg2) +func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) { + ui.MsgBoxError(n.uiWindow, msg1, msg2) + // TODO: make new node + return n } +/* func DeleteWindow(name string) { log.Println("gui.DeleteWindow() START name =", name) window := Data.WindowMap[name] @@ -51,6 +56,7 @@ func DeleteWindow(name string) { } } } +*/ func makeNode(parent *Node, title string, x int, y int) *Node { var node Node @@ -137,26 +143,6 @@ func (n *Node) uiNewWindow(title string, x int, y int) { func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) - if Data.WindowMap[title] != nil { - log.Println("Data.WindowMap[title] already exists title =", title) - title = title + Config.prefix + strconv.Itoa(Config.counter) - Config.counter += 1 - } - if Data.WindowMap[title] != nil { - log.Println("Data.WindowMap[title] already exists title =", title) - panic("Data.WindowMap[newGuiWindow.Name] already exists") - return nil - } - - var newGuiWindow GuiWindow - newGuiWindow.Width = x - newGuiWindow.Height = y - newGuiWindow.Name = title - newGuiWindow.UiWindow = window - - newGuiWindow.EntryMap = make(map[string]*GuiEntry) - - Data.WindowMap[newGuiWindow.Name] = &newGuiWindow node := makeNode(parent, title, x, y) node.uiWindow = window From 51d324e805a20d6d3ab11ae40b052bd929151da5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 22:22:16 -0500 Subject: [PATCH 092/113] CLEAN: more code removals Signed-off-by: Jeff Carr --- debug-window.go | 83 ------------------------------------------------- find.go | 6 ---- gui.go | 1 - new-structs.go | 1 - structs.go | 59 ----------------------------------- window.go | 37 ---------------------- 6 files changed, 187 deletions(-) diff --git a/debug-window.go b/debug-window.go index 0849f71..288d433 100644 --- a/debug-window.go +++ b/debug-window.go @@ -33,57 +33,6 @@ func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) -/* - ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "range Data.WindowMap") - cbox := ui.NewCombobox() - - for name, _ := range Data.WindowMap { - if (Config.Debug) { - log.Println("range Data.WindowMap() name =", name) - } - addName(cbox, name) - } - cbox.SetSelected(0) - vbox.Append(cbox, false) - - cbox.OnSelected(func(*ui.Combobox) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("names[x] =", names[x]) - dumpBox(names[x]) - }) - - ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Debug Window") - - b1 := addButton(vbox, "dumpBox(window)") - b1.OnClicked(func(*ui.Button) { - x := cbox.Selected() - log.Println("x =", x) - log.Println("names[x] =", names[x]) - dumpBox(names[x]) - }) - - ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "Global Debug") - - dump3 := addButton(vbox, "Dump Windows") - dump3.OnClicked(func(*ui.Button) { - DumpWindows() - }) - - dump2 := addButton(vbox, "Dump Boxes") - dump2.OnClicked(func(*ui.Button) { - DumpBoxes() - }) - - dump1 := addButton(vbox, "Dump MAP") - dump1.OnClicked(func(*ui.Button) { - DumpMap() - }) -*/ - ///////////////////////////////////////////////////// nodeBox := addGroup(hbox, "Windows:") nodeCombo := ui.NewCombobox() @@ -208,38 +157,6 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } -/* -func dumpBox(s string) { - var name string - var window *GuiWindow - - for name, window = range Data.WindowMap { - if name != s { - continue - } - log.Println("gui.DumpBoxes() MAP: ", name) - if window.TabNumber == nil { - log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") - } else { - log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) - } - log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) - // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) - log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) - log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) - if window.UiTab != nil { - pages := window.UiTab.NumPages() - log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) - tabSetMargined(window.UiTab) - if Config.Debug { - scs := spew.ConfigState{MaxDepth: 2} - scs.Dump(window.UiTab) - } - } - } -} -*/ - func addButton(box *ui.Box, name string) *ui.Button { button := ui.NewButton(name) diff --git a/find.go b/find.go index 5eb0854..15f2714 100644 --- a/find.go +++ b/find.go @@ -17,12 +17,6 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } -/* -func (w *GuiWindow) FindNode() *Node { - return w.node -} -*/ - func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") diff --git a/gui.go b/gui.go index bb7e0e5..236affb 100644 --- a/gui.go +++ b/gui.go @@ -17,7 +17,6 @@ func init() { log.Println("gui.init() has been run") Data.buttonMap = make(map[*ui.Button]*GuiButton) - // Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) Data.NodeSlice = make([]*Node, 0) diff --git a/new-structs.go b/new-structs.go index 32d34aa..6f222b9 100644 --- a/new-structs.go +++ b/new-structs.go @@ -49,7 +49,6 @@ type Node struct { parent *Node children []*Node - // window *GuiWindow area *GuiArea custom func(*Node) diff --git a/structs.go b/structs.go index 9a47e44..dc0c1f4 100644 --- a/structs.go +++ b/structs.go @@ -65,65 +65,6 @@ type GuiTab struct { // Window *GuiWindow // the parent Window } -// -// stores information on the 'window' -// -// This merges the concept of andlabs/ui *Window and *Tab -// -// More than one Window is not supported in a cross platform -// sense & may never be. On Windows and MacOS, you have to have -// 'tabs'. Even under Linux, more than one Window is currently -// unstable -// -// This code will make a 'GuiWindow' regardless of if it is -// a stand alone window (which is more or less working on Linux) -// or a 'tab' inside a window (which is all that works on MacOS -// and MSWindows. -// -// This struct keeps track of what is in the window so you -// can destroy and replace it with something else -// -/* -type GuiWindow struct { - Name string // field for human readable name - Width int - Height int - Axis int // does it add items to the X or Y axis - TabNumber *int // the andlabs/ui tab index - - // the components of the window - EntryMap map[string]*GuiEntry - Area *GuiArea - - node *Node - - // andlabs/ui abstraction mapping - UiWindow *ui.Window - UiTab *ui.Tab // if this != nil, the window is 'tabbed' -} -*/ - -/* -func (w *GuiWindow) Dump() { - log.Println("gui.GuiWindow.Dump() Name = ", w.Name) - log.Println("gui.GuiWindow.Dump() node = ", w.node) - log.Println("gui.GuiWindow.Dump() Width = ", w.Width) - log.Println("gui.GuiWindow.Dump() Height = ", w.Height) -} - -func (w *GuiWindow) SetNode(n *Node) { - if (w.node != nil) { - w.Dump() - panic("gui.SetNode() Error not nil") - } - w.node = n - if (w.node == nil) { - w.Dump() - panic("gui.SetNode() node == nil") - } -} -*/ - // Note: every mouse click is handled // as a 'Button' regardless of where // the user clicks it. You could probably diff --git a/window.go b/window.go index c554d9c..48aaa17 100644 --- a/window.go +++ b/window.go @@ -21,43 +21,6 @@ func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) { return n } -/* -func DeleteWindow(name string) { - log.Println("gui.DeleteWindow() START name =", name) - window := Data.WindowMap[name] - if window == nil { - log.Println("gui.DeleteWindow() NO WINDOW WITH name =", name) - return - } - - log.Println("gui.DumpBoxes() MAP: ", name) - log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) - if window.TabNumber == nil { - log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") - } - tab := *window.TabNumber - log.Println("gui.DumpBoxes() \tWindows.TabNumber =", tab) - log.Println("gui.DumpBoxes() \tSHOULD DELETE TAB", tab, "HERE") - window.UiTab.Delete(tab) - delete(Data.WindowMap, name) - - // renumber tabs here - for name, window := range Data.WindowMap { - log.Println("gui.DumpBoxes() MAP: ", name) - if window.TabNumber == nil { - log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") - } else { - log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) - if tab < *window.TabNumber { - log.Println("gui.DumpBoxes() \tSubtracting 1 from TabNumber") - *window.TabNumber -= 1 - log.Println("gui.DumpBoxes() \tWindows.TabNumber is now =", *window.TabNumber) - } - } - } -} -*/ - func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title From 8c1c83787995595585ac3c1cadaf4a9e0b358891 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Oct 2021 23:48:34 -0500 Subject: [PATCH 093/113] CLEAN: remove GuiButton struct --- area.go | 45 ++++++++++++------------------------------- button.go | 49 +++++++++++++++++++++-------------------------- gui.go | 2 +- new-structs.go | 5 +++++ structs.go | 19 ++++++++++++------ tableCallbacks.go | 8 +++++--- 6 files changed, 58 insertions(+), 70 deletions(-) diff --git a/area.go b/area.go index 4fb05ec..c4e0cae 100644 --- a/area.go +++ b/area.go @@ -7,30 +7,14 @@ import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -func makeGenericArea(n *Node, newText *ui.AttributedString, custom func(*GuiButton)) { - // make this button just to get the default font (but don't display the button) - // There should be another way to do this (?) - var newB *GuiButton - newB = CreateFontButton(n, "AREA") - newB.Custom = custom - -/* - gw := n.window - // initialize the GuiArea{} - gw.Area.Button = newB -*/ +// make this button just to get the default font (but don't display the button) +// There should be another way to do this (?) +func (n *Node) makeGenericArea(newText *ui.AttributedString, custom func(*Node)) { + newNode := n.CreateFontButton("AREA") + newNode.custom = custom area := new(GuiArea) - - // gw.Area.Box = gb - n.uiAttrstr = newText - n.uiArea = ui.NewArea(area) - - if (Config.Debug) { - spew.Dump(n.uiArea) - log.Println("DEBUGGING", Config.Debug) - } else { - log.Println("NOT DEBUGGING AREA mhAH.Button =", n.uiButton) - } + newNode.uiArea = ui.NewArea(area) + newNode.uiAttrstr = newText } func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) { @@ -54,7 +38,7 @@ func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{ String: ah.UiAttrstr, - DefaultFont: ah.Button.FB.Font(), + DefaultFont: ah.N.uiFontButton.Font(), Width: p.AreaWidth, Align: ui.DrawTextAlign(1), }) @@ -63,6 +47,7 @@ func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { } func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { + /* if (Config.Debug) { log.Println("GOT MouseEvent() ah.Button =", ah.Button) spew.Dump(me) @@ -82,6 +67,7 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { Data.MouseClick(ah.Button) } } + */ } func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) { @@ -109,21 +95,14 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { +func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*Node), name string) { log.Println("ShowTextBox() START") - gw := n.Window - if (gw == nil) { - log.Println("ShowTextBox() ERROR gw = nil") - return - } - log.Println("ShowTextBox() START gw =", gw) - // TODO: allow padded & axis here n.uiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - makeGenericArea(n, newText, custom) + n.makeGenericArea(newText, custom) n.uiBox.Append(n.area.UiArea, true) } diff --git a/button.go b/button.go index 5017f7a..92f192a 100644 --- a/button.go +++ b/button.go @@ -2,6 +2,7 @@ package gui import "log" import "reflect" +// import "image/color" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" @@ -45,44 +46,38 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return newNode } -func CreateFontButton(n *Node, action string) *GuiButton { +func (n *Node) CreateFontButton(action string) *Node { // create a 'fake' button entry for the mouse clicks - var newGB GuiButton - newGB.Name = "FONT" - newGB.FB = ui.NewFontButton() + // var newGB GuiButton + // newGB.Name = "FONT" + n.uiFontButton = ui.NewFontButton() // newGB.Box = n.box - Data.AllButtons = append(Data.AllButtons, &newGB) + // Data.AllButtons = append(Data.AllButtons, &newGB) - newGB.FB.OnChanged(func (*ui.FontButton) { - log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) - if (Data.MouseClick != nil) { - Data.MouseClick(&newGB) - } + n.uiFontButton.OnChanged(func (*ui.FontButton) { + log.Println("FontButton.OnChanged() START") + n.Dump() }) - return &newGB + return n } -func CreateColorButton(n *Node, custom func(*GuiButton), name string, values interface {}) *GuiButton { +func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node { // create a 'fake' button entry for the mouse clicks - var newCB GuiButton - newCB.Name = name - newCB.CB = ui.NewColorButton() - // newCB.Box = n.box - newCB.Custom = custom - newCB.Values = values + n.uiColorButton = ui.NewColorButton() + n.custom = custom + n.values = values - Data.AllButtons = append(Data.AllButtons, &newCB) - - newCB.CB.OnChanged(func (*ui.ColorButton) { + n.uiColorButton.OnChanged(func (*ui.ColorButton) { log.Println("ColorButton.OnChanged() START Color Button Click") - r, g, b, a := newCB.CB.Color() + rgba := n.Color + r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) - if (newCB.Custom != nil) { - newCB.Custom(&newCB) + if (n.custom != nil) { + n.custom(n) } else if (Data.MouseClick != nil) { - Data.MouseClick(&newCB) + Data.MouseClick(n) } }) - n.uiBox.Append(newCB.CB, false) - return &newCB + n.uiBox.Append(n.uiColorButton, false) + return n } diff --git a/gui.go b/gui.go index 236affb..e4c5e2c 100644 --- a/gui.go +++ b/gui.go @@ -16,7 +16,7 @@ const Yaxis = 1 // box that is vertical func init() { log.Println("gui.init() has been run") - Data.buttonMap = make(map[*ui.Button]*GuiButton) + // Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.NodeMap = make(map[string]*Node) Data.NodeSlice = make([]*Node, 0) diff --git a/new-structs.go b/new-structs.go index 6f222b9..8d7a203 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,6 +3,7 @@ package gui import ( "log" "fmt" + "image/color" // "reflect" // "github.com/davecgh/go-spew/spew" @@ -45,15 +46,19 @@ type Node struct { Width int Height int OnChanged func () + Color color.RGBA parent *Node children []*Node area *GuiArea custom func(*Node) + values interface {} uiControl *ui.Control uiButton *ui.Button + uiFontButton *ui.FontButton + uiColorButton *ui.ColorButton uiWindow *ui.Window uiAttrstr *ui.AttributedString uiTab *ui.Tab diff --git a/structs.go b/structs.go index dc0c1f4..83229b4 100644 --- a/structs.go +++ b/structs.go @@ -38,7 +38,7 @@ type GuiConfig struct { type GuiData struct { // a fallback default function to handle mouse events // if nothing else is defined to handle them - MouseClick func(*GuiButton) + MouseClick func(*Node) // A map of all the entry boxes AllEntries []*GuiEntry @@ -55,16 +55,19 @@ type GuiData struct { // // This has to work this way because of how // andlabs/ui & andlabs/libui work - AllButtons []*GuiButton - buttonMap map[*ui.Button]*GuiButton + // AllButtons []*GuiButton + // buttonMap map[*ui.Button]*GuiButton } +/* type GuiTab struct { Name string // field for human readable name Number int // the andlabs/ui tab index // Window *GuiWindow // the parent Window } +*/ +/* // Note: every mouse click is handled // as a 'Button' regardless of where // the user clicks it. You could probably @@ -82,6 +85,7 @@ type GuiButton struct { FB *ui.FontButton CB *ui.ColorButton } +*/ // text entry fields type GuiEntry struct { @@ -90,7 +94,8 @@ type GuiEntry struct { Last string // the last value Normalize func(string) string // function to 'normalize' the data - B *GuiButton + // B *GuiButton + N *Node // andlabs/ui abstraction mapping UiEntry *ui.Entry @@ -102,7 +107,8 @@ type GuiEntry struct { // AREA STRUCTURES START // type GuiArea struct { - Button *GuiButton // what button handles mouse events + // Button *GuiButton // what button handles mouse events + N *Node // what button handles mouse events UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -167,7 +173,8 @@ type HumanCellData struct { TextID int Color color.RGBA ColorID int - Button *GuiButton + // Button *GuiButton + N *Node } type HumanMap struct { diff --git a/tableCallbacks.go b/tableCallbacks.go index 9f4b786..f294a9b 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -95,10 +95,12 @@ func defaultSetCellValue(mh *TableData, row int, column int) { humanID := mh.Cells[column].HumanID log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID) - button := mh.Rows[row].HumanData[humanID].Button - if (button != nil) { + n := mh.Rows[row].HumanData[humanID].N + if (n != nil) { // TODO: fixme. removed on Oct 31 2021 - // guiButtonClick(button) + if (n.OnChanged != nil) { + n.OnChanged() + } return } log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE") From 898874b0e9300724806f23953c9cdb8a9f9d3072 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Nov 2021 00:24:56 -0500 Subject: [PATCH 094/113] CLEAN: out of the rabbit hole Signed-off-by: Jeff Carr --- button.go | 9 ++------ gui.go | 1 - new-structs.go | 23 +++++++++++++++++++++ structs.go | 56 +------------------------------------------------- 4 files changed, 26 insertions(+), 63 deletions(-) diff --git a/button.go b/button.go index 92f192a..8fddf6e 100644 --- a/button.go +++ b/button.go @@ -8,6 +8,8 @@ import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" +// TODO: bring this generic mouse click function back +// // This is the default mouse click handler // Every mouse click that hasn't been assigned to // something specific will fall into this routine @@ -17,8 +19,6 @@ import _ "github.com/andlabs/ui/winmanifest" // This routine MUST be here as this is how the andlabs/ui works // This is the raw routine passed to every button in andlabs libui / ui // -// There is a []GuiButton which has all the buttons. We search -// for the button and then call the function below // func (n *Node) AddButton(name string, custom func(*Node)) *Node { @@ -47,12 +47,7 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { } func (n *Node) CreateFontButton(action string) *Node { - // create a 'fake' button entry for the mouse clicks - // var newGB GuiButton - // newGB.Name = "FONT" n.uiFontButton = ui.NewFontButton() - // newGB.Box = n.box - // Data.AllButtons = append(Data.AllButtons, &newGB) n.uiFontButton.OnChanged(func (*ui.FontButton) { log.Println("FontButton.OnChanged() START") diff --git a/gui.go b/gui.go index e4c5e2c..88554c8 100644 --- a/gui.go +++ b/gui.go @@ -16,7 +16,6 @@ const Yaxis = 1 // box that is vertical func init() { log.Println("gui.init() has been run") - // Data.buttonMap = make(map[*ui.Button]*GuiButton) Data.NodeMap = make(map[string]*Node) Data.NodeSlice = make([]*Node, 0) diff --git a/new-structs.go b/new-structs.go index 8d7a203..92ce84a 100644 --- a/new-structs.go +++ b/new-structs.go @@ -234,6 +234,29 @@ func (n *Node) AddTabNode(title string) *Node { return newNode } +func (n *Node) AddHorizontalBox(title string) *Node { + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + if (n.uiBox != nil) { + log.Println("add new hbox to uiBox =", n.uiBox) + n.uiBox.Append(hbox, false) + newNode := n.makeNode(title, 333, 333 + Config.counter) + newNode.parent = n + newNode.uiBox = hbox + // newNode.uiControl = hbox + return newNode + } + if (n.uiTab != nil) { + log.Println("add new hbox to uiTab =", n.uiTab) + n.uiTab.Append(title, hbox) + newNode := n.makeNode(title, 333, 333 + Config.counter) + newNode.parent = n + newNode.uiBox = hbox + // newNode.uiControl = hbox + return newNode + } + return n +} func (n *Node) AddTab(title string, uiC *ui.Box) *Node { parent := n log.Println("gui.Node.AddTab() START name =", title) diff --git a/structs.go b/structs.go index 83229b4..223ec4d 100644 --- a/structs.go +++ b/structs.go @@ -42,51 +42,13 @@ type GuiData struct { // A map of all the entry boxes AllEntries []*GuiEntry - // WindowMap map[string]*GuiWindow // Store access to everything via binary tree's NodeMap map[string]*Node NodeArray []*Node NodeSlice []*Node - - // A map of all buttons everywhere on all - // windows, all tabs, across all goroutines - // This is "GLOBAL" - // - // This has to work this way because of how - // andlabs/ui & andlabs/libui work - // AllButtons []*GuiButton - // buttonMap map[*ui.Button]*GuiButton } -/* -type GuiTab struct { - Name string // field for human readable name - Number int // the andlabs/ui tab index - // Window *GuiWindow // the parent Window -} -*/ - -/* -// Note: every mouse click is handled -// as a 'Button' regardless of where -// the user clicks it. You could probably -// call this 'GuiMouseClick' -type GuiButton struct { - Name string // field for human readable name - - // a callback function for the main application - Custom func(*GuiButton) - Values interface{} - Color color.RGBA - - // andlabs/ui abstraction mapping - B *ui.Button - FB *ui.FontButton - CB *ui.ColorButton -} -*/ - // text entry fields type GuiEntry struct { Name string // field for human readable name @@ -94,21 +56,14 @@ type GuiEntry struct { Last string // the last value Normalize func(string) string // function to 'normalize' the data - // B *GuiButton N *Node // andlabs/ui abstraction mapping UiEntry *ui.Entry } -// -// AREA STRUCTURES START -// AREA STRUCTURES START -// AREA STRUCTURES START -// type GuiArea struct { - // Button *GuiButton // what button handles mouse events - N *Node // what button handles mouse events + N *Node // what node to pass mouse events UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -122,14 +77,6 @@ type FontString struct { } // -// AREA STRUCTURES END -// AREA STRUCTURES END -// AREA STRUCTURES END -// - -// -// TABLE DATA STRUCTURES START -// TABLE DATA STRUCTURES START // TABLE DATA STRUCTURES START // @@ -173,7 +120,6 @@ type HumanCellData struct { TextID int Color color.RGBA ColorID int - // Button *GuiButton N *Node } From 91e4ad1351f9acbf424334dd00be2c5e4900a0b6 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Nov 2021 01:13:07 -0500 Subject: [PATCH 095/113] CLEAN: remove more cruft Signed-off-by: Jeff Carr --- debug.go | 86 ++------------------------------------------------ new-structs.go | 11 ++++--- 2 files changed, 9 insertions(+), 88 deletions(-) diff --git a/debug.go b/debug.go index 2caf6d0..c895e01 100644 --- a/debug.go +++ b/debug.go @@ -31,71 +31,6 @@ func WatchGUI() { } } -/* -func DumpWindows() { - for name, _ := range Data.WindowMap { - log.Println("gui.DumpWindows() window =", name) - } -} - -func DumpMap() { - for name, window := range Data.WindowMap { - log.Println("gui.DumpBoxes() MAP: ", name) - log.Println("gui.DumpBoxes() window:", window) - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - } - } -} - -func DumpBoxes() { - for name, window := range Data.WindowMap { - log.Println("gui.DumpBoxes() MAP: ", name) - if window.TabNumber == nil { - log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") - } else { - log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) - } - log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) - // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) - log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) - log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) - for name, abox := range window.BoxMap { - log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - if name == "MAINBOX" { - if Config.Debug { - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(abox.UiBox) - } - } - } - if window.UiTab != nil { - // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) - // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) - pages := window.UiTab.NumPages() - log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) - // for i := 0; i < pages; i++ { - // log.Println("gui.DumpBoxes()\t\tWindow.UiTab.Margined(", i, ") =", window.UiTab.Margined(i)) - // } - // tmp := spew.NewDefaultConfig() - // tmp.MaxDepth = 2 - // tmp.Dump(window.UiTab) - if Config.Debug { - scs := spew.ConfigState{MaxDepth: 2} - scs.Dump(window.UiTab) - } - } - } - for i, window := range Data.Windows { - if (window.TabNumber == nil) { - log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") - } else { - log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) - } - } -} -*/ - func addTableTab() { var parts []TableColumnData @@ -126,24 +61,6 @@ func (dn *GuiData) DumpNodeMap() { } } -/* -func DebugDataNodeChildren() { - if Data.NodeMap == nil { - log.Println("DebugDataNodeChildren() NodeMap == nil") - return - } - log.Println("DebugDataNodeChildren():") - for name, node := range Data.NodeMap { - log.Println("\tNode name =", node.Width, node.Height, name) - if (node.children == nil) { - log.Println("\t\tNo children") - break - } - log.Println("\t\tHas children:", node.children) - } -} -*/ - func (dn *GuiData) ListChildren(dump bool) { if Data.NodeMap == nil { log.Println("gui.Data.ListChildren() Data.NodeMap == nil") @@ -151,8 +68,9 @@ func (dn *GuiData) ListChildren(dump bool) { } log.Println("gui.Data.ListChildren() Data.NodeMap:") for name, node := range Data.NodeMap { - log.Println("\tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) + listChildrenDepth = 0 if (dump == true) { + log.Println("tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) node.Dump() } node.ListChildren(dump) diff --git a/new-structs.go b/new-structs.go index 92ce84a..daeab64 100644 --- a/new-structs.go +++ b/new-structs.go @@ -135,19 +135,22 @@ func (n *Node) List() { var listChildrenParent *Node var listChildrenDepth int = 0 +// var indent string = "\t" +var indent string = " " + func indentPrintln(depth int, format string, a ...interface{}) { - var tabs string + var space string for i := 0; i < depth; i++ { - tabs = tabs + "\t" + space = space + indent } // newFormat := tabs + strconv.Itoa(depth) + " " + format - newFormat := tabs + format + newFormat := space + format log.Println(newFormat, a) } func (n *Node) ListChildren(dump bool) { - indentPrintln(listChildrenDepth, "\t", n.id, n.Width, n.Height, n.Name) + indentPrintln(listChildrenDepth, "", n.id, n.Width, n.Height, n.Name) if (dump == true) { n.Dump() From f92435a726d7e160c6555c2b5eeeeb9d54114633 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Nov 2021 01:26:31 -0500 Subject: [PATCH 096/113] BREAK: add vertical and horizontal breaks Signed-off-by: Jeff Carr --- new-structs.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/new-structs.go b/new-structs.go index daeab64..b320b24 100644 --- a/new-structs.go +++ b/new-structs.go @@ -237,6 +237,31 @@ func (n *Node) AddTabNode(title string) *Node { return newNode } +func (n *Node) AddHorizontalBreak() *Node { + log.Println("AddHorizontalBreak added to node =", n.Name) + if (n.uiBox != nil) { + tmp := ui.NewHorizontalSeparator() + n.uiBox.Append(tmp, false) + } else { + n.Dump() + // panic("AddHorizontalBreak") + return nil + } + return n +} + +func (n *Node) AddVerticalBreak() *Node { + log.Println("AddVerticalBreak added to node =", n.Name) + if (n.uiBox != nil) { + tmp := ui.NewVerticalSeparator() + n.uiBox.Append(tmp, false) + } else { + n.Dump() + return nil + } + return n +} + func (n *Node) AddHorizontalBox(title string) *Node { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) From 934470d1a981e6f01742bb88aa79b52e2a8bb4f3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Nov 2021 02:15:38 -0500 Subject: [PATCH 097/113] CODE: old code Signed-off-by: Jeff Carr --- new-structs.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/new-structs.go b/new-structs.go index b320b24..62f826c 100644 --- a/new-structs.go +++ b/new-structs.go @@ -293,22 +293,12 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() ERROR ui.Window == nil") return nil } - /* - if parent.box == nil { - parent.Dump() - // panic("gui.AddTab() ERROR box == nil") - } - */ if parent.uiTab == nil { inittab := ui.NewTab() // no, not that 'inittab' parent.uiWindow.SetChild(inittab) parent.uiWindow.SetMargined(true) parent.uiTab = inittab - - // parent.Dump() - // panic("gui.AddTab() ERROR uiTab == nil") } - tab := parent.uiTab parent.uiWindow.SetMargined(true) @@ -322,7 +312,6 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab newNode.uiBox = uiC - // panic("gui.AddTab() after makeNode()") tabSetMargined(newNode.uiTab) return newNode } From 9960652ec7178637a31aca9725fbed6793cae1f5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Nov 2021 03:44:39 -0500 Subject: [PATCH 098/113] TABS: very reliable tab, window and node handling Signed-off-by: Jeff Carr --- entry.go | 2 +- window.go | 46 +++++++++++++++++++++------------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/entry.go b/entry.go index e2e85c3..05db849 100644 --- a/entry.go +++ b/entry.go @@ -12,7 +12,7 @@ import _ "github.com/andlabs/ui/winmanifest" func (n *Node) NewLabel(text string) *Node { // make new node here // n.Append(ui.NewLabel(text), false) - newNode := makeNode(n, text, 333, 334) + newNode := n.makeNode(text, 333, 334) newNode.Dump() // panic("node.NewLabel()") diff --git a/window.go b/window.go index 48aaa17..ceb9cd1 100644 --- a/window.go +++ b/window.go @@ -2,7 +2,7 @@ package gui import ( "log" - "fmt" +// "fmt" "strconv" "github.com/andlabs/ui" @@ -21,7 +21,7 @@ func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) { return n } -func makeNode(parent *Node, title string, x int, y int) *Node { +func initNode(title string, x int, y int) *Node { var node Node node.Name = title node.Width = x @@ -31,26 +31,18 @@ func makeNode(parent *Node, title string, x int, y int) *Node { Config.counter += 1 node.id = id - // panic("gui.makeNode() START") - if (parent == nil) { - if (Data.NodeMap[title] != nil) { - log.Println("Duplicate window name =", title) - // TODO: just change the 'title' to something unique - panic(fmt.Sprintf("Duplicate window name = %s\n", title)) - return nil - } - // panic("gui.makeNode() before NodeMap()") - Data.NodeMap[title] = &node - Data.NodeArray = append(Data.NodeArray, &node) - Data.NodeSlice = append(Data.NodeSlice, &node) - // panic("gui.makeNode() after NodeMap()") - return &node - } else { - // panic("gui.makeNode() before Append()") - parent.Append(&node) - // panic("gui.makeNode() after Append()") + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate window name =", title) + // TODO: just change the 'title' to something unique + // panic(fmt.Sprintf("Duplicate window name = %s\n", title)) + return Data.NodeMap[title] } - node.parent = parent + Data.NodeMap[title] = &node + Data.NodeArray = append(Data.NodeArray, &node) + Data.NodeSlice = append(Data.NodeSlice, &node) + return &node + // parent.Append(&node) + //node.parent = parent return &node } @@ -104,6 +96,7 @@ func (n *Node) uiNewWindow(title string, x int, y int) { return } +/* func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) @@ -112,6 +105,7 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod return node } +*/ // This routine creates a blank window with a Title and size (W x H) // @@ -124,11 +118,13 @@ func NewWindow() *Node { w := Config.Width h := Config.Height - var n *Node - n = mapWindow(nil, nil, title, w, h) -// box := n.box -// log.Println("gui.NewWindow() title = box.Name =", box.Name) + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate window name =", title) + return Data.NodeMap[title] + } + var n *Node + n = initNode(title, w, h) n.uiNewWindow(title, w, h) window := n.uiWindow From 9c946630a1693d761bddcadabd4e22120f609e1b Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 3 Nov 2021 01:44:32 -0500 Subject: [PATCH 099/113] WINDOW: try to properly destroy a window Signed-off-by: Jeff Carr --- button.go | 6 ++++-- window.go | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/button.go b/button.go index 8fddf6e..c1c1c73 100644 --- a/button.go +++ b/button.go @@ -27,8 +27,10 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return n } button := ui.NewButton(name) - log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) - log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + if (Config.Debug) { + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + } // true == expand, false == make normal size button n.uiBox.Append(button, false) n.uiButton = button diff --git a/window.go b/window.go index ceb9cd1..b776ad6 100644 --- a/window.go +++ b/window.go @@ -120,6 +120,13 @@ func NewWindow() *Node { if (Data.NodeMap[title] != nil) { log.Println("Duplicate window name =", title) + Data.NodeMap[title].Dump() + Data.NodeMap[title].ListChildren(false) + uiW := Data.NodeMap[title].uiWindow + if (uiW != nil) { + uiW.Show() + } + panic("check here to see if window is really alive") return Data.NodeMap[title] } From 8d5b885b3a37615c7e6d7e8acb451bb11f90db93 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 3 Nov 2021 22:41:22 -0500 Subject: [PATCH 100/113] GUI: show error windows Signed-off-by: Jeff Carr --- window.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/window.go b/window.go index b776ad6..f22e614 100644 --- a/window.go +++ b/window.go @@ -9,16 +9,26 @@ import ( _ "github.com/andlabs/ui/winmanifest" ) -func (n *Node) MessageWindow2(msg1 string, msg2 string) (*Node) { - ui.MsgBox(n.uiWindow, msg1, msg2) - // TODO: make new node - return n +func findUiWindow() *ui.Window { + for _, node := range Data.NodeMap { + if (node.uiWindow != nil) { + return node.uiWindow + } + } + return nil } -func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) { - ui.MsgBoxError(n.uiWindow, msg1, msg2) +func MessageWindow(msg1 string, msg2 string) (*Node) { + uiW := findUiWindow() + ui.MsgBox(uiW, msg1, msg2) // TODO: make new node - return n + return nil +} + +func ErrorWindow(msg1 string, msg2 string) (*Node) { + uiW := findUiWindow() + ui.MsgBoxError(uiW, msg1, msg2) + return nil } func initNode(title string, x int, y int) *Node { From 1b8b31a123f51b617903d1cab83342444c1c0a7e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 3 Nov 2021 23:25:57 -0500 Subject: [PATCH 101/113] EDITBOX: pull in a edit box example Signed-off-by: Jeff Carr --- demo-window.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/demo-window.go b/demo-window.go index 16566c4..f15f3ee 100644 --- a/demo-window.go +++ b/demo-window.go @@ -26,3 +26,48 @@ func (n *Node) AddGroup(title string) *Node { newNode.uiBox = vbox return newNode } + +func (n *Node) MakeBasicControlsPage(title string) *Node { + if (n == nil) { + return nil + } + origbox := n.uiBox + if (origbox == nil) { + return n + } + + vbox := ui.NewVerticalBox() + vbox.SetPadded(true) + + hbox := ui.NewHorizontalBox() + hbox.SetPadded(true) + vbox.Append(hbox, false) + + hbox.Append(ui.NewButton("Button"), false) + hbox.Append(ui.NewCheckbox("Checkbox"), false) + + vbox.Append(ui.NewLabel("This is a label. Right now, labels can only span one line."), false) + + vbox.Append(ui.NewHorizontalSeparator(), false) + + group := ui.NewGroup("Entries") + group.SetMargined(true) + vbox.Append(group, true) + + group.SetChild(ui.NewNonWrappingMultilineEntry()) + + entryForm := ui.NewForm() + entryForm.SetPadded(true) + group.SetChild(entryForm) + + entryForm.Append("Entry", ui.NewEntry(), false) + entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) + entryForm.Append("Search Entry", ui.NewSearchEntry(), false) + entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true) + entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true) + + origbox.Append(vbox, false) + newNode := n.AddNode(title) + newNode.uiBox = vbox + return newNode +} From 20899fc2b4726c737536703ba6fe13cc91fdbc53 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 00:12:48 -0500 Subject: [PATCH 102/113] PANIC: remove almost all panic()s Signed-off-by: Jeff Carr --- box.go | 3 --- button.go | 2 -- doc.go | 5 +---- entry.go | 1 - new-structs.go | 6 ++---- window.go | 17 ++++++++++------- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/box.go b/box.go index 5953f54..65a8d39 100644 --- a/box.go +++ b/box.go @@ -38,9 +38,6 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { }) box.Append(ecbox, false) - - // newNode.Dump() - // panic("junk") return newNode } diff --git a/button.go b/button.go index c1c1c73..ef73f73 100644 --- a/button.go +++ b/button.go @@ -43,8 +43,6 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { log.Println("gui.AppendButton() Button Clicked. Running custom()") custom(newNode) }) - // panic("AppendButton") - // time.Sleep(3 * time.Second) return newNode } diff --git a/doc.go b/doc.go index 2b324c9..3f8bc64 100644 --- a/doc.go +++ b/doc.go @@ -64,9 +64,6 @@ GUI Usage Errors -Since it is possible for custom Stringer/error interfaces to panic, spew -detects them and handles them internally by printing the panic information -inline with the output. Since spew is intended to provide deep pretty printing -capabilities on structures, it intentionally does not return any errors. +Not sure about errors yet. To early to document them. This is a work in progress. */ package gui diff --git a/entry.go b/entry.go index 05db849..d215cd2 100644 --- a/entry.go +++ b/entry.go @@ -14,7 +14,6 @@ func (n *Node) NewLabel(text string) *Node { // n.Append(ui.NewLabel(text), false) newNode := n.makeNode(text, 333, 334) newNode.Dump() - // panic("node.NewLabel()") n.Append(newNode) return newNode diff --git a/new-structs.go b/new-structs.go index 62f826c..65b964f 100644 --- a/new-structs.go +++ b/new-structs.go @@ -99,7 +99,7 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() uiButton = ", n.uiButton) log.Println("gui.Node.Dump() uiText = ", n.uiText) if (n.id == "") { - panic("gui.Node.Dump() id == nil") + log.Println("THIS SHOULD NOT HAPPEN: gui.Node.Dump() id == nil") } } @@ -228,10 +228,9 @@ func (n *Node) AddTabNode(title string) *Node { } if (newNode.uiTab != nil) { - log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") + log.Println("ERROR: wit/gui/ AddTabNode() Something went wrong tab == nil") // TODO: try to find the tab or window and make them if need be // newNode.uiTab.Append(title, b.UiBox) - panic("newNode.uiTab") } return newNode @@ -244,7 +243,6 @@ func (n *Node) AddHorizontalBreak() *Node { n.uiBox.Append(tmp, false) } else { n.Dump() - // panic("AddHorizontalBreak") return nil } return n diff --git a/window.go b/window.go index f22e614..eb39e87 100644 --- a/window.go +++ b/window.go @@ -42,9 +42,8 @@ func initNode(title string, x int, y int) *Node { node.id = id if (Data.NodeMap[title] != nil) { - log.Println("Duplicate window name =", title) + log.Println("ERROR: Duplicate window name =", title) // TODO: just change the 'title' to something unique - // panic(fmt.Sprintf("Duplicate window name = %s\n", title)) return Data.NodeMap[title] } Data.NodeMap[title] = &node @@ -91,11 +90,15 @@ func (n *Node) uiNewWindow(title string, x int, y int) { w.SetBorderless(false) f := Config.Exit w.OnClosing(func(*ui.Window) bool { - if (Config.Debug) { - log.Println("ui.Window().OnClosing()") - } + log.Println("RUNNING the ui.Window().OnClosing() function") if (f != nil) { f(n) + } else { + n.Dump() + log.Println("gui.uiWindow().OnClosing() NOT SURE WHAT TO DO HERE") + // TODO: always do this here? // by default delete the node? + name := n.Name + delete(Data.NodeMap, name) } return true }) @@ -136,7 +139,7 @@ func NewWindow() *Node { if (uiW != nil) { uiW.Show() } - panic("check here to see if window is really alive") + log.Println("PROBABLY BAD ERROR: check here to see if window is really alive") return Data.NodeMap[title] } @@ -156,7 +159,7 @@ func NewWindow() *Node { n.uiWindow = window if(n.uiWindow == nil) { - panic("node.uiWindow == nil. This should never happen") + log.Println("ERROR: node.uiWindow == nil. This should never happen") } return n } From 50a33262c14f947e65d20197fe92bcbf03037db7 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 01:12:42 -0500 Subject: [PATCH 103/113] GOOD: add Node.SetMargined() Signed-off-by: Jeff Carr --- demo-window.go | 39 ++++++++++++++++++++++++++++++++++++++- entry.go | 16 +++++++++++++++- new-structs.go | 2 ++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/demo-window.go b/demo-window.go index f15f3ee..3d17c35 100644 --- a/demo-window.go +++ b/demo-window.go @@ -1,6 +1,6 @@ package gui -// import "log" +import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -71,3 +71,40 @@ func (n *Node) MakeBasicControlsPage(title string) *Node { newNode.uiBox = vbox return newNode } + +func (n *Node) MakeGroupEdit(title string) *Node { + n.Dump() + + group := ui.NewGroup(title) + group.SetMargined(true) + n.uiBox.Append(group, true) + + entrybox := ui.NewNonWrappingMultilineEntry() + + group.SetChild(entrybox) + + log.Println("entrybox =", entrybox) + n.uiMultilineEntry = entrybox + newNode := n.AddNode(title) + newNode.uiMultilineEntry = entrybox + newNode.uiGroup = group + return newNode + +/* + panic("dump") + entryForm := ui.NewForm() + entryForm.SetPadded(true) + group.SetChild(entryForm) + + entryForm.Append("Entry", ui.NewEntry(), false) + entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) + entryForm.Append("Search Entry", ui.NewSearchEntry(), false) + entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true) + entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true) + + origbox.Append(vbox, false) + newNode := n.AddNode(title) + newNode.uiBox = vbox +*/ + return n +} diff --git a/entry.go b/entry.go index d215cd2..a69adba 100644 --- a/entry.go +++ b/entry.go @@ -1,6 +1,7 @@ package gui import "log" +import "errors" // import "fmt" import "github.com/andlabs/ui" @@ -29,7 +30,20 @@ func (n *Node) SetText(value string) error { n.uiButton.SetText(value) return nil } - 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) { diff --git a/new-structs.go b/new-structs.go index 65b964f..5bceae2 100644 --- a/new-structs.go +++ b/new-structs.go @@ -65,6 +65,8 @@ type Node struct { uiBox *ui.Box uiArea *ui.Area uiText *ui.EditableCombobox + uiMultilineEntry *ui.MultilineEntry + uiGroup *ui.Group } func (n *Node) Parent() *Node { From 2af6db4d6cd01f171d790902f5414f969ce61cf0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 02:23:41 -0500 Subject: [PATCH 104/113] GOOD: use global 'Stretchy' setting Signed-off-by: Jeff Carr --- box.go | 2 +- button.go | 4 ++-- debug-window.go | 6 +++--- demo-window.go | 22 ++-------------------- entry.go | 3 +-- gui.go | 1 + new-structs.go | 6 +++--- structs.go | 1 + 8 files changed, 14 insertions(+), 31 deletions(-) diff --git a/box.go b/box.go index 65a8d39..5b4febe 100644 --- a/box.go +++ b/box.go @@ -37,7 +37,7 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { } }) - box.Append(ecbox, false) + box.Append(ecbox, Config.Stretchy) return newNode } diff --git a/button.go b/button.go index ef73f73..9895ed8 100644 --- a/button.go +++ b/button.go @@ -32,7 +32,7 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) } // true == expand, false == make normal size button - n.uiBox.Append(button, false) + n.uiBox.Append(button, Config.Stretchy) n.uiButton = button newNode := n.makeNode(name, 888, 888 + Config.counter) @@ -73,6 +73,6 @@ func (n *Node) CreateColorButton(custom func(*Node), name string, values interfa Data.MouseClick(n) } }) - n.uiBox.Append(n.uiColorButton, false) + n.uiBox.Append(n.uiColorButton, Config.Stretchy) return n } diff --git a/debug-window.go b/debug-window.go index 288d433..72272ec 100644 --- a/debug-window.go +++ b/debug-window.go @@ -46,7 +46,7 @@ func makeWindowDebug() *ui.Box { } nodeCombo.SetSelected(0) - nodeBox.Append(nodeCombo, false) + nodeBox.Append(nodeCombo, Config.Stretchy) nodeCombo.OnSelected(func(*ui.Combobox) { y := nodeCombo.Selected() @@ -148,7 +148,7 @@ func addName(c *ui.Combobox, s string) { func addGroup(b *ui.Box, name string) *ui.Box { group := ui.NewGroup(name) group.SetMargined(true) - b.Append(group, true) + b.Append(group, Config.Stretchy) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -164,7 +164,7 @@ func addButton(box *ui.Box, name string) *ui.Button { log.Println("Should do something here") }) - box.Append(button, false) + box.Append(button, Config.Stretchy) return button } diff --git a/demo-window.go b/demo-window.go index 3d17c35..6cbb5fd 100644 --- a/demo-window.go +++ b/demo-window.go @@ -16,7 +16,7 @@ func (n *Node) AddGroup(title string) *Node { } group := ui.NewGroup(title) group.SetMargined(true) - hbox.Append(group, true) + hbox.Append(group, Config.Stretchy) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -77,7 +77,7 @@ func (n *Node) MakeGroupEdit(title string) *Node { group := ui.NewGroup(title) group.SetMargined(true) - n.uiBox.Append(group, true) + n.uiBox.Append(group, Config.Stretchy) entrybox := ui.NewNonWrappingMultilineEntry() @@ -89,22 +89,4 @@ func (n *Node) MakeGroupEdit(title string) *Node { newNode.uiMultilineEntry = entrybox newNode.uiGroup = group return newNode - -/* - panic("dump") - entryForm := ui.NewForm() - entryForm.SetPadded(true) - group.SetChild(entryForm) - - entryForm.Append("Entry", ui.NewEntry(), false) - entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) - entryForm.Append("Search Entry", ui.NewSearchEntry(), false) - entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true) - entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true) - - origbox.Append(vbox, false) - newNode := n.AddNode(title) - newNode.uiBox = vbox -*/ - return n } diff --git a/entry.go b/entry.go index a69adba..539c2f7 100644 --- a/entry.go +++ b/entry.go @@ -12,8 +12,7 @@ import _ "github.com/andlabs/ui/winmanifest" func (n *Node) NewLabel(text string) *Node { // make new node here - // n.Append(ui.NewLabel(text), false) - newNode := n.makeNode(text, 333, 334) +newNode := n.makeNode(text, 333, 334) newNode.Dump() n.Append(newNode) diff --git a/gui.go b/gui.go index 88554c8..6f7a236 100644 --- a/gui.go +++ b/gui.go @@ -24,6 +24,7 @@ func init() { Config.prefix = "wit" Config.DebugNode = false Config.DebugTabs = false + Config.Stretchy = true } func GuiInit() { diff --git a/new-structs.go b/new-structs.go index 5bceae2..e6b947e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -242,7 +242,7 @@ func (n *Node) AddHorizontalBreak() *Node { log.Println("AddHorizontalBreak added to node =", n.Name) if (n.uiBox != nil) { tmp := ui.NewHorizontalSeparator() - n.uiBox.Append(tmp, false) + n.uiBox.Append(tmp, Config.Stretchy) } else { n.Dump() return nil @@ -254,7 +254,7 @@ func (n *Node) AddVerticalBreak() *Node { log.Println("AddVerticalBreak added to node =", n.Name) if (n.uiBox != nil) { tmp := ui.NewVerticalSeparator() - n.uiBox.Append(tmp, false) + n.uiBox.Append(tmp, Config.Stretchy) } else { n.Dump() return nil @@ -267,7 +267,7 @@ func (n *Node) AddHorizontalBox(title string) *Node { hbox.SetPadded(true) if (n.uiBox != nil) { log.Println("add new hbox to uiBox =", n.uiBox) - n.uiBox.Append(hbox, false) + n.uiBox.Append(hbox, Config.Stretchy) newNode := n.makeNode(title, 333, 333 + Config.counter) newNode.parent = n newNode.uiBox = hbox diff --git a/structs.go b/structs.go index 223ec4d..d82e621 100644 --- a/structs.go +++ b/structs.go @@ -22,6 +22,7 @@ type GuiConfig struct { Title string Width int Height int + Stretchy bool Exit func(*Node) Debug bool From f615feaf81e9d533f1bd4c6f58a94315a3adc720 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 02:48:41 -0500 Subject: [PATCH 105/113] GOOD: read text from multi-line entrybox Signed-off-by: Jeff Carr --- box.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/box.go b/box.go index 5b4febe..67c0c05 100644 --- a/box.go +++ b/box.go @@ -42,6 +42,9 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { } func (n *Node) GetText() string { + if (n.uiMultilineEntry != nil) { + return n.uiMultilineEntry.Text() + } if (n.uiText == nil) { return "" } From 12cc3882f5dde4095f0a355cc1df963521991d1c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 03:25:42 -0500 Subject: [PATCH 106/113] GOOD: font button shows up again (doesn't do anything) Signed-off-by: Jeff Carr --- button.go | 1 + 1 file changed, 1 insertion(+) diff --git a/button.go b/button.go index 9895ed8..5510ed7 100644 --- a/button.go +++ b/button.go @@ -53,6 +53,7 @@ func (n *Node) CreateFontButton(action string) *Node { log.Println("FontButton.OnChanged() START") n.Dump() }) + n.uiBox.Append(n.uiFontButton, Config.Stretchy) return n } From c91d7d52b8b09f202363332547fb96c0a2f72d30 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 05:46:49 -0500 Subject: [PATCH 107/113] SMALL: some stuff hanging around Signed-off-by: Jeff Carr --- button.go | 3 +++ new-structs.go | 1 + structs.go | 1 + window.go | 5 ++++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/button.go b/button.go index 5510ed7..755d9ab 100644 --- a/button.go +++ b/button.go @@ -54,6 +54,9 @@ func (n *Node) CreateFontButton(action string) *Node { n.Dump() }) n.uiBox.Append(n.uiFontButton, Config.Stretchy) + + // TODO: implement Grid + n.uiGrid = ui.NewGrid() return n } diff --git a/new-structs.go b/new-structs.go index e6b947e..f806696 100644 --- a/new-structs.go +++ b/new-structs.go @@ -67,6 +67,7 @@ type Node struct { uiText *ui.EditableCombobox uiMultilineEntry *ui.MultilineEntry uiGroup *ui.Group + uiGrid *ui.Grid } func (n *Node) Parent() *Node { diff --git a/structs.go b/structs.go index d82e621..79b3fbf 100644 --- a/structs.go +++ b/structs.go @@ -23,6 +23,7 @@ type GuiConfig struct { Width int Height int Stretchy bool + Menu bool Exit func(*Node) Debug bool diff --git a/window.go b/window.go index eb39e87..50f7073 100644 --- a/window.go +++ b/window.go @@ -86,7 +86,7 @@ func (n *Node) AddNode(title string) *Node { } func (n *Node) uiNewWindow(title string, x int, y int) { - w := ui.NewWindow(title, x, y, false) + w := ui.NewWindow(title, x, y, Config.Menu) w.SetBorderless(false) f := Config.Exit w.OnClosing(func(*ui.Window) bool { @@ -126,6 +126,9 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod // it can be passed via the 'andlabs/ui' queue which, because it is // cross platform, must pass UI changes into the OS threads (that is // my guess). +// +// There is probably some way to pass arguements here that I'm can't think of right now +// func NewWindow() *Node { title := Config.Title w := Config.Width From cc676d14ec784a0a674afdcb9dd264f3283dedd3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Nov 2021 08:45:20 -0500 Subject: [PATCH 108/113] NOTE: minor Signed-off-by: Jeff Carr --- gui.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui.go b/gui.go index 6f7a236..ac75f1e 100644 --- a/gui.go +++ b/gui.go @@ -14,10 +14,9 @@ const Xaxis = 0 // box that is horizontal const Yaxis = 1 // box that is vertical func init() { - log.Println("gui.init() has been run") + log.Println("gui.init() REMOVE THIS init()") Data.NodeMap = make(map[string]*Node) - Data.NodeSlice = make([]*Node, 0) Config.counter = 0 From 0e69bcd67a6d29463bd52540fdda68ab74417f83 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Oct 2022 17:33:12 -0500 Subject: [PATCH 109/113] BUILD: builds again with go 1.19 on sid as of today Signed-off-by: Jeff Carr --- cmds/gui-demo/Makefile | 2 +- cmds/gui-example/Makefile | 2 +- entry.go | 1 + go.mod | 9 +++++---- go.sum | 8 +++++--- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cmds/gui-demo/Makefile b/cmds/gui-demo/Makefile index 2dbc808..41fdd10 100644 --- a/cmds/gui-demo/Makefile +++ b/cmds/gui-demo/Makefile @@ -2,4 +2,4 @@ run: build ./gui-demo build: - GO111MODULE="off" go build + go build diff --git a/cmds/gui-example/Makefile b/cmds/gui-example/Makefile index 5028ebd..8718fd1 100644 --- a/cmds/gui-example/Makefile +++ b/cmds/gui-example/Makefile @@ -2,4 +2,4 @@ run: build ./gui-example build: - GO111MODULE="off" go build + go build diff --git a/entry.go b/entry.go index 539c2f7..524609f 100644 --- a/entry.go +++ b/entry.go @@ -5,6 +5,7 @@ import "errors" // import "fmt" import "github.com/andlabs/ui" +// import ui "git.wit.org/interesting/andlabs-ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" diff --git a/go.mod b/go.mod index c72bbca..18a5b64 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,10 @@ module git.wit.org/wit/gui -go 1.17 +go 1.19 require ( - github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e - github.com/davecgh/go-spew v1.1.1 - golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d + git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e // indirect + github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect ) diff --git a/go.sum b/go.sum index 27ff5d2..dd2a245 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,10 @@ +git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e h1:CTg83RH/Poy/HCBbBkRFIqKsdBSsHkLeED6XbMmzZzk= +git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:UuaKXIGj4crFE8XDWljgHTyKi8j4pSd9Vvn+zeHNjkQ= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= -golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= +golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 54a402449f0d61ddec3a01c5e98bcf4503a7a959 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Oct 2022 19:31:35 -0500 Subject: [PATCH 110/113] use the old way to ignore go.mod? Signed-off-by: Jeff Carr --- cmds/gui-example/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/cmds/gui-example/Makefile b/cmds/gui-example/Makefile index 5028ebd..638cffc 100644 --- a/cmds/gui-example/Makefile +++ b/cmds/gui-example/Makefile @@ -2,4 +2,5 @@ run: build ./gui-example build: + GO111MODULE="off" go -v get . GO111MODULE="off" go build From f68428d13b6bed2336b4814a44b45f243c588ae5 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Oct 2022 23:51:48 -0500 Subject: [PATCH 111/113] Try renaming 'Node' to 'Box' --- area.go | 58 ++++++--- box.go | 203 +++++++++++++++++++++++++++++--- button.go | 159 +++++++++++++++++++------ cmds/gui-example/demo-window.go | 4 +- debug-window.go | 172 ++++++++++++++++++++++++++- debug.go | 90 +++++++++++++- demo-window.go | 68 +---------- doc.go | 5 +- entry.go | 104 +++++++++++++--- find.go | 59 ++++++++++ go.mod | 9 +- go.sum | 8 +- gui.go | 6 +- new-structs.go | 111 +++++------------ structs.go | 176 +++++++++++++++++++++++++-- table.go | 14 +-- tableCallbacks.go | 9 +- window.go | 159 +++++++++++++++---------- 18 files changed, 1083 insertions(+), 331 deletions(-) diff --git a/area.go b/area.go index c4e0cae..7c42c6c 100644 --- a/area.go +++ b/area.go @@ -7,14 +7,28 @@ import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -// make this button just to get the default font (but don't display the button) -// There should be another way to do this (?) -func (n *Node) makeGenericArea(newText *ui.AttributedString, custom func(*Node)) { - newNode := n.CreateFontButton("AREA") - newNode.custom = custom - area := new(GuiArea) - newNode.uiArea = ui.NewArea(area) - newNode.uiAttrstr = newText +func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) { + // make this button just to get the default font (but don't display the button) + // There should be another way to do this (?) + var newB *GuiButton + newB = CreateFontButton(gb, "AREA") + newB.Box = gb + newB.Custom = custom + + gw := gb.Window + // initialize the GuiArea{} + gw.Area = new(GuiArea) + gw.Area.Button = newB + gw.Area.Box = gb + gw.Area.UiAttrstr = newText + gw.Area.UiArea = ui.NewArea(gw.Area) + + if (Config.Debug) { + spew.Dump(gw.Area.UiArea) + log.Println("DEBUGGING", Config.Debug) + } else { + log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button) + } } func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) { @@ -38,7 +52,7 @@ func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{ String: ah.UiAttrstr, - DefaultFont: ah.N.uiFontButton.Font(), + DefaultFont: ah.Button.FB.Font(), Width: p.AreaWidth, Align: ui.DrawTextAlign(1), }) @@ -47,7 +61,6 @@ func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { } func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { - /* if (Config.Debug) { log.Println("GOT MouseEvent() ah.Button =", ah.Button) spew.Dump(me) @@ -67,7 +80,6 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { Data.MouseClick(ah.Button) } } - */ } func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) { @@ -95,14 +107,30 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*Node), name string) { +func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") + gw := b.Window + if (gw == nil) { + log.Println("ShowTextBox() ERROR gw = nil") + return + } + log.Println("ShowTextBox() START gw =", gw) + + /* + var newbox *GuiBox + newbox = new(GuiBox) + newbox.Window = gw + newbox.Name = name + hbox := ui.NewVerticalBox() + newbox.UiBox = hbox + */ + // TODO: allow padded & axis here - n.uiBox.SetPadded(true) + b.UiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - n.makeGenericArea(newText, custom) - n.uiBox.Append(n.area.UiArea, true) + makeGenericArea(b, newText, custom) + b.UiBox.Append(b.Window.Area.UiArea, true) } diff --git a/box.go b/box.go index 67c0c05..7a61f55 100644 --- a/box.go +++ b/box.go @@ -1,7 +1,7 @@ package gui import "log" -// import "os" +import "os" // import "reflect" import "github.com/andlabs/ui" @@ -9,17 +9,190 @@ import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" +// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX' +// add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box +// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' +// add(box, newbox, name) // add 'newbox' to 'box' and call it 'name' +func add(box *GuiBox, newbox *GuiBox) { + log.Println("gui.add() START box =", box) + log.Println("gui.add() START newbox =", newbox) + if (box == nil) { + log.Println("\tgui.add() add to Window as MAINBOX") + if (newbox.Window.UiTab != nil) { + // create a new tab here + // add the box to it as MAINBOX + log.Println("\tgui.add() add to Window as a UiTab") + // TODO: allow passing where to append + // newbox.Window.UiTab.InsertAt(newbox.Name, 0, newbox.UiBox) + newbox.Window.UiTab.Append(newbox.Name, newbox.UiBox) + // newbox.Window.UiTab.SetMargined(0, true) + + // TODO: figure out how to make a new Tab/Window/Box here + // window := InitGuiWindow(Data.Config, newbox.Name, gw.MakeWindow, gw.UiWindow, gw.UiTab) + // window.UiTab.Delete(0) + // window.MakeWindow(window) + // newbox.Window = window + + newbox.Window.BoxMap["MAINBOX"] = newbox + log.Println("gui.add() END") + panic("gui.add() MAINBOX gui.add() END") + return + } else { + log.Println("\tgui.add() ERROR DONT KNOW HOW TO ADD TO A RAW WINDOW YET") + // add this to the window + } + log.Println("\tgui.add() ERROR DON'T KNOW HOW TO add to Window as MAINBOX DONE") + log.Println("gui.add() END") + panic("gui.add() gui.add() END") + return + } + log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) + // copy the box settings over + newbox.Window = box.Window + if (box.node == nil) { + box.Dump() + panic("gui.add() ERROR box.node == nil") + } + + if (newbox.UiBox == nil) { + panic("gui.add() ERROR newbox.UiBox == nil") + } + + if (box.UiBox == nil) { + box.Dump() + // panic("gui.add() ERROR box.UiBox == nil") + return + // TODO: fix this whole add() function // Oct 9 + } + box.UiBox.Append(newbox.UiBox, false) + box.Dump() + panic("gui.add()") + + // add the newbox to the Window.BoxMap[] + box.Window.BoxMap[newbox.Name] = newbox + log.Println("gui.add() END") +} + +func (n *Node) AddBox(axis int, name string) *Node { + newBox := new(GuiBox) + newBox.Window = n.window + newBox.Name = name + + if (n.box == nil) { + n.box = newBox + } + + // make a new box & a new node + newNode := n.makeNode(name, 111, 100 + Config.counter) + newNode.box = newBox + Config.counter += 1 + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newBox.UiBox = uiBox + newNode.uiBox = uiBox + + n.Append(newNode) + // add(n.box, newBox) + return newNode +} + +func (b *GuiBox) NewBox(axis int, name string) *GuiBox { + log.Println("gui.NewBox() START") + n := b.FindNode() + if (n == nil) { + log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") + os.Exit(0) + } else { + log.Println("gui.NewBox() node =", n.Name) + } + var newbox *GuiBox + newbox = new(GuiBox) + newbox.Window = b.Window + newbox.Name = name + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newbox.UiBox = uiBox + add(b, newbox) + // panic("gui.NewBox") + return newbox +} + +func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { + log.Println("HardBox() START axis =", axis) + + if (gw.node == nil) { + gw.Dump() + panic("gui.HardBox() gw.node == nil") + } + // add a Vertical Seperator if there is already a box + // Is this right? + box := gw.BoxMap["MAINBOX"] + if (box != nil) { + if (axis == Xaxis) { + VerticalBreak(box) + } else { + HorizontalBreak(box) + } + } + + // make the new vbox + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + + // Init a new GuiBox + newbox := new(GuiBox) + newbox.Window = gw + newbox.UiBox = uiBox + newbox.Name = name + + add(gw.BoxMap["MAINBOX"], newbox) + + log.Println("HardBox END") + return newbox +} + +func HorizontalBreak(box *GuiBox) { + log.Println("VerticalSeparator added to box =", box.Name) + tmp := ui.NewHorizontalSeparator() + if (box == nil) { + return + } + if (box.UiBox == nil) { + return + } + box.UiBox.Append(tmp, false) +} + +func VerticalBreak(box *GuiBox) { + log.Println("VerticalSeparator added to box =", box.Name) + tmp := ui.NewVerticalSeparator() + box.UiBox.Append(tmp, false) +} + func (n *Node) AddComboBox(title string, s ...string) *Node { - newNode := n.AddNode(title) box := n.uiBox if (box == nil) { return n } ecbox := ui.NewEditableCombobox() - newNode.uiText = ecbox - // newNode.Dump() - // log.Println("ecbox", ecbox) for id, name := range s { log.Println("Adding Combobox Entry:", id, name) @@ -28,23 +201,21 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { ecbox.OnChanged(func(*ui.EditableCombobox) { test := ecbox.Text() - log.Println("node.Name = '" + newNode.Name + "' text for '" + title + "' is now: '" + test + "'") - if (newNode.OnChanged == nil) { - log.Println("Not doing custom OnChanged since OnChanged == nil") - newNode.Dump() - } else { - newNode.OnChanged() - } + log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") }) - box.Append(ecbox, Config.Stretchy) + box.Append(ecbox, false) + + newNode := n.AddNode(title) + newNode.uiText = ecbox return newNode } +func (n *Node) OnChanged(f func()) { + f() +} + func (n *Node) GetText() string { - if (n.uiMultilineEntry != nil) { - return n.uiMultilineEntry.Text() - } if (n.uiText == nil) { return "" } diff --git a/button.go b/button.go index 755d9ab..8ad0a3b 100644 --- a/button.go +++ b/button.go @@ -2,14 +2,11 @@ package gui import "log" import "reflect" -// import "image/color" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" -// TODO: bring this generic mouse click function back -// // This is the default mouse click handler // Every mouse click that hasn't been assigned to // something specific will fall into this routine @@ -19,7 +16,41 @@ import _ "github.com/andlabs/ui/winmanifest" // This routine MUST be here as this is how the andlabs/ui works // This is the raw routine passed to every button in andlabs libui / ui // +// There is a []GuiButton which has all the buttons. We search +// for the button and then call the function below // +func defaultButtonClick(button *ui.Button) { + log.Println("gui.defaultButtonClick() LOOK FOR BUTTON button =", button) + for key, foo := range Data.AllButtons { + if (Config.Debug) { + log.Println("gui.defaultButtonClick() Data.AllButtons =", key, foo) + // spew.Dump(foo) + } + if Data.AllButtons[key].B == button { + log.Println("\tgui.defaultButtonClick() BUTTON MATCHED") + guiButtonClick(Data.AllButtons[key]) + return + } + } + log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND") + if (Config.Debug) { + panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.Button") + } +} + +func guiButtonClick(button *GuiButton) { + log.Println("\tgui.guiButtonClick() button.Name =", button.Name) + if button.Custom != nil { + log.Println("\tgui.guiButtonClick() DOING CUSTOM FUNCTION") + button.Custom(button) + return + } + if (Data.MouseClick != nil) { + Data.MouseClick(button) + } else { + log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil") + } +} func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { @@ -27,12 +58,9 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return n } button := ui.NewButton(name) - if (Config.Debug) { - log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) - log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) - } - // true == expand, false == make normal size button - n.uiBox.Append(button, Config.Stretchy) + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + n.uiBox.Append(button, false) n.uiButton = button newNode := n.makeNode(name, 888, 888 + Config.counter) @@ -43,40 +71,101 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { log.Println("gui.AppendButton() Button Clicked. Running custom()") custom(newNode) }) + // panic("AppendButton") + // time.Sleep(3 * time.Second) return newNode } -func (n *Node) CreateFontButton(action string) *Node { - n.uiFontButton = ui.NewFontButton() +func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { + newNode := n.AddBox(Xaxis, "test CreateButton") + box := newNode.FindBox() + if (box == nil) { + panic("node.CreateButton().FindBox() == nil") + } + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) - n.uiFontButton.OnChanged(func (*ui.FontButton) { - log.Println("FontButton.OnChanged() START") - n.Dump() - }) - n.uiBox.Append(n.uiFontButton, Config.Stretchy) + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.UiBox == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } else { + // uibox := box.UiBox + // uibox.Append(newUiB, true) + } + newB.Box = box + newB.Custom = custom + newB.Values = values - // TODO: implement Grid - n.uiGrid = ui.NewGrid() - return n + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newNode } -func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node { - // create a 'fake' button entry for the mouse clicks - n.uiColorButton = ui.NewColorButton() - n.custom = custom - n.values = values +func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) - n.uiColorButton.OnChanged(func (*ui.ColorButton) { - log.Println("ColorButton.OnChanged() START Color Button Click") - rgba := n.Color - r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A - log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) - if (n.custom != nil) { - n.custom(n) - } else if (Data.MouseClick != nil) { - Data.MouseClick(n) + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.Window == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } + newB.Box = box + newB.Custom = custom + newB.Values = values + + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newB +} + +func CreateFontButton(box *GuiBox, action string) *GuiButton { + // create a 'fake' button entry for the mouse clicks + var newGB GuiButton + newGB.Name = "FONT" + newGB.FB = ui.NewFontButton() + newGB.Box = box + Data.AllButtons = append(Data.AllButtons, &newGB) + + newGB.FB.OnChanged(func (*ui.FontButton) { + log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) + if (Data.MouseClick != nil) { + Data.MouseClick(&newGB) } }) - n.uiBox.Append(n.uiColorButton, Config.Stretchy) - return n + return &newGB +} + +func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + // create a 'fake' button entry for the mouse clicks + var newCB GuiButton + newCB.Name = name + newCB.CB = ui.NewColorButton() + newCB.Box = box + newCB.Custom = custom + newCB.Values = values + + Data.AllButtons = append(Data.AllButtons, &newCB) + + newCB.CB.OnChanged(func (*ui.ColorButton) { + log.Println("ColorButton.OnChanged() START Color Button Click") + r, g, b, a := newCB.CB.Color() + log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) + if (newCB.Custom != nil) { + newCB.Custom(&newCB) + } else if (Data.MouseClick != nil) { + Data.MouseClick(&newCB) + } + }) + box.Append(newCB.CB, false) + return &newCB } diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go index f01c1a9..993900d 100644 --- a/cmds/gui-example/demo-window.go +++ b/cmds/gui-example/demo-window.go @@ -33,9 +33,9 @@ func addDemoTab(n *gui.Node, title string) { groupNode1 := newNode.AddGroup("group 1") cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") - cbNode.OnChanged = func () { + cbNode.OnChanged(func () { username = cbNode.GetText() - } + }) groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") groupNode1.Dump() diff --git a/debug-window.go b/debug-window.go index 72272ec..19f276d 100644 --- a/debug-window.go +++ b/debug-window.go @@ -7,7 +7,7 @@ import ( "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" -// "github.com/davecgh/go-spew/spew" + "github.com/davecgh/go-spew/spew" ) var names = make([]string, 100) @@ -33,6 +33,126 @@ func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) + ///////////////////////////////////////////////////// + vbox := addGroup(hbox, "range Data.WindowMap") + cbox := ui.NewCombobox() + + for name, _ := range Data.WindowMap { + if (Config.Debug) { + log.Println("range Data.WindowMap() name =", name) + } + addName(cbox, name) + } + cbox.SetSelected(0) + + vbox.Append(cbox, false) + + cbox.OnSelected(func(*ui.Combobox) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) + }) + + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Debug Window") + + b1 := addButton(vbox, "dumpBox(window)") + b1.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) + }) + + b2 := addButton(vbox, "SetMargined(tab)") + b2.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + if gw.TabNumber == nil { + return + } + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(gw) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab) + log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber) + gw.UiTab.SetMargined(*gw.TabNumber, true) + }) + + b3 := addButton(vbox, "Hide(tab)") + b3.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + gw.UiTab.Hide() + }) + + b4 := addButton(vbox, "Show(tab)") + b4.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + gw.UiTab.Show() + }) + + b5 := addButton(vbox, "Delete(tab)") + b5.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + if gw.TabNumber == nil { + return + } + gw.UiTab.Delete(*gw.TabNumber) + }) + + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Global Debug") + + dump3 := addButton(vbox, "Dump Windows") + dump3.OnClicked(func(*ui.Button) { + DumpWindows() + }) + + dump2 := addButton(vbox, "Dump Boxes") + dump2.OnClicked(func(*ui.Button) { + DumpBoxes() + }) + + dump1 := addButton(vbox, "Dump MAP") + dump1.OnClicked(func(*ui.Button) { + DumpMap() + }) + ///////////////////////////////////////////////////// nodeBox := addGroup(hbox, "Windows:") nodeCombo := ui.NewCombobox() @@ -46,7 +166,7 @@ func makeWindowDebug() *ui.Box { } nodeCombo.SetSelected(0) - nodeBox.Append(nodeCombo, Config.Stretchy) + nodeBox.Append(nodeCombo, false) nodeCombo.OnSelected(func(*ui.Combobox) { y := nodeCombo.Selected() @@ -59,7 +179,7 @@ func makeWindowDebug() *ui.Box { }) ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "Node Debug") + vbox = addGroup(hbox, "Node Debug") n1 := addButton(vbox, "Data.DumpNodeMap()") n1.OnClicked(func(*ui.Button) { @@ -148,7 +268,7 @@ func addName(c *ui.Combobox, s string) { func addGroup(b *ui.Box, name string) *ui.Box { group := ui.NewGroup(name) group.SetMargined(true) - b.Append(group, Config.Stretchy) + b.Append(group, true) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -157,6 +277,48 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } +func dumpBox(s string) { + var name string + var window *GuiWindow + + for name, window = range Data.WindowMap { + if name != s { + continue + } + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + log.Println("gui.dumpBox() BoxMap START") + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + abox.Dump() + if name == "MAINBOX" { + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(abox.UiBox) + } + } + } + log.Println("gui.dumpBox() BoxMap END") + if window.UiTab != nil { + pages := window.UiTab.NumPages() + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) + tabSetMargined(window.UiTab) + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } + } + } +} + func addButton(box *ui.Box, name string) *ui.Button { button := ui.NewButton(name) @@ -164,7 +326,7 @@ func addButton(box *ui.Box, name string) *ui.Button { log.Println("Should do something here") }) - box.Append(button, Config.Stretchy) + box.Append(button, false) return button } diff --git a/debug.go b/debug.go index c895e01..0b0baa4 100644 --- a/debug.go +++ b/debug.go @@ -5,7 +5,7 @@ import ( "log" "time" - // "github.com/davecgh/go-spew/spew" + "github.com/davecgh/go-spew/spew" ) // WatchGUI() opens a goroutine @@ -22,7 +22,7 @@ func WatchGUI() { if count > 20 { log.Println("Sleep() in watchGUI()") if Config.Debug { - // DumpBoxes() + DumpBoxes() } count = 0 } @@ -31,6 +31,71 @@ func WatchGUI() { } } +func DumpWindows() { + for name, _ := range Data.WindowMap { + log.Println("gui.DumpWindows() window =", name) + } +} + +func DumpMap() { + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + log.Println("gui.DumpBoxes() BOXES:", name) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + } + } +} + +func DumpBoxes() { + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + if name == "MAINBOX" { + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(abox.UiBox) + } + } + } + if window.UiTab != nil { + // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) + // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + pages := window.UiTab.NumPages() + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) + // for i := 0; i < pages; i++ { + // log.Println("gui.DumpBoxes()\t\tWindow.UiTab.Margined(", i, ") =", window.UiTab.Margined(i)) + // } + // tmp := spew.NewDefaultConfig() + // tmp.MaxDepth = 2 + // tmp.Dump(window.UiTab) + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } + } + } + /* + for i, window := range Data.Windows { + if (window.TabNumber == nil) { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) + } + } + */ +} + func addTableTab() { var parts []TableColumnData @@ -61,6 +126,24 @@ func (dn *GuiData) DumpNodeMap() { } } +/* +func DebugDataNodeChildren() { + if Data.NodeMap == nil { + log.Println("DebugDataNodeChildren() NodeMap == nil") + return + } + log.Println("DebugDataNodeChildren():") + for name, node := range Data.NodeMap { + log.Println("\tNode name =", node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + break + } + log.Println("\t\tHas children:", node.children) + } +} +*/ + func (dn *GuiData) ListChildren(dump bool) { if Data.NodeMap == nil { log.Println("gui.Data.ListChildren() Data.NodeMap == nil") @@ -68,9 +151,8 @@ func (dn *GuiData) ListChildren(dump bool) { } log.Println("gui.Data.ListChildren() Data.NodeMap:") for name, node := range Data.NodeMap { - listChildrenDepth = 0 + log.Println("\tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) if (dump == true) { - log.Println("tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) node.Dump() } node.ListChildren(dump) diff --git a/demo-window.go b/demo-window.go index 6cbb5fd..16566c4 100644 --- a/demo-window.go +++ b/demo-window.go @@ -1,6 +1,6 @@ package gui -import "log" +// import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -16,7 +16,7 @@ func (n *Node) AddGroup(title string) *Node { } group := ui.NewGroup(title) group.SetMargined(true) - hbox.Append(group, Config.Stretchy) + hbox.Append(group, true) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -26,67 +26,3 @@ func (n *Node) AddGroup(title string) *Node { newNode.uiBox = vbox return newNode } - -func (n *Node) MakeBasicControlsPage(title string) *Node { - if (n == nil) { - return nil - } - origbox := n.uiBox - if (origbox == nil) { - return n - } - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - vbox.Append(hbox, false) - - hbox.Append(ui.NewButton("Button"), false) - hbox.Append(ui.NewCheckbox("Checkbox"), false) - - vbox.Append(ui.NewLabel("This is a label. Right now, labels can only span one line."), false) - - vbox.Append(ui.NewHorizontalSeparator(), false) - - group := ui.NewGroup("Entries") - group.SetMargined(true) - vbox.Append(group, true) - - group.SetChild(ui.NewNonWrappingMultilineEntry()) - - entryForm := ui.NewForm() - entryForm.SetPadded(true) - group.SetChild(entryForm) - - entryForm.Append("Entry", ui.NewEntry(), false) - entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) - entryForm.Append("Search Entry", ui.NewSearchEntry(), false) - entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true) - entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true) - - origbox.Append(vbox, false) - newNode := n.AddNode(title) - newNode.uiBox = vbox - return newNode -} - -func (n *Node) MakeGroupEdit(title string) *Node { - n.Dump() - - group := ui.NewGroup(title) - group.SetMargined(true) - n.uiBox.Append(group, Config.Stretchy) - - entrybox := ui.NewNonWrappingMultilineEntry() - - group.SetChild(entrybox) - - log.Println("entrybox =", entrybox) - n.uiMultilineEntry = entrybox - newNode := n.AddNode(title) - newNode.uiMultilineEntry = entrybox - newNode.uiGroup = group - return newNode -} diff --git a/doc.go b/doc.go index 3f8bc64..2b324c9 100644 --- a/doc.go +++ b/doc.go @@ -64,6 +64,9 @@ GUI Usage Errors -Not sure about errors yet. To early to document them. This is a work in progress. +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. */ package gui diff --git a/entry.go b/entry.go index 524609f..c10b7d0 100644 --- a/entry.go +++ b/entry.go @@ -1,25 +1,45 @@ package gui import "log" -import "errors" -// import "fmt" +import "fmt" import "github.com/andlabs/ui" -// import ui "git.wit.org/interesting/andlabs-ui" import _ "github.com/andlabs/ui/winmanifest" -// import "github.com/davecgh/go-spew/spew" +import "github.com/davecgh/go-spew/spew" // functions for handling text entry boxes +func NewLabel(box *GuiBox, text string) { + box.Append(ui.NewLabel(text), false) +} + func (n *Node) NewLabel(text string) *Node { // make new node here -newNode := n.makeNode(text, 333, 334) + // n.Append(ui.NewLabel(text), false) + newNode := makeNode(n, text, 333, 334) newNode.Dump() + // panic("node.NewLabel()") n.Append(newNode) return newNode } +func (b *GuiBox) GetText(name string) string { + if (b.Window.EntryMap == nil) { + log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil") + return "" + } + spew.Dump(b.Window.EntryMap) + if (b.Window.EntryMap[name] == nil) { + log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") + return "" + } + e := b.Window.EntryMap[name] + log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) + log.Println("gui.GetText() END") + return e.UiEntry.Text() +} + func (n *Node) SetText(value string) error { log.Println("gui.SetText() value =", value) if (n.uiText != nil) { @@ -30,20 +50,72 @@ func (n *Node) SetText(value string) error { 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") + return nil } -func (n *Node) SetMargined(x bool) { - if (n.uiGroup != nil) { - n.uiGroup.SetMargined(x) - return +func SetText(box *GuiBox, name string, value string) error { + if (box == nil) { + return fmt.Errorf("gui.SetText() ERROR box == nil") } - log.Println("Couldn't find something that has a Margin setting") + 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 { + hboxN := ui.NewHorizontalBox() + hboxN.SetPadded(true) + hboxN.Append(ui.NewLabel(a), false) + + e := defaultMakeEntry(startValue, edit, action) + hboxN.Append(e.UiEntry, true) + + box.UiBox.Append(hboxN, true) + + 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 } func defaultEntryChange(e *ui.Entry) { diff --git a/find.go b/find.go index 15f2714..e046161 100644 --- a/find.go +++ b/find.go @@ -17,6 +17,65 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } +func (n *Node) FindBox() *GuiBox { + if (n.box != nil) { + return n.box + } + if (n.parent != nil) { + p := n.parent + return p.box + } + return n.box +} + +func (n *Node) FindWindowBox() *GuiBox { + if (n.box == nil) { + panic("SERIOUS ERROR n.box == nil in FindWindowBox()") + } + return n.box +} + +func (w *GuiWindow) FindNode() *Node { + return w.node +} + +func (b *GuiBox) FindNode() *Node { + log.Println("gui.FindNode() on GuiBox") + if b.node != nil { + return b.node + } + Data.ListChildren(true) + b.Dump() + log.Println("gui.FindNode() on GuiBox is nil") + os.Exit(-1) + return nil +} + +func FindWindow(s string) *GuiWindow { + for name, window := range Data.WindowMap { + if name == s { + return window + } + } + log.Printf("COULD NOT FIND WINDOW " + s) + return nil +} + +func FindBox(s string) *GuiBox { + for name, window := range Data.WindowMap { + if name != s { + continue + } + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + return abox + } + log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) + } + log.Println("gui.FindBox() COULD NOT FIND BOX", s) + return nil +} + func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") diff --git a/go.mod b/go.mod index 18a5b64..c72bbca 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,9 @@ module git.wit.org/wit/gui -go 1.19 +go 1.17 require ( - git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e // indirect - github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect + github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e + github.com/davecgh/go-spew v1.1.1 + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d ) diff --git a/go.sum b/go.sum index dd2a245..27ff5d2 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,8 @@ -git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e h1:CTg83RH/Poy/HCBbBkRFIqKsdBSsHkLeED6XbMmzZzk= -git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:UuaKXIGj4crFE8XDWljgHTyKi8j4pSd9Vvn+zeHNjkQ= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/gui.go b/gui.go index ac75f1e..4174133 100644 --- a/gui.go +++ b/gui.go @@ -14,16 +14,18 @@ const Xaxis = 0 // box that is horizontal const Yaxis = 1 // box that is vertical func init() { - log.Println("gui.init() REMOVE THIS init()") + log.Println("gui.init() has been run") + Data.buttonMap = make(map[*ui.Button]*GuiButton) + Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) + Data.NodeSlice = make([]*Node, 0) Config.counter = 0 Config.prefix = "wit" Config.DebugNode = false Config.DebugTabs = false - Config.Stretchy = true } func GuiInit() { diff --git a/new-structs.go b/new-structs.go index f806696..4f9989e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,7 +3,6 @@ package gui import ( "log" "fmt" - "image/color" // "reflect" // "github.com/davecgh/go-spew/spew" @@ -45,29 +44,20 @@ type Node struct { Name string Width int Height int - OnChanged func () - Color color.RGBA parent *Node children []*Node - area *GuiArea + window *GuiWindow + box *GuiBox custom func(*Node) - values interface {} uiControl *ui.Control uiButton *ui.Button - uiFontButton *ui.FontButton - uiColorButton *ui.ColorButton uiWindow *ui.Window - uiAttrstr *ui.AttributedString - uiTab *ui.Tab - uiBox *ui.Box - uiArea *ui.Area - uiText *ui.EditableCombobox - uiMultilineEntry *ui.MultilineEntry - uiGroup *ui.Group - uiGrid *ui.Grid + uiTab *ui.Tab + uiBox *ui.Box + uiText *ui.EditableCombobox } func (n *Node) Parent() *Node { @@ -83,7 +73,6 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() Name = ", n.Name) log.Println("gui.Node.Dump() Width = ", n.Width) log.Println("gui.Node.Dump() Height = ", n.Height) - log.Println("gui.Node.Dump() OnChanged = ", n.OnChanged) if (n.parent == nil) { log.Println("gui.Node.Dump() parent = nil") @@ -92,20 +81,24 @@ func (n *Node) Dump() { } log.Println("gui.Node.Dump() children = ", n.children) - // log.Println("gui.Node.Dump() window = ", n.window) - // log.Println("gui.Node.Dump() box = ", n.box) + log.Println("gui.Node.Dump() window = ", n.window) + log.Println("gui.Node.Dump() box = ", n.box) log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) log.Println("gui.Node.Dump() uiTab = ", n.uiTab) log.Println("gui.Node.Dump() uiBox = ", n.uiBox) log.Println("gui.Node.Dump() uiControl = ", n.uiControl) log.Println("gui.Node.Dump() uiButton = ", n.uiButton) - log.Println("gui.Node.Dump() uiText = ", n.uiText) if (n.id == "") { - log.Println("THIS SHOULD NOT HAPPEN: gui.Node.Dump() id == nil") + panic("gui.Node.Dump() id == nil") } } + +func (n *Node) SetBox(box *GuiBox) { + n.box = box +} + func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.uiWindow != nil) { @@ -138,22 +131,19 @@ func (n *Node) List() { var listChildrenParent *Node var listChildrenDepth int = 0 -// var indent string = "\t" -var indent string = " " - func indentPrintln(depth int, format string, a ...interface{}) { - var space string + var tabs string for i := 0; i < depth; i++ { - space = space + indent + tabs = tabs + "\t" } // newFormat := tabs + strconv.Itoa(depth) + " " + format - newFormat := space + format + newFormat := tabs + format log.Println(newFormat, a) } func (n *Node) ListChildren(dump bool) { - indentPrintln(listChildrenDepth, "", n.id, n.Width, n.Height, n.Name) + indentPrintln(listChildrenDepth, "\t", n.id, n.Width, n.Height, n.Name) if (dump == true) { n.Dump() @@ -212,13 +202,13 @@ func (n *Node) ListChildren(dump bool) { // // This function should make a new node with the parent and // the 'stuff' Node as a child -func (n *Node) AddTabNode(title string) *Node { +func (n *Node) AddTabNode(title string, b *GuiBox) *Node { var newNode *Node parent := n newNode = parent.makeNode(title, 444, 400 + Config.counter) newNode.uiTab = parent.uiTab - // newNode.box = b + newNode.box = b if (Config.DebugNode) { fmt.Println("") @@ -230,62 +220,16 @@ func (n *Node) AddTabNode(title string) *Node { newNode.Dump() } - if (newNode.uiTab != nil) { - log.Println("ERROR: wit/gui/ AddTabNode() Something went wrong tab == nil") + if (newNode.uiTab == nil) { + log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") // TODO: try to find the tab or window and make them if need be - // newNode.uiTab.Append(title, b.UiBox) + return newNode } + newNode.uiTab.Append(title, b.UiBox) return newNode } -func (n *Node) AddHorizontalBreak() *Node { - log.Println("AddHorizontalBreak added to node =", n.Name) - if (n.uiBox != nil) { - tmp := ui.NewHorizontalSeparator() - n.uiBox.Append(tmp, Config.Stretchy) - } else { - n.Dump() - return nil - } - return n -} - -func (n *Node) AddVerticalBreak() *Node { - log.Println("AddVerticalBreak added to node =", n.Name) - if (n.uiBox != nil) { - tmp := ui.NewVerticalSeparator() - n.uiBox.Append(tmp, Config.Stretchy) - } else { - n.Dump() - return nil - } - return n -} - -func (n *Node) AddHorizontalBox(title string) *Node { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - if (n.uiBox != nil) { - log.Println("add new hbox to uiBox =", n.uiBox) - n.uiBox.Append(hbox, Config.Stretchy) - newNode := n.makeNode(title, 333, 333 + Config.counter) - newNode.parent = n - newNode.uiBox = hbox - // newNode.uiControl = hbox - return newNode - } - if (n.uiTab != nil) { - log.Println("add new hbox to uiTab =", n.uiTab) - n.uiTab.Append(title, hbox) - newNode := n.makeNode(title, 333, 333 + Config.counter) - newNode.parent = n - newNode.uiBox = hbox - // newNode.uiControl = hbox - return newNode - } - return n -} func (n *Node) AddTab(title string, uiC *ui.Box) *Node { parent := n log.Println("gui.Node.AddTab() START name =", title) @@ -294,12 +238,20 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() ERROR ui.Window == nil") return nil } + if parent.box == nil { + parent.Dump() + panic("gui.AddTab() ERROR box == nil") + } if parent.uiTab == nil { inittab := ui.NewTab() // no, not that 'inittab' parent.uiWindow.SetChild(inittab) parent.uiWindow.SetMargined(true) parent.uiTab = inittab + + // parent.Dump() + // panic("gui.AddTab() ERROR uiTab == nil") } + tab := parent.uiTab parent.uiWindow.SetMargined(true) @@ -313,6 +265,7 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab newNode.uiBox = uiC + // panic("gui.AddTab() after makeNode()") tabSetMargined(newNode.uiTab) return newNode } diff --git a/structs.go b/structs.go index 79b3fbf..c15f4b7 100644 --- a/structs.go +++ b/structs.go @@ -2,7 +2,7 @@ package gui import ( "image/color" -// "log" + "log" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -22,8 +22,6 @@ type GuiConfig struct { Title string Width int Height int - Stretchy bool - Menu bool Exit func(*Node) Debug bool @@ -40,15 +38,162 @@ type GuiConfig struct { type GuiData struct { // a fallback default function to handle mouse events // if nothing else is defined to handle them - MouseClick func(*Node) + MouseClick func(*GuiButton) // A map of all the entry boxes AllEntries []*GuiEntry + WindowMap map[string]*GuiWindow // Store access to everything via binary tree's NodeMap map[string]*Node NodeArray []*Node NodeSlice []*Node + + // A map of all buttons everywhere on all + // windows, all tabs, across all goroutines + // This is "GLOBAL" + // + // This has to work this way because of how + // andlabs/ui & andlabs/libui work + AllButtons []*GuiButton + buttonMap map[*ui.Button]*GuiButton +} + +type GuiTab struct { + Name string // field for human readable name + Number int // the andlabs/ui tab index + Window *GuiWindow // the parent Window +} + +// +// stores information on the 'window' +// +// This merges the concept of andlabs/ui *Window and *Tab +// +// More than one Window is not supported in a cross platform +// sense & may never be. On Windows and MacOS, you have to have +// 'tabs'. Even under Linux, more than one Window is currently +// unstable +// +// This code will make a 'GuiWindow' regardless of if it is +// a stand alone window (which is more or less working on Linux) +// or a 'tab' inside a window (which is all that works on MacOS +// and MSWindows. +// +// This struct keeps track of what is in the window so you +// can destroy and replace it with something else +// +type GuiWindow struct { + Name string // field for human readable name + Width int + Height int + Axis int // does it add items to the X or Y axis + TabNumber *int // the andlabs/ui tab index + + // the callback function to make the window contents + // MakeWindow func(*GuiBox) *GuiBox + + // the components of the window + BoxMap map[string]*GuiBox + EntryMap map[string]*GuiEntry + Area *GuiArea + + node *Node + + // andlabs/ui abstraction mapping + UiWindow *ui.Window + UiTab *ui.Tab // if this != nil, the window is 'tabbed' +} + +func (w *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", w.Name) + log.Println("gui.GuiWindow.Dump() node = ", w.node) + log.Println("gui.GuiWindow.Dump() Width = ", w.Width) + log.Println("gui.GuiWindow.Dump() Height = ", w.Height) +} + +// GuiBox is any type of ui.Hbox or ui.Vbox +// There can be lots of these for each GuiWindow +type GuiBox struct { + Name string // field for human readable name + Axis int // does it add items to the X or Y axis + Window *GuiWindow // the parent Window + + node *Node + + // andlabs/ui abstraction mapping + UiBox *ui.Box +} + +func (b *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", b.Name) + log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) + log.Println("gui.GuiBox.Dump() node = ", b.node) + log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) +} + +func (b *GuiBox) SetTitle(title string) { + log.Println("DID IT!", title) + if b.Window == nil { + return + } + if b.Window.UiWindow == nil { + return + } + b.Window.UiWindow.SetTitle(title) + return +} + +func (w *GuiWindow) SetNode(n *Node) { + if (w.node != nil) { + w.Dump() + panic("gui.SetNode() Error not nil") + } + w.node = n + if (w.node == nil) { + w.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) SetNode(n *Node) { + if (b.node != nil) { + b.Dump() + panic("gui.SetNode() Error not nil") + } + b.node = n + if (b.node == nil) { + b.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) Append(child ui.Control, x bool) { + if b.UiBox == nil { + panic("GuiBox.Append() can't work. UiBox == nil") + return + } + b.UiBox.Append(child, x) +} + +// Note: every mouse click is handled +// as a 'Button' regardless of where +// the user clicks it. You could probably +// call this 'GuiMouseClick' +type GuiButton struct { + Name string // field for human readable name + Box *GuiBox // what box the button click was in + + // a callback function for the main application + Custom func(*GuiButton) + Values interface{} + Color color.RGBA + + // andlabs/ui abstraction mapping + B *ui.Button + FB *ui.FontButton + CB *ui.ColorButton } // text entry fields @@ -58,14 +203,21 @@ type GuiEntry struct { Last string // the last value Normalize func(string) string // function to 'normalize' the data - N *Node + B *GuiButton + Box *GuiBox // andlabs/ui abstraction mapping UiEntry *ui.Entry } +// +// AREA STRUCTURES START +// AREA STRUCTURES START +// AREA STRUCTURES START +// type GuiArea struct { - N *Node // what node to pass mouse events + Button *GuiButton // what button handles mouse events + Box *GuiBox UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -79,6 +231,14 @@ type FontString struct { } // +// AREA STRUCTURES END +// AREA STRUCTURES END +// AREA STRUCTURES END +// + +// +// TABLE DATA STRUCTURES START +// TABLE DATA STRUCTURES START // TABLE DATA STRUCTURES START // @@ -95,7 +255,7 @@ type TableData struct { Cells [20]CellData Human [20]HumanMap - n *Node + Box *GuiBox lastRow int lastColumn int @@ -122,7 +282,7 @@ type HumanCellData struct { TextID int Color color.RGBA ColorID int - N *Node + Button *GuiButton } type HumanMap struct { diff --git a/table.go b/table.go index 378cab2..92ae871 100644 --- a/table.go +++ b/table.go @@ -97,12 +97,13 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } } -func AddTableTab(name string, rowcount int, parts []TableColumnData) *TableData { - n := NewWindow() - return n.AddTableBox(name, rowcount, parts) +func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { + node := NewWindow() + b := node.box + return b.AddTableBox(name, rowcount, parts) } -func (n *Node) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { +func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData) mh.RowCount = rowcount @@ -141,10 +142,9 @@ func (n *Node) AddTableBox(name string, rowcount int, parts []TableColumnData) * // is this needed? // gw.BoxMap[name] = box - // mh.Box = b - mh.n = n + mh.Box = b - n.uiBox.Append(table, true) + b.UiBox.Append(table, true) return mh } diff --git a/tableCallbacks.go b/tableCallbacks.go index f294a9b..6eefd8d 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -95,12 +95,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) { humanID := mh.Cells[column].HumanID log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID) - n := mh.Rows[row].HumanData[humanID].N - if (n != nil) { - // TODO: fixme. removed on Oct 31 2021 - if (n.OnChanged != nil) { - n.OnChanged() - } + button := mh.Rows[row].HumanData[humanID].Button + if (button != nil) { + guiButtonClick(button) return } log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE") diff --git a/window.go b/window.go index 50f7073..403638e 100644 --- a/window.go +++ b/window.go @@ -2,36 +2,57 @@ package gui import ( "log" -// "fmt" + "fmt" "strconv" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" ) -func findUiWindow() *ui.Window { - for _, node := range Data.NodeMap { - if (node.uiWindow != nil) { - return node.uiWindow +func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBox(gw.UiWindow, msg1, msg2) +} + +func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBoxError(gw.UiWindow, msg1, msg2) +} + +func DeleteWindow(name string) { + log.Println("gui.DeleteWindow() START name =", name) + window := Data.WindowMap[name] + if window == nil { + log.Println("gui.DeleteWindow() NO WINDOW WITH name =", name) + return + } + + log.Println("gui.DumpBoxes() MAP: ", name) + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } + tab := *window.TabNumber + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", tab) + log.Println("gui.DumpBoxes() \tSHOULD DELETE TAB", tab, "HERE") + window.UiTab.Delete(tab) + delete(Data.WindowMap, name) + + // renumber tabs here + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + if tab < *window.TabNumber { + log.Println("gui.DumpBoxes() \tSubtracting 1 from TabNumber") + *window.TabNumber -= 1 + log.Println("gui.DumpBoxes() \tWindows.TabNumber is now =", *window.TabNumber) + } } } - return nil } -func MessageWindow(msg1 string, msg2 string) (*Node) { - uiW := findUiWindow() - ui.MsgBox(uiW, msg1, msg2) - // TODO: make new node - return nil -} - -func ErrorWindow(msg1 string, msg2 string) (*Node) { - uiW := findUiWindow() - ui.MsgBoxError(uiW, msg1, msg2) - return nil -} - -func initNode(title string, x int, y int) *Node { +func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title node.Width = x @@ -41,17 +62,26 @@ func initNode(title string, x int, y int) *Node { Config.counter += 1 node.id = id - if (Data.NodeMap[title] != nil) { - log.Println("ERROR: Duplicate window name =", title) - // TODO: just change the 'title' to something unique - return Data.NodeMap[title] + // panic("gui.makeNode() START") + if (parent == nil) { + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate window name =", title) + // TODO: just change the 'title' to something unique + panic(fmt.Sprintf("Duplicate window name = %s\n", title)) + return nil + } + // panic("gui.makeNode() before NodeMap()") + Data.NodeMap[title] = &node + Data.NodeArray = append(Data.NodeArray, &node) + Data.NodeSlice = append(Data.NodeSlice, &node) + // panic("gui.makeNode() after NodeMap()") + return &node + } else { + // panic("gui.makeNode() before Append()") + parent.Append(&node) + // panic("gui.makeNode() after Append()") } - Data.NodeMap[title] = &node - Data.NodeArray = append(Data.NodeArray, &node) - Data.NodeSlice = append(Data.NodeSlice, &node) - return &node - // parent.Append(&node) - //node.parent = parent + node.parent = parent return &node } @@ -86,19 +116,15 @@ func (n *Node) AddNode(title string) *Node { } func (n *Node) uiNewWindow(title string, x int, y int) { - w := ui.NewWindow(title, x, y, Config.Menu) + w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) f := Config.Exit w.OnClosing(func(*ui.Window) bool { - log.Println("RUNNING the ui.Window().OnClosing() function") + if (Config.Debug) { + log.Println("ui.Window().OnClosing()") + } if (f != nil) { f(n) - } else { - n.Dump() - log.Println("gui.uiWindow().OnClosing() NOT SURE WHAT TO DO HERE") - // TODO: always do this here? // by default delete the node? - name := n.Name - delete(Data.NodeMap, name) } return true }) @@ -109,16 +135,43 @@ func (n *Node) uiNewWindow(title string, x int, y int) { return } -/* func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) + if Data.WindowMap[title] != nil { + log.Println("Data.WindowMap[title] already exists title =", title) + title = title + Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + } + if Data.WindowMap[title] != nil { + log.Println("Data.WindowMap[title] already exists title =", title) + panic("Data.WindowMap[newGuiWindow.Name] already exists") + return nil + } + + var newGuiWindow GuiWindow + newGuiWindow.Width = x + newGuiWindow.Height = y + newGuiWindow.Name = title + newGuiWindow.UiWindow = window + + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + + Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + + var box GuiBox + box.Window = &newGuiWindow + box.Name = title node := makeNode(parent, title, x, y) + node.box = &box node.uiWindow = window + box.node = node + + newGuiWindow.BoxMap["jcarrInitTest"] = &box return node } -*/ // This routine creates a blank window with a Title and size (W x H) // @@ -126,29 +179,17 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod // it can be passed via the 'andlabs/ui' queue which, because it is // cross platform, must pass UI changes into the OS threads (that is // my guess). -// -// There is probably some way to pass arguements here that I'm can't think of right now -// func NewWindow() *Node { title := Config.Title w := Config.Width h := Config.Height - if (Data.NodeMap[title] != nil) { - log.Println("Duplicate window name =", title) - Data.NodeMap[title].Dump() - Data.NodeMap[title].ListChildren(false) - uiW := Data.NodeMap[title].uiWindow - if (uiW != nil) { - uiW.Show() - } - log.Println("PROBABLY BAD ERROR: check here to see if window is really alive") - return Data.NodeMap[title] - } - var n *Node - n = initNode(title, w, h) - n.uiNewWindow(title, w, h) + n = mapWindow(nil, nil, title, w, h) + box := n.box + log.Println("gui.NewWindow() title = box.Name =", box.Name) + + n.uiNewWindow(box.Name, w, h) window := n.uiWindow f := Config.Exit @@ -160,9 +201,9 @@ func NewWindow() *Node { return true }) - n.uiWindow = window + box.Window.UiWindow = window if(n.uiWindow == nil) { - log.Println("ERROR: node.uiWindow == nil. This should never happen") + panic("node.uiWindow == nil. This should never happen") } return n } From 390556e083c05144452ef5742dddc90c576f08de Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 11 Oct 2022 11:25:46 -0500 Subject: [PATCH 112/113] Change Node to Box --- area.go | 58 ++++++--- box.go | 203 +++++++++++++++++++++++++++++--- button.go | 159 +++++++++++++++++++------ cmds/gui-example/demo-window.go | 4 +- cmds/helloworld/main.go | 27 +++++ debug-window.go | 172 ++++++++++++++++++++++++++- debug.go | 90 +++++++++++++- demo-window.go | 68 +---------- doc.go | 30 +++-- entry.go | 104 +++++++++++++--- find.go | 59 ++++++++++ go.mod | 9 +- go.sum | 8 +- gui.go | 6 +- new-structs.go | 111 +++++------------ structs.go | 176 +++++++++++++++++++++++++-- table.go | 14 +-- tableCallbacks.go | 9 +- window.go | 159 +++++++++++++++---------- 19 files changed, 1127 insertions(+), 339 deletions(-) create mode 100644 cmds/helloworld/main.go diff --git a/area.go b/area.go index c4e0cae..7c42c6c 100644 --- a/area.go +++ b/area.go @@ -7,14 +7,28 @@ import _ "github.com/andlabs/ui/winmanifest" import "github.com/davecgh/go-spew/spew" -// make this button just to get the default font (but don't display the button) -// There should be another way to do this (?) -func (n *Node) makeGenericArea(newText *ui.AttributedString, custom func(*Node)) { - newNode := n.CreateFontButton("AREA") - newNode.custom = custom - area := new(GuiArea) - newNode.uiArea = ui.NewArea(area) - newNode.uiAttrstr = newText +func makeGenericArea(gb *GuiBox, newText *ui.AttributedString, custom func(*GuiButton)) { + // make this button just to get the default font (but don't display the button) + // There should be another way to do this (?) + var newB *GuiButton + newB = CreateFontButton(gb, "AREA") + newB.Box = gb + newB.Custom = custom + + gw := gb.Window + // initialize the GuiArea{} + gw.Area = new(GuiArea) + gw.Area.Button = newB + gw.Area.Box = gb + gw.Area.UiAttrstr = newText + gw.Area.UiArea = ui.NewArea(gw.Area) + + if (Config.Debug) { + spew.Dump(gw.Area.UiArea) + log.Println("DEBUGGING", Config.Debug) + } else { + log.Println("NOT DEBUGGING AREA mhAH.Button =", gw.Area.Button) + } } func AreaAppendText(newText *ui.AttributedString, what string, attrs ...ui.Attribute) { @@ -38,7 +52,7 @@ func appendWithAttributes(newText *ui.AttributedString, what string, attrs ...ui func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { tl := ui.DrawNewTextLayout(&ui.DrawTextLayoutParams{ String: ah.UiAttrstr, - DefaultFont: ah.N.uiFontButton.Font(), + DefaultFont: ah.Button.FB.Font(), Width: p.AreaWidth, Align: ui.DrawTextAlign(1), }) @@ -47,7 +61,6 @@ func (ah GuiArea) Draw(a *ui.Area, p *ui.AreaDrawParams) { } func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { - /* if (Config.Debug) { log.Println("GOT MouseEvent() ah.Button =", ah.Button) spew.Dump(me) @@ -67,7 +80,6 @@ func (ah GuiArea) MouseEvent(a *ui.Area, me *ui.AreaMouseEvent) { Data.MouseClick(ah.Button) } } - */ } func (ah GuiArea) MouseCrossed(a *ui.Area, left bool) { @@ -95,14 +107,30 @@ func (ah GuiArea) KeyEvent(a *ui.Area, ke *ui.AreaKeyEvent) (handled bool) { return false } -func (n *Node) ShowTextBox(newText *ui.AttributedString, custom func(*Node), name string) { +func (b *GuiBox) ShowTextBox(newText *ui.AttributedString, custom func(*GuiButton), name string) { log.Println("ShowTextBox() START") + gw := b.Window + if (gw == nil) { + log.Println("ShowTextBox() ERROR gw = nil") + return + } + log.Println("ShowTextBox() START gw =", gw) + + /* + var newbox *GuiBox + newbox = new(GuiBox) + newbox.Window = gw + newbox.Name = name + hbox := ui.NewVerticalBox() + newbox.UiBox = hbox + */ + // TODO: allow padded & axis here - n.uiBox.SetPadded(true) + b.UiBox.SetPadded(true) // add(gw.BoxMap["MAINBOX"], newbox) - n.makeGenericArea(newText, custom) - n.uiBox.Append(n.area.UiArea, true) + makeGenericArea(b, newText, custom) + b.UiBox.Append(b.Window.Area.UiArea, true) } diff --git a/box.go b/box.go index 67c0c05..7a61f55 100644 --- a/box.go +++ b/box.go @@ -1,7 +1,7 @@ package gui import "log" -// import "os" +import "os" // import "reflect" import "github.com/andlabs/ui" @@ -9,17 +9,190 @@ import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" +// add(nil, newbox, "") // use this when the Window is created. Always called 'MAINBOX' +// add(gw.BoxMap["MAINBOX"], newbox, name) // use this to add a box off the main box +// add(gw.BoxMap["BUTTONBOX"], newbox, name) // use this to add something to the box called 'BUTTONBOX' +// add(box, newbox, name) // add 'newbox' to 'box' and call it 'name' +func add(box *GuiBox, newbox *GuiBox) { + log.Println("gui.add() START box =", box) + log.Println("gui.add() START newbox =", newbox) + if (box == nil) { + log.Println("\tgui.add() add to Window as MAINBOX") + if (newbox.Window.UiTab != nil) { + // create a new tab here + // add the box to it as MAINBOX + log.Println("\tgui.add() add to Window as a UiTab") + // TODO: allow passing where to append + // newbox.Window.UiTab.InsertAt(newbox.Name, 0, newbox.UiBox) + newbox.Window.UiTab.Append(newbox.Name, newbox.UiBox) + // newbox.Window.UiTab.SetMargined(0, true) + + // TODO: figure out how to make a new Tab/Window/Box here + // window := InitGuiWindow(Data.Config, newbox.Name, gw.MakeWindow, gw.UiWindow, gw.UiTab) + // window.UiTab.Delete(0) + // window.MakeWindow(window) + // newbox.Window = window + + newbox.Window.BoxMap["MAINBOX"] = newbox + log.Println("gui.add() END") + panic("gui.add() MAINBOX gui.add() END") + return + } else { + log.Println("\tgui.add() ERROR DONT KNOW HOW TO ADD TO A RAW WINDOW YET") + // add this to the window + } + log.Println("\tgui.add() ERROR DON'T KNOW HOW TO add to Window as MAINBOX DONE") + log.Println("gui.add() END") + panic("gui.add() gui.add() END") + return + } + log.Println("\tgui.add() adding", newbox.Name, "to", box.Name) + // copy the box settings over + newbox.Window = box.Window + if (box.node == nil) { + box.Dump() + panic("gui.add() ERROR box.node == nil") + } + + if (newbox.UiBox == nil) { + panic("gui.add() ERROR newbox.UiBox == nil") + } + + if (box.UiBox == nil) { + box.Dump() + // panic("gui.add() ERROR box.UiBox == nil") + return + // TODO: fix this whole add() function // Oct 9 + } + box.UiBox.Append(newbox.UiBox, false) + box.Dump() + panic("gui.add()") + + // add the newbox to the Window.BoxMap[] + box.Window.BoxMap[newbox.Name] = newbox + log.Println("gui.add() END") +} + +func (n *Node) AddBox(axis int, name string) *Node { + newBox := new(GuiBox) + newBox.Window = n.window + newBox.Name = name + + if (n.box == nil) { + n.box = newBox + } + + // make a new box & a new node + newNode := n.makeNode(name, 111, 100 + Config.counter) + newNode.box = newBox + Config.counter += 1 + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newBox.UiBox = uiBox + newNode.uiBox = uiBox + + n.Append(newNode) + // add(n.box, newBox) + return newNode +} + +func (b *GuiBox) NewBox(axis int, name string) *GuiBox { + log.Println("gui.NewBox() START") + n := b.FindNode() + if (n == nil) { + log.Println("gui.NewBox() SERIOUS ERROR. CAN NOT FIND NODE") + os.Exit(0) + } else { + log.Println("gui.NewBox() node =", n.Name) + } + var newbox *GuiBox + newbox = new(GuiBox) + newbox.Window = b.Window + newbox.Name = name + + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + newbox.UiBox = uiBox + add(b, newbox) + // panic("gui.NewBox") + return newbox +} + +func HardBox(gw *GuiWindow, axis int, name string) *GuiBox { + log.Println("HardBox() START axis =", axis) + + if (gw.node == nil) { + gw.Dump() + panic("gui.HardBox() gw.node == nil") + } + // add a Vertical Seperator if there is already a box + // Is this right? + box := gw.BoxMap["MAINBOX"] + if (box != nil) { + if (axis == Xaxis) { + VerticalBreak(box) + } else { + HorizontalBreak(box) + } + } + + // make the new vbox + var uiBox *ui.Box + if (axis == Xaxis) { + uiBox = ui.NewHorizontalBox() + } else { + uiBox = ui.NewVerticalBox() + } + uiBox.SetPadded(true) + + // Init a new GuiBox + newbox := new(GuiBox) + newbox.Window = gw + newbox.UiBox = uiBox + newbox.Name = name + + add(gw.BoxMap["MAINBOX"], newbox) + + log.Println("HardBox END") + return newbox +} + +func HorizontalBreak(box *GuiBox) { + log.Println("VerticalSeparator added to box =", box.Name) + tmp := ui.NewHorizontalSeparator() + if (box == nil) { + return + } + if (box.UiBox == nil) { + return + } + box.UiBox.Append(tmp, false) +} + +func VerticalBreak(box *GuiBox) { + log.Println("VerticalSeparator added to box =", box.Name) + tmp := ui.NewVerticalSeparator() + box.UiBox.Append(tmp, false) +} + func (n *Node) AddComboBox(title string, s ...string) *Node { - newNode := n.AddNode(title) box := n.uiBox if (box == nil) { return n } ecbox := ui.NewEditableCombobox() - newNode.uiText = ecbox - // newNode.Dump() - // log.Println("ecbox", ecbox) for id, name := range s { log.Println("Adding Combobox Entry:", id, name) @@ -28,23 +201,21 @@ func (n *Node) AddComboBox(title string, s ...string) *Node { ecbox.OnChanged(func(*ui.EditableCombobox) { test := ecbox.Text() - log.Println("node.Name = '" + newNode.Name + "' text for '" + title + "' is now: '" + test + "'") - if (newNode.OnChanged == nil) { - log.Println("Not doing custom OnChanged since OnChanged == nil") - newNode.Dump() - } else { - newNode.OnChanged() - } + log.Println("node.Name = '" + n.Name + "' text for '" + title + "' is now: '" + test + "'") }) - box.Append(ecbox, Config.Stretchy) + box.Append(ecbox, false) + + newNode := n.AddNode(title) + newNode.uiText = ecbox return newNode } +func (n *Node) OnChanged(f func()) { + f() +} + func (n *Node) GetText() string { - if (n.uiMultilineEntry != nil) { - return n.uiMultilineEntry.Text() - } if (n.uiText == nil) { return "" } diff --git a/button.go b/button.go index 755d9ab..8ad0a3b 100644 --- a/button.go +++ b/button.go @@ -2,14 +2,11 @@ package gui import "log" import "reflect" -// import "image/color" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" // import "github.com/davecgh/go-spew/spew" -// TODO: bring this generic mouse click function back -// // This is the default mouse click handler // Every mouse click that hasn't been assigned to // something specific will fall into this routine @@ -19,7 +16,41 @@ import _ "github.com/andlabs/ui/winmanifest" // This routine MUST be here as this is how the andlabs/ui works // This is the raw routine passed to every button in andlabs libui / ui // +// There is a []GuiButton which has all the buttons. We search +// for the button and then call the function below // +func defaultButtonClick(button *ui.Button) { + log.Println("gui.defaultButtonClick() LOOK FOR BUTTON button =", button) + for key, foo := range Data.AllButtons { + if (Config.Debug) { + log.Println("gui.defaultButtonClick() Data.AllButtons =", key, foo) + // spew.Dump(foo) + } + if Data.AllButtons[key].B == button { + log.Println("\tgui.defaultButtonClick() BUTTON MATCHED") + guiButtonClick(Data.AllButtons[key]) + return + } + } + log.Println("\tgui.defaultButtonClick() ERROR: BUTTON NOT FOUND") + if (Config.Debug) { + panic("gui.defaultButtonClick() ERROR: UNMAPPED ui.Button") + } +} + +func guiButtonClick(button *GuiButton) { + log.Println("\tgui.guiButtonClick() button.Name =", button.Name) + if button.Custom != nil { + log.Println("\tgui.guiButtonClick() DOING CUSTOM FUNCTION") + button.Custom(button) + return + } + if (Data.MouseClick != nil) { + Data.MouseClick(button) + } else { + log.Println("\tgui.guiButtonClick() IGNORING BUTTON. MouseClick() is nil") + } +} func (n *Node) AddButton(name string, custom func(*Node)) *Node { if (n.uiBox == nil) { @@ -27,12 +58,9 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { return n } button := ui.NewButton(name) - if (Config.Debug) { - log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) - log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) - } - // true == expand, false == make normal size button - n.uiBox.Append(button, Config.Stretchy) + log.Println("reflect.TypeOF(uiBox) =", reflect.TypeOf(n.uiBox)) + log.Println("reflect.TypeOF(uiButton) =", reflect.TypeOf(button)) + n.uiBox.Append(button, false) n.uiButton = button newNode := n.makeNode(name, 888, 888 + Config.counter) @@ -43,40 +71,101 @@ func (n *Node) AddButton(name string, custom func(*Node)) *Node { log.Println("gui.AppendButton() Button Clicked. Running custom()") custom(newNode) }) + // panic("AppendButton") + // time.Sleep(3 * time.Second) return newNode } -func (n *Node) CreateFontButton(action string) *Node { - n.uiFontButton = ui.NewFontButton() +func (n *Node) CreateButton(custom func(*GuiButton), name string, values interface {}) *Node { + newNode := n.AddBox(Xaxis, "test CreateButton") + box := newNode.FindBox() + if (box == nil) { + panic("node.CreateButton().FindBox() == nil") + } + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) - n.uiFontButton.OnChanged(func (*ui.FontButton) { - log.Println("FontButton.OnChanged() START") - n.Dump() - }) - n.uiBox.Append(n.uiFontButton, Config.Stretchy) + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.UiBox == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } else { + // uibox := box.UiBox + // uibox.Append(newUiB, true) + } + newB.Box = box + newB.Custom = custom + newB.Values = values - // TODO: implement Grid - n.uiGrid = ui.NewGrid() - return n + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newNode } -func (n *Node) CreateColorButton(custom func(*Node), name string, values interface {}) *Node { - // create a 'fake' button entry for the mouse clicks - n.uiColorButton = ui.NewColorButton() - n.custom = custom - n.values = values +func CreateButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + newUiB := ui.NewButton(name) + newUiB.OnClicked(defaultButtonClick) - n.uiColorButton.OnChanged(func (*ui.ColorButton) { - log.Println("ColorButton.OnChanged() START Color Button Click") - rgba := n.Color - r, g, b, a := rgba.R, rgba.G, rgba.B, rgba.A - log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) - if (n.custom != nil) { - n.custom(n) - } else if (Data.MouseClick != nil) { - Data.MouseClick(n) + var newB *GuiButton + newB = new(GuiButton) + newB.B = newUiB + if (box.Window == nil) { + log.Println("CreateButton() box.Window == nil") + // ErrorWindow(box.Window, "Login Failed", msg) // can't even do this + panic("maybe print an error and return nil? or make a fake button?") + } + newB.Box = box + newB.Custom = custom + newB.Values = values + + Data.AllButtons = append(Data.AllButtons, newB) + + box.Append(newB.B, false) + return newB +} + +func CreateFontButton(box *GuiBox, action string) *GuiButton { + // create a 'fake' button entry for the mouse clicks + var newGB GuiButton + newGB.Name = "FONT" + newGB.FB = ui.NewFontButton() + newGB.Box = box + Data.AllButtons = append(Data.AllButtons, &newGB) + + newGB.FB.OnChanged(func (*ui.FontButton) { + log.Println("FontButton.OnChanged() START mouseClick(&newBM)", newGB) + if (Data.MouseClick != nil) { + Data.MouseClick(&newGB) } }) - n.uiBox.Append(n.uiColorButton, Config.Stretchy) - return n + return &newGB +} + +func CreateColorButton(box *GuiBox, custom func(*GuiButton), name string, values interface {}) *GuiButton { + // create a 'fake' button entry for the mouse clicks + var newCB GuiButton + newCB.Name = name + newCB.CB = ui.NewColorButton() + newCB.Box = box + newCB.Custom = custom + newCB.Values = values + + Data.AllButtons = append(Data.AllButtons, &newCB) + + newCB.CB.OnChanged(func (*ui.ColorButton) { + log.Println("ColorButton.OnChanged() START Color Button Click") + r, g, b, a := newCB.CB.Color() + log.Println("ColorButton.OnChanged() Color() =", r, g, b, a) + if (newCB.Custom != nil) { + newCB.Custom(&newCB) + } else if (Data.MouseClick != nil) { + Data.MouseClick(&newCB) + } + }) + box.Append(newCB.CB, false) + return &newCB } diff --git a/cmds/gui-example/demo-window.go b/cmds/gui-example/demo-window.go index f01c1a9..993900d 100644 --- a/cmds/gui-example/demo-window.go +++ b/cmds/gui-example/demo-window.go @@ -33,9 +33,9 @@ func addDemoTab(n *gui.Node, title string) { groupNode1 := newNode.AddGroup("group 1") cbNode := groupNode1.AddComboBox("username", "root", "jcarr", "hugo") - cbNode.OnChanged = func () { + cbNode.OnChanged(func () { username = cbNode.GetText() - } + }) groupNode1.AddComboBox("demoCombo3", "foo 3", "bar", "stuff") groupNode1.Dump() diff --git a/cmds/helloworld/main.go b/cmds/helloworld/main.go new file mode 100644 index 0000000..1cb1bbd --- /dev/null +++ b/cmds/helloworld/main.go @@ -0,0 +1,27 @@ +// This creates a simple hello world window +package main + +import ( + "git.wit.org/wit/gui" +) + +func main() { + gui.Main(initGUI) +} + +// This initializes the first window +func initGUI() { + gui.Config.Title = "Hello World golang wit/gui Window" + gui.Config.Width = 640 + gui.Config.Height = 480 + node1 := gui.NewWindow() + addDemoTab(node1, "A Simple Tab Demo") + addDemoTab(node1, "A Second Tab") +} + +func addDemoTab(n *gui.Node, title string) { + newNode := n.AddTab(title, nil) + + groupNode1 := newNode.AddGroup("group 1") + groupNode1.AddComboBox("demoCombo2", "more 1", "more 2", "more 3") +} diff --git a/debug-window.go b/debug-window.go index 72272ec..19f276d 100644 --- a/debug-window.go +++ b/debug-window.go @@ -7,7 +7,7 @@ import ( "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" -// "github.com/davecgh/go-spew/spew" + "github.com/davecgh/go-spew/spew" ) var names = make([]string, 100) @@ -33,6 +33,126 @@ func makeWindowDebug() *ui.Box { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) + ///////////////////////////////////////////////////// + vbox := addGroup(hbox, "range Data.WindowMap") + cbox := ui.NewCombobox() + + for name, _ := range Data.WindowMap { + if (Config.Debug) { + log.Println("range Data.WindowMap() name =", name) + } + addName(cbox, name) + } + cbox.SetSelected(0) + + vbox.Append(cbox, false) + + cbox.OnSelected(func(*ui.Combobox) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) + }) + + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Debug Window") + + b1 := addButton(vbox, "dumpBox(window)") + b1.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("names[x] =", names[x]) + dumpBox(names[x]) + }) + + b2 := addButton(vbox, "SetMargined(tab)") + b2.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + if gw.TabNumber == nil { + return + } + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(gw) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", gw.UiTab) + log.Println("gui.DumpBoxes()\tWindow.TabNumber =", *gw.TabNumber) + gw.UiTab.SetMargined(*gw.TabNumber, true) + }) + + b3 := addButton(vbox, "Hide(tab)") + b3.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + gw.UiTab.Hide() + }) + + b4 := addButton(vbox, "Show(tab)") + b4.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + gw.UiTab.Show() + }) + + b5 := addButton(vbox, "Delete(tab)") + b5.OnClicked(func(*ui.Button) { + x := cbox.Selected() + log.Println("x =", x) + log.Println("FindWindow; names[x] =", names[x]) + gw := FindWindow(names[x]) + if gw == nil { + return + } + if gw.UiTab == nil { + return + } + if gw.TabNumber == nil { + return + } + gw.UiTab.Delete(*gw.TabNumber) + }) + + ///////////////////////////////////////////////////// + vbox = addGroup(hbox, "Global Debug") + + dump3 := addButton(vbox, "Dump Windows") + dump3.OnClicked(func(*ui.Button) { + DumpWindows() + }) + + dump2 := addButton(vbox, "Dump Boxes") + dump2.OnClicked(func(*ui.Button) { + DumpBoxes() + }) + + dump1 := addButton(vbox, "Dump MAP") + dump1.OnClicked(func(*ui.Button) { + DumpMap() + }) + ///////////////////////////////////////////////////// nodeBox := addGroup(hbox, "Windows:") nodeCombo := ui.NewCombobox() @@ -46,7 +166,7 @@ func makeWindowDebug() *ui.Box { } nodeCombo.SetSelected(0) - nodeBox.Append(nodeCombo, Config.Stretchy) + nodeBox.Append(nodeCombo, false) nodeCombo.OnSelected(func(*ui.Combobox) { y := nodeCombo.Selected() @@ -59,7 +179,7 @@ func makeWindowDebug() *ui.Box { }) ///////////////////////////////////////////////////// - vbox := addGroup(hbox, "Node Debug") + vbox = addGroup(hbox, "Node Debug") n1 := addButton(vbox, "Data.DumpNodeMap()") n1.OnClicked(func(*ui.Button) { @@ -148,7 +268,7 @@ func addName(c *ui.Combobox, s string) { func addGroup(b *ui.Box, name string) *ui.Box { group := ui.NewGroup(name) group.SetMargined(true) - b.Append(group, Config.Stretchy) + b.Append(group, true) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -157,6 +277,48 @@ func addGroup(b *ui.Box, name string) *ui.Box { return vbox } +func dumpBox(s string) { + var name string + var window *GuiWindow + + for name, window = range Data.WindowMap { + if name != s { + continue + } + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + log.Println("gui.dumpBox() BoxMap START") + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + abox.Dump() + if name == "MAINBOX" { + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(abox.UiBox) + } + } + } + log.Println("gui.dumpBox() BoxMap END") + if window.UiTab != nil { + pages := window.UiTab.NumPages() + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) + tabSetMargined(window.UiTab) + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } + } + } +} + func addButton(box *ui.Box, name string) *ui.Button { button := ui.NewButton(name) @@ -164,7 +326,7 @@ func addButton(box *ui.Box, name string) *ui.Button { log.Println("Should do something here") }) - box.Append(button, Config.Stretchy) + box.Append(button, false) return button } diff --git a/debug.go b/debug.go index c895e01..0b0baa4 100644 --- a/debug.go +++ b/debug.go @@ -5,7 +5,7 @@ import ( "log" "time" - // "github.com/davecgh/go-spew/spew" + "github.com/davecgh/go-spew/spew" ) // WatchGUI() opens a goroutine @@ -22,7 +22,7 @@ func WatchGUI() { if count > 20 { log.Println("Sleep() in watchGUI()") if Config.Debug { - // DumpBoxes() + DumpBoxes() } count = 0 } @@ -31,6 +31,71 @@ func WatchGUI() { } } +func DumpWindows() { + for name, _ := range Data.WindowMap { + log.Println("gui.DumpWindows() window =", name) + } +} + +func DumpMap() { + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + log.Println("gui.DumpBoxes() BOXES:", name) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + } + } +} + +func DumpBoxes() { + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + } + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + // log.Println("gui.DumpBoxes()\tWindow.UiWindow type =", reflect.TypeOf(window.UiWindow)) + log.Println("gui.DumpBoxes()\tWindow.UiWindow =", window.UiWindow) + log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + if name == "MAINBOX" { + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 1} + scs.Dump(abox.UiBox) + } + } + } + if window.UiTab != nil { + // log.Println("gui.DumpBoxes()\tWindow.UiTab type =", reflect.TypeOf(window.UiTab)) + // log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) + pages := window.UiTab.NumPages() + log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) + // for i := 0; i < pages; i++ { + // log.Println("gui.DumpBoxes()\t\tWindow.UiTab.Margined(", i, ") =", window.UiTab.Margined(i)) + // } + // tmp := spew.NewDefaultConfig() + // tmp.MaxDepth = 2 + // tmp.Dump(window.UiTab) + if Config.Debug { + scs := spew.ConfigState{MaxDepth: 2} + scs.Dump(window.UiTab) + } + } + } + /* + for i, window := range Data.Windows { + if (window.TabNumber == nil) { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() Data.Windows", i, "Name =", window.Name, "TabNumber =", *window.TabNumber) + } + } + */ +} + func addTableTab() { var parts []TableColumnData @@ -61,6 +126,24 @@ func (dn *GuiData) DumpNodeMap() { } } +/* +func DebugDataNodeChildren() { + if Data.NodeMap == nil { + log.Println("DebugDataNodeChildren() NodeMap == nil") + return + } + log.Println("DebugDataNodeChildren():") + for name, node := range Data.NodeMap { + log.Println("\tNode name =", node.Width, node.Height, name) + if (node.children == nil) { + log.Println("\t\tNo children") + break + } + log.Println("\t\tHas children:", node.children) + } +} +*/ + func (dn *GuiData) ListChildren(dump bool) { if Data.NodeMap == nil { log.Println("gui.Data.ListChildren() Data.NodeMap == nil") @@ -68,9 +151,8 @@ func (dn *GuiData) ListChildren(dump bool) { } log.Println("gui.Data.ListChildren() Data.NodeMap:") for name, node := range Data.NodeMap { - listChildrenDepth = 0 + log.Println("\tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) if (dump == true) { - log.Println("tgui.Data.ListChildren() node =", node.id, node.Width, node.Height, name) node.Dump() } node.ListChildren(dump) diff --git a/demo-window.go b/demo-window.go index 6cbb5fd..16566c4 100644 --- a/demo-window.go +++ b/demo-window.go @@ -1,6 +1,6 @@ package gui -import "log" +// import "log" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -16,7 +16,7 @@ func (n *Node) AddGroup(title string) *Node { } group := ui.NewGroup(title) group.SetMargined(true) - hbox.Append(group, Config.Stretchy) + hbox.Append(group, true) vbox := ui.NewVerticalBox() vbox.SetPadded(true) @@ -26,67 +26,3 @@ func (n *Node) AddGroup(title string) *Node { newNode.uiBox = vbox return newNode } - -func (n *Node) MakeBasicControlsPage(title string) *Node { - if (n == nil) { - return nil - } - origbox := n.uiBox - if (origbox == nil) { - return n - } - - vbox := ui.NewVerticalBox() - vbox.SetPadded(true) - - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - vbox.Append(hbox, false) - - hbox.Append(ui.NewButton("Button"), false) - hbox.Append(ui.NewCheckbox("Checkbox"), false) - - vbox.Append(ui.NewLabel("This is a label. Right now, labels can only span one line."), false) - - vbox.Append(ui.NewHorizontalSeparator(), false) - - group := ui.NewGroup("Entries") - group.SetMargined(true) - vbox.Append(group, true) - - group.SetChild(ui.NewNonWrappingMultilineEntry()) - - entryForm := ui.NewForm() - entryForm.SetPadded(true) - group.SetChild(entryForm) - - entryForm.Append("Entry", ui.NewEntry(), false) - entryForm.Append("Password Entry", ui.NewPasswordEntry(), false) - entryForm.Append("Search Entry", ui.NewSearchEntry(), false) - entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true) - entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true) - - origbox.Append(vbox, false) - newNode := n.AddNode(title) - newNode.uiBox = vbox - return newNode -} - -func (n *Node) MakeGroupEdit(title string) *Node { - n.Dump() - - group := ui.NewGroup(title) - group.SetMargined(true) - n.uiBox.Append(group, Config.Stretchy) - - entrybox := ui.NewNonWrappingMultilineEntry() - - group.SetChild(entrybox) - - log.Println("entrybox =", entrybox) - n.uiMultilineEntry = entrybox - newNode := n.AddNode(title) - newNode.uiMultilineEntry = entrybox - newNode.uiGroup = group - return newNode -} diff --git a/doc.go b/doc.go index 3f8bc64..35c6a8f 100644 --- a/doc.go +++ b/doc.go @@ -1,7 +1,6 @@ /* -Package wit/gui implements a abstraction layer for Go visual elements in -a cross platform way. Right now, this abstraction is built on top of -the GUI toolkit 'andlabs/ui' which does the cross platform support. +Package gui implements a abstraction layer for Go visual elements in +a cross platform way. A quick overview of the features, some general design guidelines and principles for how this package should generally work: @@ -15,9 +14,7 @@ Quick Start This section demonstrates how to quickly get started with spew. See the sections below for further details on formatting and configuration options. -To dump a variable with full newlines, indentation, type, and pointer -information use Dump, Fdump, or Sdump: - + // This creates a simple hello world window package main import ( @@ -30,11 +27,12 @@ information use Dump, Fdump, or Sdump: // This initializes the first window func initGUI() { - gui.Config.Title = "WIT GUI Window 1" + gui.Config.Title = "Hello World golang wit/gui Window" gui.Config.Width = 640 gui.Config.Height = 480 node1 := gui.NewWindow() addDemoTab(node1, "A Simple Tab Demo") + addDemoTab(node1, "A Second Tab") } func addDemoTab(n *gui.Node, title string) { @@ -60,10 +58,24 @@ The following configuration options are available: * Debug When 'true' log more output -GUI Usage +Toolkit Usage + +Right now, this abstraction is built on top of the go package 'andlabs/ui' +which does the cross platform support. +The next step is to intent is to allow this to work directly against GTK and QT. +It should be able to add Fyne, WASM, native macos & windows, android, etc. Errors -Not sure about errors yet. To early to document them. This is a work in progress. +Since it is possible for custom Stringer/error interfaces to panic, spew +detects them and handles them internally by printing the panic information +inline with the output. Since spew is intended to provide deep pretty printing +capabilities on structures, it intentionally does not return any errors. + +Debugging + +To dump variables with full newlines, indentation, type, and pointer +information this uses spew.Dump() + */ package gui diff --git a/entry.go b/entry.go index 524609f..c10b7d0 100644 --- a/entry.go +++ b/entry.go @@ -1,25 +1,45 @@ package gui import "log" -import "errors" -// import "fmt" +import "fmt" import "github.com/andlabs/ui" -// import ui "git.wit.org/interesting/andlabs-ui" import _ "github.com/andlabs/ui/winmanifest" -// import "github.com/davecgh/go-spew/spew" +import "github.com/davecgh/go-spew/spew" // functions for handling text entry boxes +func NewLabel(box *GuiBox, text string) { + box.Append(ui.NewLabel(text), false) +} + func (n *Node) NewLabel(text string) *Node { // make new node here -newNode := n.makeNode(text, 333, 334) + // n.Append(ui.NewLabel(text), false) + newNode := makeNode(n, text, 333, 334) newNode.Dump() + // panic("node.NewLabel()") n.Append(newNode) return newNode } +func (b *GuiBox) GetText(name string) string { + if (b.Window.EntryMap == nil) { + log.Println("gui.GetText() ERROR b.Box.Window.EntryMap == nil") + return "" + } + spew.Dump(b.Window.EntryMap) + if (b.Window.EntryMap[name] == nil) { + log.Println("gui.GetText() ERROR box.Window.EntryMap[", name, "] == nil ") + return "" + } + e := b.Window.EntryMap[name] + log.Println("gui.GetText() box.Window.EntryMap[", name, "] = ", e.UiEntry.Text()) + log.Println("gui.GetText() END") + return e.UiEntry.Text() +} + func (n *Node) SetText(value string) error { log.Println("gui.SetText() value =", value) if (n.uiText != nil) { @@ -30,20 +50,72 @@ func (n *Node) SetText(value string) error { 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") + return nil } -func (n *Node) SetMargined(x bool) { - if (n.uiGroup != nil) { - n.uiGroup.SetMargined(x) - return +func SetText(box *GuiBox, name string, value string) error { + if (box == nil) { + return fmt.Errorf("gui.SetText() ERROR box == nil") } - log.Println("Couldn't find something that has a Margin setting") + 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 { + hboxN := ui.NewHorizontalBox() + hboxN.SetPadded(true) + hboxN.Append(ui.NewLabel(a), false) + + e := defaultMakeEntry(startValue, edit, action) + hboxN.Append(e.UiEntry, true) + + box.UiBox.Append(hboxN, true) + + 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 } func defaultEntryChange(e *ui.Entry) { diff --git a/find.go b/find.go index 15f2714..e046161 100644 --- a/find.go +++ b/find.go @@ -17,6 +17,65 @@ func (n *Node) FindControl() *ui.Control { return n.uiControl } +func (n *Node) FindBox() *GuiBox { + if (n.box != nil) { + return n.box + } + if (n.parent != nil) { + p := n.parent + return p.box + } + return n.box +} + +func (n *Node) FindWindowBox() *GuiBox { + if (n.box == nil) { + panic("SERIOUS ERROR n.box == nil in FindWindowBox()") + } + return n.box +} + +func (w *GuiWindow) FindNode() *Node { + return w.node +} + +func (b *GuiBox) FindNode() *Node { + log.Println("gui.FindNode() on GuiBox") + if b.node != nil { + return b.node + } + Data.ListChildren(true) + b.Dump() + log.Println("gui.FindNode() on GuiBox is nil") + os.Exit(-1) + return nil +} + +func FindWindow(s string) *GuiWindow { + for name, window := range Data.WindowMap { + if name == s { + return window + } + } + log.Printf("COULD NOT FIND WINDOW " + s) + return nil +} + +func FindBox(s string) *GuiBox { + for name, window := range Data.WindowMap { + if name != s { + continue + } + for name, abox := range window.BoxMap { + log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) + return abox + } + log.Println("gui.FindBox() NEED TO INIT WINDOW name =", name) + } + log.Println("gui.FindBox() COULD NOT FIND BOX", s) + return nil +} + func FindNode(name string) *Node { if Data.NodeMap == nil { log.Println("gui.FindNode() gui.Data.NodeMap == nil") diff --git a/go.mod b/go.mod index 18a5b64..c72bbca 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,9 @@ module git.wit.org/wit/gui -go 1.19 +go 1.17 require ( - git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e // indirect - github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect + github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e + github.com/davecgh/go-spew v1.1.1 + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d ) diff --git a/go.sum b/go.sum index dd2a245..27ff5d2 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,8 @@ -git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e h1:CTg83RH/Poy/HCBbBkRFIqKsdBSsHkLeED6XbMmzZzk= -git.wit.org/interesting/andlabs-ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:UuaKXIGj4crFE8XDWljgHTyKi8j4pSd9Vvn+zeHNjkQ= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e h1:wSQCJiig/QkoUnpvelSPbLiZNWvh2yMqQTQvIQqSUkU= github.com/andlabs/ui v0.0.0-20200610043537-70a69d6ae31e/go.mod h1:5G2EjwzgZUPnnReoKvPWVneT8APYbyKkihDVAHUi0II= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 h1:Lj6HJGCSn5AjxRAH2+r35Mir4icalbqku+CLUtjnvXY= -golang.org/x/image v0.0.0-20220902085622-e7cb96979f69/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/gui.go b/gui.go index ac75f1e..4174133 100644 --- a/gui.go +++ b/gui.go @@ -14,16 +14,18 @@ const Xaxis = 0 // box that is horizontal const Yaxis = 1 // box that is vertical func init() { - log.Println("gui.init() REMOVE THIS init()") + log.Println("gui.init() has been run") + Data.buttonMap = make(map[*ui.Button]*GuiButton) + Data.WindowMap = make(map[string]*GuiWindow) Data.NodeMap = make(map[string]*Node) + Data.NodeSlice = make([]*Node, 0) Config.counter = 0 Config.prefix = "wit" Config.DebugNode = false Config.DebugTabs = false - Config.Stretchy = true } func GuiInit() { diff --git a/new-structs.go b/new-structs.go index f806696..4f9989e 100644 --- a/new-structs.go +++ b/new-structs.go @@ -3,7 +3,6 @@ package gui import ( "log" "fmt" - "image/color" // "reflect" // "github.com/davecgh/go-spew/spew" @@ -45,29 +44,20 @@ type Node struct { Name string Width int Height int - OnChanged func () - Color color.RGBA parent *Node children []*Node - area *GuiArea + window *GuiWindow + box *GuiBox custom func(*Node) - values interface {} uiControl *ui.Control uiButton *ui.Button - uiFontButton *ui.FontButton - uiColorButton *ui.ColorButton uiWindow *ui.Window - uiAttrstr *ui.AttributedString - uiTab *ui.Tab - uiBox *ui.Box - uiArea *ui.Area - uiText *ui.EditableCombobox - uiMultilineEntry *ui.MultilineEntry - uiGroup *ui.Group - uiGrid *ui.Grid + uiTab *ui.Tab + uiBox *ui.Box + uiText *ui.EditableCombobox } func (n *Node) Parent() *Node { @@ -83,7 +73,6 @@ func (n *Node) Dump() { log.Println("gui.Node.Dump() Name = ", n.Name) log.Println("gui.Node.Dump() Width = ", n.Width) log.Println("gui.Node.Dump() Height = ", n.Height) - log.Println("gui.Node.Dump() OnChanged = ", n.OnChanged) if (n.parent == nil) { log.Println("gui.Node.Dump() parent = nil") @@ -92,20 +81,24 @@ func (n *Node) Dump() { } log.Println("gui.Node.Dump() children = ", n.children) - // log.Println("gui.Node.Dump() window = ", n.window) - // log.Println("gui.Node.Dump() box = ", n.box) + log.Println("gui.Node.Dump() window = ", n.window) + log.Println("gui.Node.Dump() box = ", n.box) log.Println("gui.Node.Dump() uiWindow = ", n.uiWindow) log.Println("gui.Node.Dump() uiTab = ", n.uiTab) log.Println("gui.Node.Dump() uiBox = ", n.uiBox) log.Println("gui.Node.Dump() uiControl = ", n.uiControl) log.Println("gui.Node.Dump() uiButton = ", n.uiButton) - log.Println("gui.Node.Dump() uiText = ", n.uiText) if (n.id == "") { - log.Println("THIS SHOULD NOT HAPPEN: gui.Node.Dump() id == nil") + panic("gui.Node.Dump() id == nil") } } + +func (n *Node) SetBox(box *GuiBox) { + n.box = box +} + func (n *Node) SetName(name string) { // n.uiType.SetName(name) if (n.uiWindow != nil) { @@ -138,22 +131,19 @@ func (n *Node) List() { var listChildrenParent *Node var listChildrenDepth int = 0 -// var indent string = "\t" -var indent string = " " - func indentPrintln(depth int, format string, a ...interface{}) { - var space string + var tabs string for i := 0; i < depth; i++ { - space = space + indent + tabs = tabs + "\t" } // newFormat := tabs + strconv.Itoa(depth) + " " + format - newFormat := space + format + newFormat := tabs + format log.Println(newFormat, a) } func (n *Node) ListChildren(dump bool) { - indentPrintln(listChildrenDepth, "", n.id, n.Width, n.Height, n.Name) + indentPrintln(listChildrenDepth, "\t", n.id, n.Width, n.Height, n.Name) if (dump == true) { n.Dump() @@ -212,13 +202,13 @@ func (n *Node) ListChildren(dump bool) { // // This function should make a new node with the parent and // the 'stuff' Node as a child -func (n *Node) AddTabNode(title string) *Node { +func (n *Node) AddTabNode(title string, b *GuiBox) *Node { var newNode *Node parent := n newNode = parent.makeNode(title, 444, 400 + Config.counter) newNode.uiTab = parent.uiTab - // newNode.box = b + newNode.box = b if (Config.DebugNode) { fmt.Println("") @@ -230,62 +220,16 @@ func (n *Node) AddTabNode(title string) *Node { newNode.Dump() } - if (newNode.uiTab != nil) { - log.Println("ERROR: wit/gui/ AddTabNode() Something went wrong tab == nil") + if (newNode.uiTab == nil) { + log.Println("wit/gui/ AddTabNode() Something went wrong tab == nil") // TODO: try to find the tab or window and make them if need be - // newNode.uiTab.Append(title, b.UiBox) + return newNode } + newNode.uiTab.Append(title, b.UiBox) return newNode } -func (n *Node) AddHorizontalBreak() *Node { - log.Println("AddHorizontalBreak added to node =", n.Name) - if (n.uiBox != nil) { - tmp := ui.NewHorizontalSeparator() - n.uiBox.Append(tmp, Config.Stretchy) - } else { - n.Dump() - return nil - } - return n -} - -func (n *Node) AddVerticalBreak() *Node { - log.Println("AddVerticalBreak added to node =", n.Name) - if (n.uiBox != nil) { - tmp := ui.NewVerticalSeparator() - n.uiBox.Append(tmp, Config.Stretchy) - } else { - n.Dump() - return nil - } - return n -} - -func (n *Node) AddHorizontalBox(title string) *Node { - hbox := ui.NewHorizontalBox() - hbox.SetPadded(true) - if (n.uiBox != nil) { - log.Println("add new hbox to uiBox =", n.uiBox) - n.uiBox.Append(hbox, Config.Stretchy) - newNode := n.makeNode(title, 333, 333 + Config.counter) - newNode.parent = n - newNode.uiBox = hbox - // newNode.uiControl = hbox - return newNode - } - if (n.uiTab != nil) { - log.Println("add new hbox to uiTab =", n.uiTab) - n.uiTab.Append(title, hbox) - newNode := n.makeNode(title, 333, 333 + Config.counter) - newNode.parent = n - newNode.uiBox = hbox - // newNode.uiControl = hbox - return newNode - } - return n -} func (n *Node) AddTab(title string, uiC *ui.Box) *Node { parent := n log.Println("gui.Node.AddTab() START name =", title) @@ -294,12 +238,20 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { log.Println("gui.Node.AddTab() ERROR ui.Window == nil") return nil } + if parent.box == nil { + parent.Dump() + panic("gui.AddTab() ERROR box == nil") + } if parent.uiTab == nil { inittab := ui.NewTab() // no, not that 'inittab' parent.uiWindow.SetChild(inittab) parent.uiWindow.SetMargined(true) parent.uiTab = inittab + + // parent.Dump() + // panic("gui.AddTab() ERROR uiTab == nil") } + tab := parent.uiTab parent.uiWindow.SetMargined(true) @@ -313,6 +265,7 @@ func (n *Node) AddTab(title string, uiC *ui.Box) *Node { newNode := parent.makeNode(title, 555, 600 + Config.counter) newNode.uiTab = tab newNode.uiBox = uiC + // panic("gui.AddTab() after makeNode()") tabSetMargined(newNode.uiTab) return newNode } diff --git a/structs.go b/structs.go index 79b3fbf..c15f4b7 100644 --- a/structs.go +++ b/structs.go @@ -2,7 +2,7 @@ package gui import ( "image/color" -// "log" + "log" "github.com/andlabs/ui" "golang.org/x/image/font" @@ -22,8 +22,6 @@ type GuiConfig struct { Title string Width int Height int - Stretchy bool - Menu bool Exit func(*Node) Debug bool @@ -40,15 +38,162 @@ type GuiConfig struct { type GuiData struct { // a fallback default function to handle mouse events // if nothing else is defined to handle them - MouseClick func(*Node) + MouseClick func(*GuiButton) // A map of all the entry boxes AllEntries []*GuiEntry + WindowMap map[string]*GuiWindow // Store access to everything via binary tree's NodeMap map[string]*Node NodeArray []*Node NodeSlice []*Node + + // A map of all buttons everywhere on all + // windows, all tabs, across all goroutines + // This is "GLOBAL" + // + // This has to work this way because of how + // andlabs/ui & andlabs/libui work + AllButtons []*GuiButton + buttonMap map[*ui.Button]*GuiButton +} + +type GuiTab struct { + Name string // field for human readable name + Number int // the andlabs/ui tab index + Window *GuiWindow // the parent Window +} + +// +// stores information on the 'window' +// +// This merges the concept of andlabs/ui *Window and *Tab +// +// More than one Window is not supported in a cross platform +// sense & may never be. On Windows and MacOS, you have to have +// 'tabs'. Even under Linux, more than one Window is currently +// unstable +// +// This code will make a 'GuiWindow' regardless of if it is +// a stand alone window (which is more or less working on Linux) +// or a 'tab' inside a window (which is all that works on MacOS +// and MSWindows. +// +// This struct keeps track of what is in the window so you +// can destroy and replace it with something else +// +type GuiWindow struct { + Name string // field for human readable name + Width int + Height int + Axis int // does it add items to the X or Y axis + TabNumber *int // the andlabs/ui tab index + + // the callback function to make the window contents + // MakeWindow func(*GuiBox) *GuiBox + + // the components of the window + BoxMap map[string]*GuiBox + EntryMap map[string]*GuiEntry + Area *GuiArea + + node *Node + + // andlabs/ui abstraction mapping + UiWindow *ui.Window + UiTab *ui.Tab // if this != nil, the window is 'tabbed' +} + +func (w *GuiWindow) Dump() { + log.Println("gui.GuiWindow.Dump() Name = ", w.Name) + log.Println("gui.GuiWindow.Dump() node = ", w.node) + log.Println("gui.GuiWindow.Dump() Width = ", w.Width) + log.Println("gui.GuiWindow.Dump() Height = ", w.Height) +} + +// GuiBox is any type of ui.Hbox or ui.Vbox +// There can be lots of these for each GuiWindow +type GuiBox struct { + Name string // field for human readable name + Axis int // does it add items to the X or Y axis + Window *GuiWindow // the parent Window + + node *Node + + // andlabs/ui abstraction mapping + UiBox *ui.Box +} + +func (b *GuiBox) Dump() { + log.Println("gui.GuiBox.Dump() Name = ", b.Name) + log.Println("gui.GuiBox.Dump() Axis = ", b.Axis) + log.Println("gui.GuiBox.Dump() GuiWindow = ", b.Window) + log.Println("gui.GuiBox.Dump() node = ", b.node) + log.Println("gui.GuiBox.Dump() UiBox = ", b.UiBox) +} + +func (b *GuiBox) SetTitle(title string) { + log.Println("DID IT!", title) + if b.Window == nil { + return + } + if b.Window.UiWindow == nil { + return + } + b.Window.UiWindow.SetTitle(title) + return +} + +func (w *GuiWindow) SetNode(n *Node) { + if (w.node != nil) { + w.Dump() + panic("gui.SetNode() Error not nil") + } + w.node = n + if (w.node == nil) { + w.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) SetNode(n *Node) { + if (b.node != nil) { + b.Dump() + panic("gui.SetNode() Error not nil") + } + b.node = n + if (b.node == nil) { + b.Dump() + panic("gui.SetNode() node == nil") + } +} + +func (b *GuiBox) Append(child ui.Control, x bool) { + if b.UiBox == nil { + panic("GuiBox.Append() can't work. UiBox == nil") + return + } + b.UiBox.Append(child, x) +} + +// Note: every mouse click is handled +// as a 'Button' regardless of where +// the user clicks it. You could probably +// call this 'GuiMouseClick' +type GuiButton struct { + Name string // field for human readable name + Box *GuiBox // what box the button click was in + + // a callback function for the main application + Custom func(*GuiButton) + Values interface{} + Color color.RGBA + + // andlabs/ui abstraction mapping + B *ui.Button + FB *ui.FontButton + CB *ui.ColorButton } // text entry fields @@ -58,14 +203,21 @@ type GuiEntry struct { Last string // the last value Normalize func(string) string // function to 'normalize' the data - N *Node + B *GuiButton + Box *GuiBox // andlabs/ui abstraction mapping UiEntry *ui.Entry } +// +// AREA STRUCTURES START +// AREA STRUCTURES START +// AREA STRUCTURES START +// type GuiArea struct { - N *Node // what node to pass mouse events + Button *GuiButton // what button handles mouse events + Box *GuiBox UiAttrstr *ui.AttributedString UiArea *ui.Area @@ -79,6 +231,14 @@ type FontString struct { } // +// AREA STRUCTURES END +// AREA STRUCTURES END +// AREA STRUCTURES END +// + +// +// TABLE DATA STRUCTURES START +// TABLE DATA STRUCTURES START // TABLE DATA STRUCTURES START // @@ -95,7 +255,7 @@ type TableData struct { Cells [20]CellData Human [20]HumanMap - n *Node + Box *GuiBox lastRow int lastColumn int @@ -122,7 +282,7 @@ type HumanCellData struct { TextID int Color color.RGBA ColorID int - N *Node + Button *GuiButton } type HumanMap struct { diff --git a/table.go b/table.go index 378cab2..92ae871 100644 --- a/table.go +++ b/table.go @@ -97,12 +97,13 @@ func InitColumns(mh *TableData, parts []TableColumnData) { } } -func AddTableTab(name string, rowcount int, parts []TableColumnData) *TableData { - n := NewWindow() - return n.AddTableBox(name, rowcount, parts) +func AddTableTab(gw *GuiWindow, name string, rowcount int, parts []TableColumnData) *TableData { + node := NewWindow() + b := node.box + return b.AddTableBox(name, rowcount, parts) } -func (n *Node) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { +func (b *GuiBox) AddTableBox(name string, rowcount int, parts []TableColumnData) *TableData { mh := new(TableData) mh.RowCount = rowcount @@ -141,10 +142,9 @@ func (n *Node) AddTableBox(name string, rowcount int, parts []TableColumnData) * // is this needed? // gw.BoxMap[name] = box - // mh.Box = b - mh.n = n + mh.Box = b - n.uiBox.Append(table, true) + b.UiBox.Append(table, true) return mh } diff --git a/tableCallbacks.go b/tableCallbacks.go index f294a9b..6eefd8d 100644 --- a/tableCallbacks.go +++ b/tableCallbacks.go @@ -95,12 +95,9 @@ func defaultSetCellValue(mh *TableData, row int, column int) { humanID := mh.Cells[column].HumanID log.Println("defaultSetCellValue() FOUND THE TABLE BUTTON ", row, humanID) - n := mh.Rows[row].HumanData[humanID].N - if (n != nil) { - // TODO: fixme. removed on Oct 31 2021 - if (n.OnChanged != nil) { - n.OnChanged() - } + button := mh.Rows[row].HumanData[humanID].Button + if (button != nil) { + guiButtonClick(button) return } log.Println("defaultSetCellValue() ERROR: UNKNOWN BUTTON IN TABLE") diff --git a/window.go b/window.go index 50f7073..403638e 100644 --- a/window.go +++ b/window.go @@ -2,36 +2,57 @@ package gui import ( "log" -// "fmt" + "fmt" "strconv" "github.com/andlabs/ui" _ "github.com/andlabs/ui/winmanifest" ) -func findUiWindow() *ui.Window { - for _, node := range Data.NodeMap { - if (node.uiWindow != nil) { - return node.uiWindow +func MessageWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBox(gw.UiWindow, msg1, msg2) +} + +func ErrorWindow(gw *GuiWindow, msg1 string, msg2 string) { + ui.MsgBoxError(gw.UiWindow, msg1, msg2) +} + +func DeleteWindow(name string) { + log.Println("gui.DeleteWindow() START name =", name) + window := Data.WindowMap[name] + if window == nil { + log.Println("gui.DeleteWindow() NO WINDOW WITH name =", name) + return + } + + log.Println("gui.DumpBoxes() MAP: ", name) + log.Println("gui.DumpBoxes()\tWindow.name =", window.Name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } + tab := *window.TabNumber + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", tab) + log.Println("gui.DumpBoxes() \tSHOULD DELETE TAB", tab, "HERE") + window.UiTab.Delete(tab) + delete(Data.WindowMap, name) + + // renumber tabs here + for name, window := range Data.WindowMap { + log.Println("gui.DumpBoxes() MAP: ", name) + if window.TabNumber == nil { + log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") + } else { + log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) + if tab < *window.TabNumber { + log.Println("gui.DumpBoxes() \tSubtracting 1 from TabNumber") + *window.TabNumber -= 1 + log.Println("gui.DumpBoxes() \tWindows.TabNumber is now =", *window.TabNumber) + } } } - return nil } -func MessageWindow(msg1 string, msg2 string) (*Node) { - uiW := findUiWindow() - ui.MsgBox(uiW, msg1, msg2) - // TODO: make new node - return nil -} - -func ErrorWindow(msg1 string, msg2 string) (*Node) { - uiW := findUiWindow() - ui.MsgBoxError(uiW, msg1, msg2) - return nil -} - -func initNode(title string, x int, y int) *Node { +func makeNode(parent *Node, title string, x int, y int) *Node { var node Node node.Name = title node.Width = x @@ -41,17 +62,26 @@ func initNode(title string, x int, y int) *Node { Config.counter += 1 node.id = id - if (Data.NodeMap[title] != nil) { - log.Println("ERROR: Duplicate window name =", title) - // TODO: just change the 'title' to something unique - return Data.NodeMap[title] + // panic("gui.makeNode() START") + if (parent == nil) { + if (Data.NodeMap[title] != nil) { + log.Println("Duplicate window name =", title) + // TODO: just change the 'title' to something unique + panic(fmt.Sprintf("Duplicate window name = %s\n", title)) + return nil + } + // panic("gui.makeNode() before NodeMap()") + Data.NodeMap[title] = &node + Data.NodeArray = append(Data.NodeArray, &node) + Data.NodeSlice = append(Data.NodeSlice, &node) + // panic("gui.makeNode() after NodeMap()") + return &node + } else { + // panic("gui.makeNode() before Append()") + parent.Append(&node) + // panic("gui.makeNode() after Append()") } - Data.NodeMap[title] = &node - Data.NodeArray = append(Data.NodeArray, &node) - Data.NodeSlice = append(Data.NodeSlice, &node) - return &node - // parent.Append(&node) - //node.parent = parent + node.parent = parent return &node } @@ -86,19 +116,15 @@ func (n *Node) AddNode(title string) *Node { } func (n *Node) uiNewWindow(title string, x int, y int) { - w := ui.NewWindow(title, x, y, Config.Menu) + w := ui.NewWindow(title, x, y, false) w.SetBorderless(false) f := Config.Exit w.OnClosing(func(*ui.Window) bool { - log.Println("RUNNING the ui.Window().OnClosing() function") + if (Config.Debug) { + log.Println("ui.Window().OnClosing()") + } if (f != nil) { f(n) - } else { - n.Dump() - log.Println("gui.uiWindow().OnClosing() NOT SURE WHAT TO DO HERE") - // TODO: always do this here? // by default delete the node? - name := n.Name - delete(Data.NodeMap, name) } return true }) @@ -109,16 +135,43 @@ func (n *Node) uiNewWindow(title string, x int, y int) { return } -/* func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node { log.Println("gui.WindowMap START title =", title) + if Data.WindowMap[title] != nil { + log.Println("Data.WindowMap[title] already exists title =", title) + title = title + Config.prefix + strconv.Itoa(Config.counter) + Config.counter += 1 + } + if Data.WindowMap[title] != nil { + log.Println("Data.WindowMap[title] already exists title =", title) + panic("Data.WindowMap[newGuiWindow.Name] already exists") + return nil + } + + var newGuiWindow GuiWindow + newGuiWindow.Width = x + newGuiWindow.Height = y + newGuiWindow.Name = title + newGuiWindow.UiWindow = window + + newGuiWindow.BoxMap = make(map[string]*GuiBox) + newGuiWindow.EntryMap = make(map[string]*GuiEntry) + + Data.WindowMap[newGuiWindow.Name] = &newGuiWindow + + var box GuiBox + box.Window = &newGuiWindow + box.Name = title node := makeNode(parent, title, x, y) + node.box = &box node.uiWindow = window + box.node = node + + newGuiWindow.BoxMap["jcarrInitTest"] = &box return node } -*/ // This routine creates a blank window with a Title and size (W x H) // @@ -126,29 +179,17 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod // it can be passed via the 'andlabs/ui' queue which, because it is // cross platform, must pass UI changes into the OS threads (that is // my guess). -// -// There is probably some way to pass arguements here that I'm can't think of right now -// func NewWindow() *Node { title := Config.Title w := Config.Width h := Config.Height - if (Data.NodeMap[title] != nil) { - log.Println("Duplicate window name =", title) - Data.NodeMap[title].Dump() - Data.NodeMap[title].ListChildren(false) - uiW := Data.NodeMap[title].uiWindow - if (uiW != nil) { - uiW.Show() - } - log.Println("PROBABLY BAD ERROR: check here to see if window is really alive") - return Data.NodeMap[title] - } - var n *Node - n = initNode(title, w, h) - n.uiNewWindow(title, w, h) + n = mapWindow(nil, nil, title, w, h) + box := n.box + log.Println("gui.NewWindow() title = box.Name =", box.Name) + + n.uiNewWindow(box.Name, w, h) window := n.uiWindow f := Config.Exit @@ -160,9 +201,9 @@ func NewWindow() *Node { return true }) - n.uiWindow = window + box.Window.UiWindow = window if(n.uiWindow == nil) { - log.Println("ERROR: node.uiWindow == nil. This should never happen") + panic("node.uiWindow == nil. This should never happen") } return n } From adb7d849f68f1b574e89b2cae585728f52b4c4e0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 11 Oct 2022 11:51:02 -0500 Subject: [PATCH 113/113] build without go.mod file --- cmds/gui-example/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmds/gui-example/Makefile b/cmds/gui-example/Makefile index 8718fd1..638cffc 100644 --- a/cmds/gui-example/Makefile +++ b/cmds/gui-example/Makefile @@ -2,4 +2,5 @@ run: build ./gui-example build: - go build + GO111MODULE="off" go -v get . + GO111MODULE="off" go build