From e796008fbdeced81a845eff3b00e8424bd5dbf72 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 7 Oct 2021 01:37:37 -0500 Subject: [PATCH 01/54] 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 02/54] 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 03/54] 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 04/54] 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 05/54] 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 06/54] 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 07/54] 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 08/54] 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 09/54] 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 10/54] 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 11/54] 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 12/54] 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 13/54] 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 14/54] 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 15/54] 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 16/54] 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 17/54] 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 18/54] 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 19/54] 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 20/54] 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 21/54] 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 22/54] 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 23/54] 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 24/54] 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 25/54] 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 26/54] 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 27/54] 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 28/54] 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 29/54] 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 30/54] 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 31/54] 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 32/54] 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 33/54] 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 34/54] 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 35/54] 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 36/54] 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 37/54] 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 38/54] 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 39/54] 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 40/54] 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 41/54] 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 42/54] 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 43/54] 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 44/54] 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 45/54] 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 46/54] 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 47/54] 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 48/54] 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 49/54] 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 50/54] 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 51/54] 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 52/54] 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 53/54] 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 54a402449f0d61ddec3a01c5e98bcf4503a7a959 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Oct 2022 19:31:35 -0500 Subject: [PATCH 54/54] 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