From b4a11c0aa1c14504121adbdbf02f418e7969d3f9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 08:36:28 -0500 Subject: [PATCH] CODE: start a general code refactor Signed-off-by: Jeff Carr --- main.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ new-structs.go | 29 +++++++++++++++++++++++++++++ structs.go | 1 + window-debug.go | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 main.go create mode 100644 new-structs.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..eb9bdb4 --- /dev/null +++ b/main.go @@ -0,0 +1,46 @@ +package gui + +import "log" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +func Main(f func()) { + log.Println("Starting gui.Main() (using gtk via andlabs/ui)") + ui.Main(f) +} + +// Other goroutines must use this +// +// You can not acess / process the GUI thread directly from +// other goroutines. This is due to the nature of how +// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) +// For example: gui.Queue(addNewTabForColorSelection()) +func Queue(f func()) { + log.Println("Sending function to gui.Main() (using gtk via andlabs/ui)") + ui.QueueMain(f) +} + +// gui.Main( +// gui.MainExample() +// ) +func MainExample() { + name := "jcarr" + log.Println("gui.initUI() inside ui.Main()") + + box := InitWindow(nil, "StartNewWindow" + name, 0) + window := box.Window + log.Println("StartNewWindow() box =", box) + + window.UiWindow.Show() +} + +func TestExample() { + log.Println("gui.initUI() inside ui.Main()") + + box := InitWindow(nil, "test", 0) + window := box.Window + log.Println("StartNewWindow() box =", box) + + window.UiWindow.Show() +} diff --git a/new-structs.go b/new-structs.go new file mode 100644 index 0000000..8d65147 --- /dev/null +++ b/new-structs.go @@ -0,0 +1,29 @@ +package gui + +import "log" + +import "github.com/andlabs/ui" +import _ "github.com/andlabs/ui/winmanifest" + +type Node struct { + Name string + tag string + Width int + Height int + + uiType *ui.Control + Children []*Node +} + +func (n Node) SetName(name string) { + // n.uiType.SetName(name) + log.Println("n.uiType =", n.uiType) + return +} + +func (n Node) Append(child Node) { +// if (n.UiBox == nil) { +// return +// } + // n.uiType.Append(child, x) +} diff --git a/structs.go b/structs.go index ac67588..6387b45 100644 --- a/structs.go +++ b/structs.go @@ -42,6 +42,7 @@ type GuiData struct { // andlabs/ui & andlabs/libui work AllButtons []*GuiButton buttonMap map[*ui.Button]*GuiButton + Nodes *Node } type GuiTab struct { diff --git a/window-debug.go b/window-debug.go index 92ed9c6..6d757a2 100644 --- a/window-debug.go +++ b/window-debug.go @@ -18,7 +18,7 @@ func makeWindowDebug() ui.Control { vbox.Append(pbar, false) ///////////////////////////////////////////////////// - vbox = addGroup(hbox, "WindowMap") + vbox = addGroup(hbox, "WindowMap 2") cbox := ui.NewCombobox() for name, _ := range Data.WindowMap {