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-10-31 21:46:30 -05:00
|
|
|
func (n *Node) MessageWindow2(msg1 string, msg2 string) (*Node) {
|
|
|
|
ui.MsgBox(n.uiWindow, msg1, msg2)
|
|
|
|
// TODO: make new node
|
|
|
|
return n
|
2019-06-03 20:53:14 -05:00
|
|
|
}
|
|
|
|
|
2021-10-31 21:46:30 -05:00
|
|
|
func (n *Node) ErrorWindow2(msg1 string, msg2 string) (*Node) {
|
|
|
|
ui.MsgBoxError(n.uiWindow, msg1, msg2)
|
|
|
|
// TODO: make new node
|
|
|
|
return n
|
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) {
|
|
|
|
log.Println("Duplicate window name =", title)
|
|
|
|
// TODO: just change the 'title' to something unique
|
|
|
|
// panic(fmt.Sprintf("Duplicate window name = %s\n", title))
|
|
|
|
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) {
|
|
|
|
w := ui.NewWindow(title, x, y, false)
|
|
|
|
w.SetBorderless(false)
|
|
|
|
f := Config.Exit
|
|
|
|
w.OnClosing(func(*ui.Window) bool {
|
|
|
|
if (Config.Debug) {
|
|
|
|
log.Println("ui.Window().OnClosing()")
|
|
|
|
}
|
|
|
|
if (f != nil) {
|
|
|
|
f(n)
|
|
|
|
}
|
|
|
|
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).
|
|
|
|
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)
|
|
|
|
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) {
|
|
|
|
panic("node.uiWindow == nil. This should never happen")
|
|
|
|
}
|
|
|
|
return n
|
2021-10-06 10:43:58 -05:00
|
|
|
}
|