2019-06-03 20:53:14 -05:00
|
|
|
package gui
|
|
|
|
|
2021-10-06 10:43:58 -05:00
|
|
|
import (
|
|
|
|
"log"
|
2021-11-01 03:44:39 -05:00
|
|
|
// "fmt"
|
2021-10-06 10:43:58 -05:00
|
|
|
"strconv"
|
2019-06-03 20:53:14 -05:00
|
|
|
|
2021-10-06 10:43:58 -05:00
|
|
|
"github.com/andlabs/ui"
|
|
|
|
_ "github.com/andlabs/ui/winmanifest"
|
|
|
|
)
|
2019-06-03 20:53:14 -05:00
|
|
|
|
2021-11-03 22:41:22 -05:00
|
|
|
func findUiWindow() *ui.Window {
|
|
|
|
for _, node := range Data.NodeMap {
|
|
|
|
if (node.uiWindow != nil) {
|
|
|
|
return node.uiWindow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2019-06-03 20:53:14 -05:00
|
|
|
}
|
|
|
|
|
2021-11-03 22:41:22 -05:00
|
|
|
func MessageWindow(msg1 string, msg2 string) (*Node) {
|
|
|
|
uiW := findUiWindow()
|
|
|
|
ui.MsgBox(uiW, msg1, msg2)
|
2021-10-31 21:46:30 -05:00
|
|
|
// TODO: make new node
|
2021-11-03 22:41:22 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrorWindow(msg1 string, msg2 string) (*Node) {
|
|
|
|
uiW := findUiWindow()
|
|
|
|
ui.MsgBoxError(uiW, msg1, msg2)
|
|
|
|
return nil
|
2019-06-03 20:53:14 -05:00
|
|
|
}
|
2019-06-13 14:08:47 -05:00
|
|
|
|
2021-11-01 03:44:39 -05:00
|
|
|
func initNode(title string, x int, y int) *Node {
|
2021-10-31 14:21:36 -05:00
|
|
|
var node Node
|
|
|
|
node.Name = title
|
|
|
|
node.Width = x
|
|
|
|
node.Height = y
|
|
|
|
|
|
|
|
id := Config.prefix + strconv.Itoa(Config.counter)
|
|
|
|
Config.counter += 1
|
|
|
|
node.id = id
|
|
|
|
|
2021-11-01 03:44:39 -05:00
|
|
|
if (Data.NodeMap[title] != nil) {
|
2021-11-04 00:12:48 -05:00
|
|
|
log.Println("ERROR: Duplicate window name =", title)
|
2021-11-01 03:44:39 -05:00
|
|
|
// TODO: just change the 'title' to something unique
|
|
|
|
return Data.NodeMap[title]
|
2021-10-31 14:21:36 -05:00
|
|
|
}
|
2021-11-01 03:44:39 -05:00
|
|
|
Data.NodeMap[title] = &node
|
|
|
|
Data.NodeArray = append(Data.NodeArray, &node)
|
|
|
|
Data.NodeSlice = append(Data.NodeSlice, &node)
|
|
|
|
return &node
|
|
|
|
// parent.Append(&node)
|
|
|
|
//node.parent = parent
|
2021-10-31 14:21:36 -05:00
|
|
|
return &node
|
2021-10-05 09:29:55 -05:00
|
|
|
}
|
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
func (parent *Node) makeNode(title string, x int, y int) *Node {
|
|
|
|
var node Node
|
|
|
|
node.Name = title
|
|
|
|
node.Width = x
|
|
|
|
node.Height = y
|
2021-10-04 14:39:38 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
id := Config.prefix + strconv.Itoa(Config.counter)
|
|
|
|
Config.counter += 1
|
|
|
|
node.id = id
|
2021-10-04 14:39:38 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
parent.Append(&node)
|
|
|
|
node.parent = parent
|
|
|
|
return &node
|
2021-10-04 14:39:38 -05:00
|
|
|
}
|
2021-10-04 20:18:51 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
func (n *Node) AddNode(title string) *Node {
|
|
|
|
var node Node
|
|
|
|
node.Name = title
|
|
|
|
node.Width = n.Width
|
|
|
|
node.Height = n.Height
|
|
|
|
|
|
|
|
id := Config.prefix + strconv.Itoa(Config.counter)
|
|
|
|
Config.counter += 1
|
|
|
|
node.id = id
|
2021-10-04 20:18:51 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
n.Append(&node)
|
|
|
|
node.parent = n
|
|
|
|
return &node
|
2021-10-05 09:29:55 -05:00
|
|
|
}
|
2021-10-04 20:18:51 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
func (n *Node) uiNewWindow(title string, x int, y int) {
|
2021-11-04 05:46:49 -05:00
|
|
|
w := ui.NewWindow(title, x, y, Config.Menu)
|
2021-10-31 14:21:36 -05:00
|
|
|
w.SetBorderless(false)
|
|
|
|
f := Config.Exit
|
|
|
|
w.OnClosing(func(*ui.Window) bool {
|
2021-11-04 00:12:48 -05:00
|
|
|
log.Println("RUNNING the ui.Window().OnClosing() function")
|
2021-10-31 14:21:36 -05:00
|
|
|
if (f != nil) {
|
|
|
|
f(n)
|
2021-11-04 00:12:48 -05:00
|
|
|
} else {
|
|
|
|
n.Dump()
|
|
|
|
log.Println("gui.uiWindow().OnClosing() NOT SURE WHAT TO DO HERE")
|
|
|
|
// TODO: always do this here? // by default delete the node?
|
|
|
|
name := n.Name
|
|
|
|
delete(Data.NodeMap, name)
|
2021-10-31 14:21:36 -05:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
w.SetMargined(true)
|
|
|
|
w.Show()
|
|
|
|
n.uiWindow = w
|
|
|
|
// w.node = &node
|
|
|
|
return
|
|
|
|
}
|
2021-10-05 10:23:27 -05:00
|
|
|
|
2021-11-01 03:44:39 -05:00
|
|
|
/*
|
2021-10-31 14:21:36 -05:00
|
|
|
func mapWindow(parent *Node, window *ui.Window, title string, x int, y int) *Node {
|
2021-10-06 05:14:24 -05:00
|
|
|
log.Println("gui.WindowMap START title =", title)
|
2021-10-04 23:38:45 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
node := makeNode(parent, title, x, y)
|
|
|
|
node.uiWindow = window
|
2021-10-06 13:23:00 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
return node
|
2021-10-04 20:18:51 -05:00
|
|
|
}
|
2021-11-01 03:44:39 -05:00
|
|
|
*/
|
2021-10-06 10:43:58 -05:00
|
|
|
|
2021-10-31 14:21:36 -05:00
|
|
|
// 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).
|
2021-11-04 05:46:49 -05:00
|
|
|
//
|
|
|
|
// There is probably some way to pass arguements here that I'm can't think of right now
|
|
|
|
//
|
2021-10-31 14:21:36 -05:00
|
|
|
func NewWindow() *Node {
|
|
|
|
title := Config.Title
|
|
|
|
w := Config.Width
|
|
|
|
h := Config.Height
|
|
|
|
|
2021-11-01 03:44:39 -05:00
|
|
|
if (Data.NodeMap[title] != nil) {
|
|
|
|
log.Println("Duplicate window name =", title)
|
2021-11-03 01:44:32 -05:00
|
|
|
Data.NodeMap[title].Dump()
|
|
|
|
Data.NodeMap[title].ListChildren(false)
|
|
|
|
uiW := Data.NodeMap[title].uiWindow
|
|
|
|
if (uiW != nil) {
|
|
|
|
uiW.Show()
|
|
|
|
}
|
2021-11-04 00:12:48 -05:00
|
|
|
log.Println("PROBABLY BAD ERROR: check here to see if window is really alive")
|
2021-11-01 03:44:39 -05:00
|
|
|
return Data.NodeMap[title]
|
|
|
|
}
|
2021-10-06 10:43:58 -05:00
|
|
|
|
2021-11-01 03:44:39 -05:00
|
|
|
var n *Node
|
|
|
|
n = initNode(title, w, h)
|
2021-10-31 20:52:19 -05:00
|
|
|
n.uiNewWindow(title, w, h)
|
2021-10-31 14:21:36 -05:00
|
|
|
window := n.uiWindow
|
|
|
|
|
|
|
|
f := Config.Exit
|
2021-10-06 10:43:58 -05:00
|
|
|
ui.OnShouldQuit(func() bool {
|
2021-10-31 14:21:36 -05:00
|
|
|
log.Println("createWindow().Destroy() on node.Name =", n.Name)
|
|
|
|
if (f != nil) {
|
|
|
|
f(n)
|
|
|
|
}
|
2021-10-06 10:43:58 -05:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2021-10-31 20:52:19 -05:00
|
|
|
n.uiWindow = window
|
2021-10-31 14:21:36 -05:00
|
|
|
if(n.uiWindow == nil) {
|
2021-11-04 00:12:48 -05:00
|
|
|
log.Println("ERROR: node.uiWindow == nil. This should never happen")
|
2021-10-31 14:21:36 -05:00
|
|
|
}
|
|
|
|
return n
|
2021-10-06 10:43:58 -05:00
|
|
|
}
|