2022-11-05 10:19:04 -05:00
|
|
|
// This creates a simple hello world window
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"log"
|
|
|
|
"git.wit.org/wit/gui"
|
|
|
|
arg "github.com/alexflint/go-arg"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LogOptions struct {
|
|
|
|
LogFile string
|
|
|
|
Verbose bool
|
|
|
|
User string `arg:"env:USER"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var args struct {
|
|
|
|
LogOptions
|
2023-02-25 14:05:25 -06:00
|
|
|
gui.GuiArgs
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2023-03-23 12:35:12 -05:00
|
|
|
// this implements ./cmd --gui-debug --gui-toolkit, etc
|
2022-11-05 10:19:04 -05:00
|
|
|
arg.MustParse(&args)
|
2023-02-25 14:05:25 -06:00
|
|
|
log.Println("Toolkit = ", args.Toolkit)
|
2022-11-05 10:19:04 -05:00
|
|
|
|
2023-02-25 14:05:25 -06:00
|
|
|
// gui.InitPlugins([]string{"andlabs"})
|
2022-11-05 10:19:04 -05:00
|
|
|
gui.Main(initGUI)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This initializes the first window
|
|
|
|
func initGUI() {
|
|
|
|
var w *gui.Node
|
2023-02-25 14:05:25 -06:00
|
|
|
gui.Config.Title = "Hello World"
|
2023-03-01 11:35:36 -06:00
|
|
|
gui.Config.Width = 642
|
|
|
|
gui.Config.Height = 481
|
2022-11-05 10:19:04 -05:00
|
|
|
gui.Config.Exit = myDefaultExit
|
|
|
|
|
|
|
|
w = gui.NewWindow()
|
2023-03-01 11:35:36 -06:00
|
|
|
w.Custom = func () {
|
|
|
|
log.Println("myDefaultExit(w)")
|
|
|
|
myDefaultExit(w)
|
|
|
|
}
|
2022-11-05 10:19:04 -05:00
|
|
|
addDemoTab(w, "A Simple Tab Demo")
|
|
|
|
addDemoTab(w, "A Second Tab")
|
|
|
|
|
|
|
|
if (args.GuiDebug) {
|
2023-03-23 12:35:12 -05:00
|
|
|
gui.DebugWindow()
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
if (args.GuiVerbose) {
|
2023-03-23 12:35:12 -05:00
|
|
|
gui.SetDebug(true)
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func addDemoTab(window *gui.Node, title string) {
|
2023-03-23 12:35:12 -05:00
|
|
|
var newNode, g *gui.Node
|
2022-11-05 10:19:04 -05:00
|
|
|
|
|
|
|
newNode = window.NewTab(title)
|
2023-03-23 12:35:12 -05:00
|
|
|
log.Println("addDemoTab() newNode START")
|
|
|
|
// newNode.Dump(true)
|
2022-11-05 10:19:04 -05:00
|
|
|
|
|
|
|
g = newNode.NewGroup("group 1")
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
g1 := g.NewGrid("grid 1", 2, 2)
|
|
|
|
g1.NewLabel("less")
|
|
|
|
dd := g1.NewDropdown("more")
|
2022-11-13 08:53:03 -06:00
|
|
|
dd.AddDropdownName("more 1")
|
|
|
|
dd.AddDropdownName("more 2")
|
|
|
|
dd.AddDropdownName("more 3")
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
g.SetNext(3,1)
|
|
|
|
g1.NewLabel("label (3,1)")
|
|
|
|
g.SetNext(3,2)
|
|
|
|
g1.NewLabel("label (3,2)")
|
|
|
|
|
|
|
|
g2 := newNode.NewGroup("group 2")
|
|
|
|
tb := g2.NewTextbox("tb")
|
2022-11-05 10:19:04 -05:00
|
|
|
log.Println("tb =", tb.GetText())
|
2023-03-01 11:35:36 -06:00
|
|
|
tb.Custom = func() {
|
2022-11-05 10:19:04 -05:00
|
|
|
s := tb.GetText()
|
|
|
|
log.Println("text =", s)
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
dd.Custom = func() {
|
|
|
|
s := dd.GetText()
|
|
|
|
log.Println("hello world " + args.User + "\n" + s + "\n")
|
|
|
|
tb.SetText("hello world " + args.User + "\n" + s + "\n")
|
|
|
|
}
|
2022-11-05 10:19:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func myDefaultExit(n *gui.Node) {
|
|
|
|
log.Println("You can Do exit() things here")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|