diff --git a/Makefile b/Makefile index 3c55c85..da02a3e 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,28 @@ all: build reset - ./basicwindow + ./gadgetwindow build: ifeq ($(GO111MODULE),) echo no. you must use GO111MODULE here false else - -rm -f basicwindow + -rm -f gadgetwindow go build -v -x endif stderr: build - echo "writing to /tmp/basicwindow.stderr" - ./basicwindow >/tmp/basicwindow.stderr 2>&1 + echo "writing to /tmp/gadgetwindow.stderr" + ./gadgetwindow >/tmp/gadgetwindow.stderr 2>&1 push: git add --all git commit -a git push +goimports: + goimports -w *.go + redomod: rm -f go.* goimports -w *.go diff --git a/choices.go b/choices.go new file mode 100644 index 0000000..32eecf6 --- /dev/null +++ b/choices.go @@ -0,0 +1,65 @@ +// This creates a simple hello world window +package main + +import ( + "go.wit.com/gui" + "go.wit.com/lib/gadgets" + "go.wit.com/log" +) + +type choices struct { + group *gui.Node // the group + grid *gui.Node // the grid + hello *gui.Node // the hello button + computers *gui.Node + colors *gui.Node + checkers *gui.Node + + socks *gadgets.OneLiner +} + +// This initializes the first window and some widgets +func newChoices(parent *gui.Node) *choices { + var c *choices + c = new(choices) + c.group = parent.NewGroup("choices") + c.grid = c.group.NewGrid("gridiron", 2, 1) + c.grid.NewButton("hello", func() { + log.Info("world") + }) + c.grid.NewButton("show basic window", func() { + basicWindow.Toggle() + }) + c.grid.NewLabel("a label") + + c.computers = c.grid.NewDropdown().SetProgName("COMPUTERS") + c.computers.AddText("Atari 500") + c.computers.AddText("Beagleboard") + c.computers.AddText("Unmatched Rev B") + c.computers.AddText("asldjf") + c.computers.AddText("asdjf") + c.computers.AddText("a1jf") + c.computers.AddText("jf") + c.computers.SetText("Beagleboard") + + c.colors = c.grid.NewCombobox().SetProgName("COLORS") + c.colors.AddText("Cyan") + c.colors.AddText("Magenta") + c.colors.AddText("Yellow") + c.colors.SetText("orange") + + c.checkers = c.grid.NewCheckbox("Checkers").SetProgName("CHECKERS") + c.checkers.Custom = func() { + log.Info("Checkers is", c.checkers.Bool()) + } + + c.socks = gadgets.NewOneLiner(c.grid, "two for one") + c.socks.SetValue("socks") + + return c +} + +func (c *choices) SetSocks(s string) *choices { + c.socks.SetValue(s) + return c +} diff --git a/go.mod b/go.mod index 2488569..c3a54ec 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,10 @@ -module go.wit.com/apps/basicwindow +module go.wit.com/apps/gadgetwindow go 1.21.4 require ( - go.wit.com/gui v0.12.17 - go.wit.com/lib/gadgets v0.12.11 + go.wit.com/gui v0.12.18 + go.wit.com/lib/gadgets v0.12.13 go.wit.com/log v0.5.5 ) diff --git a/go.sum b/go.sum index d145cda..7ab14d2 100644 --- a/go.sum +++ b/go.sum @@ -4,10 +4,10 @@ go.wit.com/dev/alexflint/scalar v1.2.1 h1:loXOcbVnd+8YeJRLey+XXidecBiedMDO00zQ26 go.wit.com/dev/alexflint/scalar v1.2.1/go.mod h1:+rYsfxqdI2cwA8kJ7GCMwWbNJvfvWUurOCXLiwdTtSs= go.wit.com/dev/davecgh/spew v1.1.4 h1:C9hj/rjlUpdK+E6aroyLjCbS5MFcyNUOuP1ICLWdNek= go.wit.com/dev/davecgh/spew v1.1.4/go.mod h1:sihvWmnQ/09FWplnEmozt90CCVqBtGuPXM811tgfhFA= -go.wit.com/gui v0.12.17 h1:O7fdI8dwDA8/TfkO0RN6LCK05dDiQRTE1Zvek1Imkrc= -go.wit.com/gui v0.12.17/go.mod h1:27+THr2a84GZ61KKUuN30WYnYoSsBewllUKc+fnWLto= -go.wit.com/lib/gadgets v0.12.11 h1:IgElPe2dFQq9xOQKtAx44Icfzf3tYEPP8NAhlXNUb2A= -go.wit.com/lib/gadgets v0.12.11/go.mod h1:Hb/vSiW22hPJjTVA1mShQ6HuqQ7dHGB95WLEfZlPO3M= +go.wit.com/gui v0.12.18 h1:gFVDaJFz/Su8JgUd9Oxnb3t+FS+bzy5WJSvGoKVGYZU= +go.wit.com/gui v0.12.18/go.mod h1:27+THr2a84GZ61KKUuN30WYnYoSsBewllUKc+fnWLto= +go.wit.com/lib/gadgets v0.12.13 h1:CEPUa+rH4VjmxtaWWSqvhgGEhpIjq8zuc01FIJ62xfA= +go.wit.com/lib/gadgets v0.12.13/go.mod h1:u+Syal5qdem7fEikOiEJdI+dO2zOybfa6vZ9ptF+bJ8= go.wit.com/log v0.5.5 h1:bK3b94uVKgev4jB5wg06FnvCFBEapQICTSH2YW+CWr4= go.wit.com/log v0.5.5/go.mod h1:BaJBfHFqcJSJLXGQ9RHi3XVhPgsStxSMZRlaRxW4kAo= go.wit.com/widget v1.1.5 h1:jx5hJ2WLZJnCcvMuaLHegzpNlzwo+0kOkzsRkzRiB30= diff --git a/main.go b/main.go index 5774340..45f692f 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( "go.wit.com/gui" + "go.wit.com/lib/debugger" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/logsettings" "go.wit.com/log" ) @@ -16,16 +18,17 @@ var mainWindow *gui.Node // this is a basic window. the user can open and close it var basicWindow *gadgets.BasicWindow -// the computers dropdown -var computers *gui.Node - -// the colors combobox -var colors *gui.Node +// the widget structure for both windows +var section1 *choices +var section2 *choices func main() { - myGui = gui.New().Default() + myGui = gui.New() + myGui.LoadToolkit("andlabs") // myGui.LoadToolkit("nocui") + myGui.Default() + helloworld() basicWindow = makebasicWindow() @@ -37,54 +40,47 @@ func main() { func helloworld() { mainWindow = myGui.NewWindow("hello world").SetProgName("BASEWIN1") - box := mainWindow.NewBox("vbox", false) - group := box.NewGroup("choices") - grid := group.NewGrid("gridiron", 2, 1) - grid.NewButton("hello", func() { - log.Println("world") - }) - grid.NewButton("show basic window", func() { + box := mainWindow.NewBox("hbox", true) + section1 = newChoices(box) + + group := box.NewGroup("interact") + group.NewButton("show basic window", func() { basicWindow.Toggle() }) - grid.NewLabel("a label") - computers = grid.NewDropdown().SetProgName("COMPUTERS") - computers.AddText("Atari 500") - computers.AddText("Beagleboard") - computers.AddText("Unmatched Rev B") - computers.AddText("asldjf") - computers.AddText("asdjf") - computers.AddText("a1jf") - computers.AddText("jf") - computers.SetText("Beagleboard") - - colors = grid.NewCombobox().SetProgName("COLORS") - colors.AddText("Cyan") - colors.AddText("Magenta") - colors.AddText("Yellow") - colors.SetText("orange") - - grid.NewCheckbox("Checkers").SetProgName("CHECKERS") - - queryGroup := box.NewGroup("interact") - - queryGroup.NewButton("Which Computer?", func() { - tmp := computers.String() + group.NewButton("Which Computer?", func() { + tmp := section1.computers.String() log.Println("computer =", tmp) - for i, s := range computers.Strings() { + for i, s := range section1.computers.Strings() { log.Println("has option", i, s) } }) - queryGroup.NewButton("Which Color?", func() { - tmp := colors.String() + group.NewButton("Which Color?", func() { + tmp := section1.colors.String() log.Println("color =", tmp) }) - queryGroup.NewButton("Show apple", func() { + group.NewButton("Show apple", func() { apple.Show() }) - queryGroup.NewButton("Hide apple", func() { + group.NewButton("Hide apple", func() { apple.Hide() }) + group.NewButton("set socks", func() { + section1.SetSocks("blue") + section2.SetSocks("green") + }) + group.NewButton("show socks", func() { + log.Info("main window socks =", section1.socks.String()) + log.Info("basic window socks =", section2.socks.String()) + }) + + group = box.NewGroup("debug") + group.NewButton("debugger", func() { + debugger.DebugWindow() + }) + group.NewButton("log options", func() { + logsettings.LogWindow() + }) } diff --git a/stateWindow.go b/stateWindow.go index 74954da..cffddde 100644 --- a/stateWindow.go +++ b/stateWindow.go @@ -14,14 +14,17 @@ var apple *gui.Node func makebasicWindow() *gadgets.BasicWindow { log.Warn("start basicWindow") basicWindow = gadgets.NewBasicWindow(myGui, "basic window test") + basicWindow.Custom = func() { + log.Info("got to close") + } basicWindow.Make() basicWindow.StandardClose() - basicWindow.Custom = func() { - log.Warn("got to close") - } box1 := basicWindow.Box() - group1 := box1.NewGroup("choices") + section2 = newChoices(box1) + + vbox := box1.NewBox("vbox", false) + group1 := vbox.NewGroup("controls").Horizontal() // Vertical() group1.NewButton("hide apple", func() { apple.Hide() }) @@ -29,13 +32,14 @@ func makebasicWindow() *gadgets.BasicWindow { apple.Show() }) group1.NewButton("hide computers", func() { - computers.Hide() + section2.computers.Hide() }) group1.NewButton("show computers", func() { - computers.Show() + section2.computers.Show() }) apple = group1.NewButton("apple", func() { log.Info("is not a pear") }) + return basicWindow }