From 07061a47e74daccec9382506845ff4ce51d44069 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 6 Oct 2021 11:17:43 -0500 Subject: [PATCH] EXAMPLE: further improvements to the example Signed-off-by: Jeff Carr --- Makefile | 14 ++++++++--- gui-example/Makefile | 4 +-- gui-example/main.go | 6 ++--- main.go | 12 +++++---- window-debug.go | 60 ++++++++++++++++++++++++++------------------ 5 files changed, 59 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index df5d201..7225bce 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,13 @@ +all: + @echo + @echo "make examples # will run all the examples" + @echo "make update # full git update" + @echo + # should update every go dependancy (?) update: - # git pull - wit go update - # go get -v -t -u ./... + git pull + go get -v -t -u ./... + +examples: + make -C gui-example diff --git a/gui-example/Makefile b/gui-example/Makefile index b705093..5028ebd 100644 --- a/gui-example/Makefile +++ b/gui-example/Makefile @@ -1,5 +1,5 @@ run: build - ~/go/bin/gui-example + ./gui-example build: - GO111MODULE="off" go install + GO111MODULE="off" go build diff --git a/gui-example/main.go b/gui-example/main.go index f3e4c48..1ff286d 100644 --- a/gui-example/main.go +++ b/gui-example/main.go @@ -16,8 +16,8 @@ func customExit(gw *gui.GuiWindow) { func main() { log.Println("starting my Control Panel") - gui.Config.Width = 1000 - gui.Config.Height = 400 + gui.Config.Width = 800 + gui.Config.Height = 300 gui.Config.Exit = customExit go gui.Main(initGUI) @@ -37,7 +37,7 @@ func watchGUI() { time.Sleep(time.Second) if i == 3 { log.Println("Sending ExampleWindow to gui.Queue()") - gui.Queue(gui.ExampleWindow) + gui.Queue(gui.DebugWindow) } } } diff --git a/main.go b/main.go index 6d371a6..09d105f 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,6 @@ func Queue(f func()) { ui.QueueMain(f) } -// gui.Main(gui.MainExample()) func ExampleWindow() { log.Println("START gui.ExampleWindow()") @@ -37,12 +36,15 @@ func ExampleWindow() { window.UiWindow.Show() } -func TestExample() { - log.Println("gui.initUI() inside ui.Main()") +func DebugWindow() { + log.Println("START gui.ExampleWindow()") - box := InitWindow(nil, "test", 0) + title := "Debug Window" + box := InitWindow(nil, title, 0) window := box.Window - log.Println("StartNewWindow() box =", box) + log.Println("box =", box) + log.Println("window =", window) + box.AddDebugTab("jcarr Debug") window.UiWindow.Show() } diff --git a/window-debug.go b/window-debug.go index 6d757a2..bf93a9b 100644 --- a/window-debug.go +++ b/window-debug.go @@ -1,10 +1,12 @@ package gui -import "log" -import "github.com/andlabs/ui" -import _ "github.com/andlabs/ui/winmanifest" +import ( + "log" -import "github.com/davecgh/go-spew/spew" + "github.com/andlabs/ui" + _ "github.com/andlabs/ui/winmanifest" + "github.com/davecgh/go-spew/spew" +) var names = make([]string, 100) @@ -12,12 +14,12 @@ func makeWindowDebug() ui.Control { hbox := ui.NewHorizontalBox() hbox.SetPadded(true) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox := addGroup(hbox, "Numbers") pbar := ui.NewProgressBar() vbox.Append(pbar, false) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox = addGroup(hbox, "WindowMap 2") cbox := ui.NewCombobox() @@ -35,7 +37,7 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) -///////////////////////////////////////////////////// + ///////////////////////////////////////////////////// vbox = addGroup(hbox, "Buttons") b1 := addButton(vbox, "dumpBox(name)") @@ -46,6 +48,16 @@ func makeWindowDebug() ui.Control { dumpBox(names[x]) }) + dump2 := addButton(vbox, "Dump Boxes") + dump2.OnClicked(func(*ui.Button) { + DumpBoxes() + }) + + dump1 := addButton(vbox, "Dump MAP") + dump1.OnClicked(func(*ui.Button) { + DumpMap() + }) + b2 := addButton(vbox, "SetMargined()") b2.OnClicked(func(*ui.Button) { x := cbox.Selected() @@ -53,13 +65,13 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } - if (gw.TabNumber == nil) { + if gw.TabNumber == nil { return } scs := spew.ConfigState{MaxDepth: 1} @@ -76,10 +88,10 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } gw.UiTab.Hide() @@ -92,10 +104,10 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } gw.UiTab.Show() @@ -108,13 +120,13 @@ func makeWindowDebug() ui.Control { log.Println("findBox; names[x] =", names[x]) findBox(names[x]) gw := findBox(names[x]) - if (gw == nil) { + if gw == nil { return } - if (gw.UiTab == nil) { + if gw.UiTab == nil { return } - if (gw.TabNumber == nil) { + if gw.TabNumber == nil { return } gw.UiTab.Delete(*gw.TabNumber) @@ -145,7 +157,7 @@ func addGroup(b *ui.Box, name string) *ui.Box { func findBox(s string) *GuiWindow { for name, window := range Data.WindowMap { - if (name == s) { + if name == s { return window } } @@ -154,11 +166,11 @@ func findBox(s string) *GuiWindow { func dumpBox(s string) { for name, window := range Data.WindowMap { - if (name != s) { + if name != s { continue } log.Println("gui.DumpBoxes() MAP: ", name) - if (window.TabNumber == nil) { + if window.TabNumber == nil { log.Println("gui.DumpBoxes() \tWindows.TabNumber = nil") } else { log.Println("gui.DumpBoxes() \tWindows.TabNumber =", *window.TabNumber) @@ -169,18 +181,18 @@ func dumpBox(s string) { log.Println("gui.DumpBoxes()\tWindow.UiTab =", window.UiTab) for name, abox := range window.BoxMap { log.Printf("gui.DumpBoxes() \tBOX mapname=%-12s abox.Name=%-12s", name, abox.Name) - if (name == "MAINBOX") { - if (Config.Debug) { + if name == "MAINBOX" { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 1} scs.Dump(abox.UiBox) } } } - if (window.UiTab != nil) { + if window.UiTab != nil { pages := window.UiTab.NumPages() log.Println("gui.DumpBoxes()\tWindow.UiTab.NumPages() =", pages) tabSetMargined(window.UiTab) - if (Config.Debug) { + if Config.Debug { scs := spew.ConfigState{MaxDepth: 2} scs.Dump(window.UiTab) }