2024-01-04 22:02:12 -06:00
|
|
|
/*
|
2024-01-18 05:04:18 -06:00
|
|
|
A Standard Window
|
2024-01-04 22:02:12 -06:00
|
|
|
*/
|
|
|
|
package gadgets
|
|
|
|
|
2024-01-18 05:04:18 -06:00
|
|
|
import (
|
|
|
|
"go.wit.com/gui"
|
2024-01-04 22:02:12 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BasicWindow struct {
|
2024-01-18 05:04:18 -06:00
|
|
|
ready bool
|
|
|
|
hidden bool
|
2024-01-05 16:11:38 -06:00
|
|
|
vertical bool
|
2024-01-18 05:04:18 -06:00
|
|
|
title string
|
2024-01-04 22:02:12 -06:00
|
|
|
|
2024-01-18 05:04:18 -06:00
|
|
|
parent *gui.Node
|
|
|
|
win *gui.Node // window widget
|
|
|
|
box *gui.Node // box
|
2024-01-04 22:02:12 -06:00
|
|
|
|
|
|
|
Custom func()
|
|
|
|
}
|
|
|
|
|
2024-01-14 10:25:23 -06:00
|
|
|
func NewBasicWindow(parent *gui.Node, title string) *BasicWindow {
|
|
|
|
var w *BasicWindow
|
2024-01-18 05:04:18 -06:00
|
|
|
w = &BasicWindow{
|
|
|
|
parent: parent,
|
|
|
|
title: title,
|
2024-01-14 10:25:23 -06:00
|
|
|
vertical: false,
|
|
|
|
}
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "NewBasicWindow() END")
|
2024-01-14 10:25:23 -06:00
|
|
|
|
|
|
|
return w
|
2024-01-04 22:02:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Show() {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-04 22:02:12 -06:00
|
|
|
w.win.Show()
|
|
|
|
w.hidden = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-14 10:25:23 -06:00
|
|
|
func (w *BasicWindow) Hide() {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Hide() here")
|
2024-01-14 10:25:23 -06:00
|
|
|
w.win.Hide()
|
|
|
|
w.hidden = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-19 18:31:56 -06:00
|
|
|
func (w *BasicWindow) Enable() {
|
|
|
|
w.box.Enable()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Disable() {
|
|
|
|
w.box.Disable()
|
|
|
|
}
|
|
|
|
|
2024-01-04 22:02:12 -06:00
|
|
|
func (w *BasicWindow) Toggle() {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-04 22:02:12 -06:00
|
|
|
if w.hidden {
|
|
|
|
w.Show()
|
|
|
|
w.hidden = false
|
|
|
|
} else {
|
|
|
|
w.Hide()
|
|
|
|
w.hidden = true
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-21 02:11:50 -06:00
|
|
|
func (w *BasicWindow) SetTitle(title string) {
|
|
|
|
w.SetLabel(title)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) SetLabel(title string) {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-05 12:24:29 -06:00
|
|
|
w.win.SetText(title)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-18 21:00:38 -06:00
|
|
|
// sets this window to run os.Exit()
|
|
|
|
func (w *BasicWindow) StandardClose() {
|
|
|
|
if !w.Initialized() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.win.Custom = w.win.StandardClose
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-16 00:54:41 -06:00
|
|
|
// sets this window to run os.Exit()
|
|
|
|
func (w *BasicWindow) StandardExit() {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-16 00:54:41 -06:00
|
|
|
w.win.Custom = func() {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Custom() closed. handled properly?", w.title)
|
2024-01-16 00:54:41 -06:00
|
|
|
if w.Custom != nil {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Custom() HAS CUSTOM")
|
2024-01-16 00:54:41 -06:00
|
|
|
w.Custom()
|
2024-01-18 21:00:38 -06:00
|
|
|
return
|
2024-01-16 00:54:41 -06:00
|
|
|
}
|
|
|
|
w.win.StandardExit()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-05 16:11:38 -06:00
|
|
|
// Returns true if initialized
|
|
|
|
func (w *BasicWindow) Initialized() bool {
|
2024-01-18 05:04:18 -06:00
|
|
|
if w == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if w.parent == nil {
|
|
|
|
return false
|
|
|
|
}
|
2024-01-05 16:11:38 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the status is valid
|
|
|
|
func (w *BasicWindow) Ready() bool {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Initialized() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !w.parent.Ready() {
|
|
|
|
return false
|
|
|
|
}
|
2024-01-05 12:24:29 -06:00
|
|
|
return w.ready
|
|
|
|
}
|
|
|
|
|
2024-01-04 22:02:12 -06:00
|
|
|
func (w *BasicWindow) Box() *gui.Node {
|
2024-01-18 05:04:18 -06:00
|
|
|
if w.win == nil {
|
2024-01-05 16:11:38 -06:00
|
|
|
w.Draw()
|
|
|
|
}
|
2024-01-04 22:02:12 -06:00
|
|
|
return w.box
|
|
|
|
}
|
|
|
|
|
2024-01-05 16:11:38 -06:00
|
|
|
func (w *BasicWindow) Vertical() {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow() Vertical() START w.vertical =", w.vertical, w.title)
|
2024-01-18 05:04:18 -06:00
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-05 16:11:38 -06:00
|
|
|
w.vertical = true
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow() Vertical() END w.vertical =", w.vertical, w.title)
|
2024-01-11 20:37:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Horizontal() {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow() Horizontal() START w.vertical =", w.vertical, w.title)
|
2024-01-18 05:04:18 -06:00
|
|
|
if w == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-11 20:37:39 -06:00
|
|
|
w.vertical = false
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow() Horizontal() END w.vertical =", w.vertical, w.title)
|
2024-01-05 16:11:38 -06:00
|
|
|
}
|
|
|
|
|
2024-01-06 13:54:06 -06:00
|
|
|
func (w *BasicWindow) Make() {
|
2024-01-13 21:30:18 -06:00
|
|
|
if w.win != nil {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Make() window was already created")
|
2024-01-13 21:30:18 -06:00
|
|
|
return
|
|
|
|
}
|
2024-01-11 20:37:39 -06:00
|
|
|
w.win = w.parent.RawWindow(w.title)
|
2024-01-16 00:54:41 -06:00
|
|
|
|
|
|
|
// if Custom isn't set, set it here. This prevents the application from
|
|
|
|
// os.Exit() if the window is closed. It destroy's the widgets in the toolkit plugins
|
|
|
|
// the the window still exists in the binary tree and functions normally
|
|
|
|
// I like to call this Sierpinski mode
|
|
|
|
if w.win.Custom == nil {
|
|
|
|
w.win.Custom = func() {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Custom() closed. handled properly?", w.title)
|
2024-01-16 00:54:41 -06:00
|
|
|
if w.Custom != nil {
|
|
|
|
w.Custom()
|
|
|
|
}
|
2024-01-14 22:14:25 -06:00
|
|
|
}
|
2024-01-06 13:54:06 -06:00
|
|
|
}
|
|
|
|
if w.vertical {
|
2024-01-11 20:37:39 -06:00
|
|
|
w.box = w.win.NewVerticalBox("BW VBOX")
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Make() made NewVerticalBox", w.title)
|
2024-01-06 13:54:06 -06:00
|
|
|
} else {
|
2024-01-11 20:37:39 -06:00
|
|
|
w.box = w.win.NewHorizontalBox("BW HBOX")
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Make() made NewHorizontalBox", w.title)
|
2024-01-06 13:54:06 -06:00
|
|
|
}
|
2024-01-20 19:53:23 -06:00
|
|
|
w.win.SetVisable(false)
|
2024-01-06 13:54:06 -06:00
|
|
|
|
|
|
|
w.ready = true
|
|
|
|
}
|
|
|
|
|
2024-01-13 21:30:18 -06:00
|
|
|
func (w *BasicWindow) TestDraw() {
|
2024-01-18 05:04:18 -06:00
|
|
|
if !w.Initialized() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-13 21:30:18 -06:00
|
|
|
if w.win == nil {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.TestDraw() can't draw on window == nil")
|
2024-01-14 10:25:23 -06:00
|
|
|
w.Make()
|
2024-01-13 21:30:18 -06:00
|
|
|
}
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.TestDraw() RUNNING HERE")
|
2024-01-13 21:30:18 -06:00
|
|
|
w.win.TestDraw()
|
|
|
|
}
|
|
|
|
|
2024-01-05 12:24:29 -06:00
|
|
|
func (w *BasicWindow) Draw() {
|
2024-01-20 19:53:23 -06:00
|
|
|
if w.win == nil {
|
2024-01-21 11:42:31 -06:00
|
|
|
log.Log(GADGETS, "BasicWindow.Draw() needs Make()")
|
2024-01-14 10:25:23 -06:00
|
|
|
w.Make()
|
2024-01-13 21:30:18 -06:00
|
|
|
}
|
2024-01-14 10:25:23 -06:00
|
|
|
w.win.TestDraw()
|
2024-01-04 22:02:12 -06:00
|
|
|
}
|