2024-01-04 22:02:12 -06:00
|
|
|
/*
|
|
|
|
A Standard Window
|
|
|
|
*/
|
|
|
|
package gadgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/gui/gui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BasicWindow struct {
|
2024-01-05 12:24:29 -06:00
|
|
|
ready bool
|
2024-01-04 22:02:12 -06:00
|
|
|
hidden bool
|
2024-01-05 16:11:38 -06:00
|
|
|
vertical bool
|
2024-01-04 22:02:12 -06:00
|
|
|
name string
|
|
|
|
|
2024-01-05 12:24:29 -06:00
|
|
|
parent *gui.Node
|
2024-01-04 22:02:12 -06:00
|
|
|
win *gui.Node // window widget
|
|
|
|
box *gui.Node // box
|
|
|
|
|
|
|
|
Custom func()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Hide() {
|
2024-01-05 12:24:29 -06:00
|
|
|
if ! w.Ready() {return}
|
2024-01-04 22:02:12 -06:00
|
|
|
w.win.Hide()
|
|
|
|
w.hidden = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Show() {
|
2024-01-05 12:24:29 -06:00
|
|
|
if ! w.Ready() {return}
|
2024-01-04 22:02:12 -06:00
|
|
|
w.win.Show()
|
|
|
|
w.hidden = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *BasicWindow) Toggle() {
|
2024-01-05 12:24:29 -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-05 12:24:29 -06:00
|
|
|
func (w *BasicWindow) Title(title string) {
|
|
|
|
if ! w.Ready() {return}
|
|
|
|
w.win.SetText(title)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-05 16:11:38 -06:00
|
|
|
// Returns true if initialized
|
|
|
|
func (w *BasicWindow) Initialized() bool {
|
2024-01-05 12:24:29 -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 {
|
|
|
|
if ! w.Initialized() {return false}
|
2024-01-05 12:24:29 -06:00
|
|
|
if ! w.parent.Ready() {return false}
|
|
|
|
return w.ready
|
|
|
|
}
|
|
|
|
|
2024-01-04 22:02:12 -06:00
|
|
|
func (w *BasicWindow) Box() *gui.Node {
|
2024-01-05 16:11:38 -06:00
|
|
|
if ! w.Initialized() {return nil}
|
|
|
|
if (w.win == nil) {
|
|
|
|
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-05 20:29:57 -06:00
|
|
|
log.Log(INFO, "BasicWindow() w.vertical =", w.vertical)
|
2024-01-05 16:11:38 -06:00
|
|
|
if ! w.Initialized() {
|
|
|
|
log.Warn("BasicWindow() not Initialized yet()")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if w.Ready() {
|
|
|
|
log.Warn("BasicWindow() is already created. You can not change it to Vertical now (TODO: fix this)")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.vertical = true
|
2024-01-05 20:29:57 -06:00
|
|
|
log.Log(INFO, "BasicWindow() w.vertical =", w.vertical)
|
2024-01-05 16:11:38 -06:00
|
|
|
}
|
|
|
|
|
2024-01-05 12:24:29 -06:00
|
|
|
func (w *BasicWindow) Draw() {
|
2024-01-05 16:11:38 -06:00
|
|
|
if ! w.Initialized() {return}
|
|
|
|
// various timeout settings
|
|
|
|
w.win = w.parent.NewWindow(w.name)
|
|
|
|
w.win.Custom = func() {
|
2024-01-05 20:29:57 -06:00
|
|
|
log.Warn("BasicWindow.Custom() closed. TODO: handle this", w.name)
|
2024-01-05 16:11:38 -06:00
|
|
|
}
|
|
|
|
if w.vertical {
|
|
|
|
w.box = w.win.NewBox("bw vbox", false)
|
2024-01-05 20:29:57 -06:00
|
|
|
log.Log(INFO, "BasicWindow.Custom() made vbox")
|
2024-01-05 16:11:38 -06:00
|
|
|
} else {
|
|
|
|
w.box = w.win.NewBox("bw hbox", true)
|
2024-01-05 20:29:57 -06:00
|
|
|
log.Log(INFO, "BasicWindow.Custom() made hbox")
|
2024-01-05 16:11:38 -06:00
|
|
|
}
|
|
|
|
|
2024-01-05 12:24:29 -06:00
|
|
|
w.ready = true
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-04 22:02:12 -06:00
|
|
|
func NewBasicWindow(parent *gui.Node, name string) *BasicWindow {
|
|
|
|
var w *BasicWindow
|
|
|
|
w = &BasicWindow {
|
2024-01-05 12:24:29 -06:00
|
|
|
parent: parent,
|
2024-01-04 22:02:12 -06:00
|
|
|
name: name,
|
2024-01-05 16:11:38 -06:00
|
|
|
vertical: false,
|
2024-01-04 22:02:12 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return w
|
|
|
|
}
|