EXIT: more accurate window close & exit code
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
3ad83abc3a
commit
76b371b375
|
@ -8,26 +8,25 @@ import (
|
||||||
"git.wit.org/wit/gui"
|
"git.wit.org/wit/gui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func customExit(gw *gui.GuiWindow) {
|
|
||||||
log.Println("Should Exit Here")
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("starting my Control Panel")
|
log.Println("Starting my Control Panel")
|
||||||
|
|
||||||
gui.Config.Width = 800
|
|
||||||
gui.Config.Height = 300
|
|
||||||
gui.Config.Exit = customExit
|
|
||||||
|
|
||||||
|
// This initializes the first window
|
||||||
go gui.Main(initGUI)
|
go gui.Main(initGUI)
|
||||||
|
|
||||||
|
// This starts a goroutine to demonstrate how to
|
||||||
|
// inject things into the GUI
|
||||||
watchGUI()
|
watchGUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGUI() {
|
func initGUI() {
|
||||||
n := gui.NewWindow("WIT GUI Example Window", 640, 480)
|
gui.Config.Title = "WIT GUI Window Demo"
|
||||||
n.AddDemoTab("A Simple Tab Demo")
|
gui.Config.Width = 640
|
||||||
|
gui.Config.Height = 480
|
||||||
|
gui.Config.Exit = myExit
|
||||||
|
|
||||||
|
node := gui.NewWindow()
|
||||||
|
node.AddDemoTab("A Simple Tab Demo")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This demonstrates how to properly interact with the GUI
|
// This demonstrates how to properly interact with the GUI
|
||||||
|
@ -36,12 +35,27 @@ func initGUI() {
|
||||||
func watchGUI() {
|
func watchGUI() {
|
||||||
var i = 1
|
var i = 1
|
||||||
for {
|
for {
|
||||||
log.Println("Waiting for customExit()", i)
|
log.Println("Waiting", i, "seconds")
|
||||||
i += 1
|
i += 1
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
if i == 4 {
|
if i == 4 {
|
||||||
log.Println("Opening a Debug Window via the gui.Queue()")
|
log.Println("Opening a Debug Window via the gui.Queue()")
|
||||||
|
gui.Config.Width = 800
|
||||||
|
gui.Config.Height = 300
|
||||||
|
gui.Config.Exit = myDebugExit
|
||||||
gui.Queue(gui.DebugWindow)
|
gui.Queue(gui.DebugWindow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func myExit(n *gui.Node) {
|
||||||
|
log.Println()
|
||||||
|
log.Println("Entered myExit() on node.Name =", n.Name)
|
||||||
|
log.Println()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func myDebugExit(n *gui.Node) {
|
||||||
|
log.Println("Entered myDebugExit() on node.Name =", n.Name)
|
||||||
|
log.Println("Don't actually os.Exit()")
|
||||||
|
}
|
||||||
|
|
|
@ -20,13 +20,15 @@ var Data GuiData
|
||||||
var Config GuiConfig
|
var Config GuiConfig
|
||||||
|
|
||||||
type GuiConfig struct {
|
type GuiConfig struct {
|
||||||
|
Title string
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
Exit func(*Node)
|
||||||
|
|
||||||
Debug bool
|
Debug bool
|
||||||
DebugNode bool
|
DebugNode bool
|
||||||
DebugTabs bool
|
DebugTabs bool
|
||||||
DebugTable bool
|
DebugTable bool
|
||||||
Exit func(*GuiWindow)
|
|
||||||
|
|
||||||
depth int
|
depth int
|
||||||
counter int // used to make unique ID's
|
counter int // used to make unique ID's
|
||||||
|
|
43
window.go
43
window.go
|
@ -80,15 +80,17 @@ func InitWindow(parent *Node, gw *GuiWindow, name string, axis int) *Node {
|
||||||
w := node.uiWindow
|
w := node.uiWindow
|
||||||
newGuiWindow.UiWindow = w
|
newGuiWindow.UiWindow = w
|
||||||
|
|
||||||
// newGuiWindow.UiWindow.SetTitle("test")
|
f := Config.Exit
|
||||||
w.OnClosing(func(*ui.Window) bool {
|
w.OnClosing(func(*ui.Window) bool {
|
||||||
log.Println("gui.InitWindow() OnClosing() THIS WINDOW IS CLOSING newGuiWindow=", newGuiWindow)
|
if (Config.Debug) {
|
||||||
|
log.Println("gui.InitWindow() OnClosing()")
|
||||||
|
}
|
||||||
// newGuiWindow.UiWindow.Destroy()
|
// newGuiWindow.UiWindow.Destroy()
|
||||||
if Config.Exit == nil {
|
if f == nil {
|
||||||
ui.Quit()
|
ui.Quit()
|
||||||
} else {
|
} else {
|
||||||
// allow a custom exit function
|
// use a custom exit function
|
||||||
Config.Exit(newGuiWindow)
|
f(node)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
@ -299,8 +301,14 @@ func (parent *Node) makeNode(title string, x int, y int) *Node {
|
||||||
func (n *Node) uiNewWindow(title string, x int, y int) {
|
func (n *Node) uiNewWindow(title string, x int, y int) {
|
||||||
w := ui.NewWindow(title, x, y, false)
|
w := ui.NewWindow(title, x, y, false)
|
||||||
w.SetBorderless(false)
|
w.SetBorderless(false)
|
||||||
|
f := Config.Exit
|
||||||
w.OnClosing(func(*ui.Window) bool {
|
w.OnClosing(func(*ui.Window) bool {
|
||||||
log.Println("ui.Window().OnClosing() IS EMPTY FOR window name =", title)
|
if (Config.Debug) {
|
||||||
|
log.Println("ui.Window().OnClosing()")
|
||||||
|
}
|
||||||
|
if (f != nil) {
|
||||||
|
f(n)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
w.SetMargined(true)
|
w.SetMargined(true)
|
||||||
|
@ -390,18 +398,31 @@ func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Nod
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindow(title string, x int, y int) *Node {
|
// This routine creates a blank window with a Title and size (W x H)
|
||||||
|
//
|
||||||
|
// This routine can not have any arguements due to the nature of how
|
||||||
|
// it can be passed via the 'andlabs/ui' queue which, because it is
|
||||||
|
// cross platform, must pass UI changes into the OS threads (that is
|
||||||
|
// my guess).
|
||||||
|
func NewWindow() *Node {
|
||||||
|
title := Config.Title
|
||||||
|
w := Config.Width
|
||||||
|
h := Config.Height
|
||||||
|
|
||||||
var node *Node
|
var node *Node
|
||||||
node = mapWindow(nil, nil, title, x, y)
|
node = mapWindow(nil, nil, title, w, h)
|
||||||
box := node.box
|
box := node.box
|
||||||
log.Println("gui.NewWindow() title = box.Name =", box.Name)
|
log.Println("gui.NewWindow() title = box.Name =", box.Name)
|
||||||
|
|
||||||
node.uiNewWindow(box.Name, x, y)
|
node.uiNewWindow(box.Name, w, h)
|
||||||
window := node.uiWindow
|
window := node.uiWindow
|
||||||
|
|
||||||
|
f := Config.Exit
|
||||||
ui.OnShouldQuit(func() bool {
|
ui.OnShouldQuit(func() bool {
|
||||||
log.Println("createWindow().Destroy()", box.Name)
|
log.Println("createWindow().Destroy() on node.Name =", node.Name)
|
||||||
window.Destroy()
|
if (f != nil) {
|
||||||
|
f(node)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue