gadgetwindow/main.go

106 lines
2.4 KiB
Go

package main
import (
"embed"
"go.wit.com/gui"
"go.wit.com/lib/debugger"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/logsettings"
"go.wit.com/log"
)
// sent via -ldflags
var VERSION string
// This is the beginning of the binary tree of widgets
var myGui *gui.Node
//go:embed resources/*
var resources embed.FS
// this is the primary window. If you close it, the program will exit
var mainWindow *gui.Node
// this is a basic window. the user can open and close it
var basicWindow *gadgets.BasicWindow
// the widget structure for both windows
var section1 *choices
var section2 *choices
func main() {
if debugger.ArgDebug() {
log.SetAll(true)
log.ShowFlags()
}
myGui = gui.New()
myGui.InitEmbed(resources)
myGui.Default()
helloworld()
basicWindow = makebasicWindow()
// go will sit here until the window exits
gui.Watchdog()
}
// This initializes the first window and some widgets
func helloworld() {
mainWindow = myGui.NewWindow("hello world").SetProgName("BASEWIN1")
box := mainWindow.NewBox("hbox", true)
// box := mainWindow.Box().Vertical()
// box := mainWindow.Box().Horizontal()
section1 = newChoices(box)
group := box.NewGroup("interact")
group.NewButton("show basic window", func() {
basicWindow.Toggle()
})
group.NewButton("Which Computer?", func() {
tmp := section1.computers.String()
log.Println("computer =", tmp)
for i, s := range section1.computers.Strings() {
log.Println("has option", i, s)
}
})
group.NewButton("Which Color?", func() {
tmp := section1.colors.String()
log.Println("color =", tmp)
})
group.NewButton("Show apple", func() {
apple.Show()
})
group.NewButton("Hide apple", func() {
apple.Hide()
})
group.NewCheckbox("test checkbox").SetChecked(true)
group.NewLabel("test label")
gadgets.NewBasicEntry(group, "test entry")
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.NewButton("show animal", func() {
log.Info("main window animal =", section1.animal.String())
log.Info("basic window animal =", section2.animal.String())
})
group = box.NewGroup("debug")
group.NewButton("debugger", func() {
debugger.DebugWindow()
})
group.NewButton("log options", func() {
logsettings.LogWindow()
})
}