summaryrefslogtreecommitdiff
path: root/smartwindow
diff options
context:
space:
mode:
Diffstat (limited to 'smartwindow')
-rw-r--r--smartwindow/args.go30
-rw-r--r--smartwindow/common.go24
-rw-r--r--smartwindow/new.go32
-rw-r--r--smartwindow/postReady.go59
-rw-r--r--smartwindow/preReady.go84
-rw-r--r--smartwindow/structs.go21
6 files changed, 250 insertions, 0 deletions
diff --git a/smartwindow/args.go b/smartwindow/args.go
new file mode 100644
index 0000000..2481b9b
--- /dev/null
+++ b/smartwindow/args.go
@@ -0,0 +1,30 @@
+package smartwindow
+
+/*
+ this enables command line options from other packages like 'gui' and 'log'
+*/
+
+import (
+ "go.wit.com/log"
+)
+
+var NOW log.LogFlag
+var INFO log.LogFlag
+var SPEW log.LogFlag
+var WARN log.LogFlag
+
+func myreg(f *log.LogFlag, b bool, name string, desc string) {
+ f.B = b
+ f.Subsystem = "go.wit.com/gadgets/smartwindow"
+ f.Short = "smartWin"
+ f.Desc = desc
+ f.Name = name
+ f.Register()
+}
+
+func init() {
+ myreg(&NOW, true, "NOW", "temp debugging stuff")
+ myreg(&INFO, false, "INFO", "normal debugging stuff")
+ myreg(&SPEW, false, "SPEW", "spew stuff")
+ myreg(&WARN, true, "WARN", "bad things")
+}
diff --git a/smartwindow/common.go b/smartwindow/common.go
new file mode 100644
index 0000000..772a790
--- /dev/null
+++ b/smartwindow/common.go
@@ -0,0 +1,24 @@
+// This creates a 'smart window'
+// it should work even when it is hidden
+// from the gui toolkit plugins
+package smartwindow
+
+import (
+ "go.wit.com/log"
+)
+
+func (sw *SmartWindow) Ready() bool {
+ log.Log(WARN, "Ready() maybe not ready? sw =", sw)
+ if sw == nil {return false}
+ if sw == nil {return false}
+ if sw.window == nil {return false}
+ return sw.ready
+}
+
+func (sw *SmartWindow) Initialized() bool {
+ log.Log(WARN, "checking Initialized()")
+ if sw == nil {return false}
+ if sw == nil {return false}
+ if sw.parent == nil {return false}
+ return true
+}
diff --git a/smartwindow/new.go b/smartwindow/new.go
new file mode 100644
index 0000000..016d10b
--- /dev/null
+++ b/smartwindow/new.go
@@ -0,0 +1,32 @@
+package smartwindow
+
+import (
+ "go.wit.com/log"
+
+ "go.wit.com/gui/gadgets"
+)
+
+func New() *SmartWindow {
+ sw := SmartWindow {
+ hidden: true,
+ ready: false,
+ }
+
+ return &sw
+}
+
+func (sw *SmartWindow) InitWindow() {
+ if sw == nil {
+ log.Log(WARN, "not initalized yet (no parent for the window?)")
+ return
+ }
+ if sw.window != nil {
+ log.Log(WARN, "You already have a SmartWindow")
+ sw.ready = true
+ return
+ }
+
+ log.Log(WARN, "Creating the Window")
+ sw.window = gadgets.NewBasicWindow(sw.parent, sw.title)
+ sw.ready = true
+}
diff --git a/smartwindow/postReady.go b/smartwindow/postReady.go
new file mode 100644
index 0000000..bb3eab8
--- /dev/null
+++ b/smartwindow/postReady.go
@@ -0,0 +1,59 @@
+// This creates a 'smart window'
+// it should work even when it is hidden
+// from the gui toolkit plugins
+package smartwindow
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+)
+
+/*
+ all these functions run after the window is Ready()
+ so they should all start with that check
+*/
+
+// reports externally if something has changed
+// since the last time it was asked about it
+func (sw *SmartWindow) Changed() bool {
+ if ! sw.Ready() {return false}
+
+ if sw.changed {
+ sw.changed = false
+ return true
+ }
+ return false
+}
+
+func (sw *SmartWindow) Show() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Show() window ready =", sw.ready)
+ sw.window.Show()
+ sw.hidden = false
+}
+
+func (sw *SmartWindow) Hide() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Hide() window ready =", sw.ready)
+ sw.window.Hide()
+ sw.hidden = true
+}
+
+func (sw *SmartWindow) Toggle() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Toggle() window ready =", sw.ready)
+ if sw.hidden {
+ sw.Show()
+ } else {
+ sw.Hide()
+ }
+}
+
+func (sw *SmartWindow) Box() *gui.Node {
+ if ! sw.Ready() {return nil}
+
+ return sw.window.Box()
+}
diff --git a/smartwindow/preReady.go b/smartwindow/preReady.go
new file mode 100644
index 0000000..5009d54
--- /dev/null
+++ b/smartwindow/preReady.go
@@ -0,0 +1,84 @@
+// these are things you can config
+package smartwindow
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+)
+
+/* for now, run these before the window is ready
+ That is, they all start with:
+
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+*/
+
+func (sw *SmartWindow) Title(title string) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Title() =", title)
+ sw.title = title
+}
+
+func (sw *SmartWindow) SetParent(p *gui.Node) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "SetParent")
+ if sw.parent == nil {
+ log.Log(WARN, "SetParent =", p)
+ sw.parent = p
+ return
+ } else {
+ log.Log(WARN, "SetParent was already set. TODO: Move to new parent")
+ }
+}
+
+func (sw *SmartWindow) SetDraw(f func(*SmartWindow)) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ sw.populate = f
+}
+
+func (sw *SmartWindow) Make() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Make() window ready =", sw.ready)
+ sw.window.Make()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
+func (sw *SmartWindow) Draw() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Draw() window ready =", sw.ready)
+ sw.window.Draw()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
+
+func (sw *SmartWindow) Vertical() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Draw() window ready =", sw.ready)
+ sw.window.Draw()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
diff --git a/smartwindow/structs.go b/smartwindow/structs.go
new file mode 100644
index 0000000..d70ea3c
--- /dev/null
+++ b/smartwindow/structs.go
@@ -0,0 +1,21 @@
+package smartwindow
+
+import (
+ "go.wit.com/gui/gui"
+ "go.wit.com/gui/gadgets"
+)
+
+type SmartWindow struct {
+ ready bool // track if the window is ready
+ hidden bool // track if the window is hidden from the toolkits
+ changed bool // track if something changed in the window
+
+ title string // what the user sees as the name
+ name string // the programatic name aka: "CALANDAR"
+
+ parent *gui.Node // where to place the window if you try to draw it
+ window *gadgets.BasicWindow // the underlying BasicWindow
+ box *gui.Node // the box inside the window // get this from BasicWindow() ?
+
+ populate func(*SmartWindow) // the function to generate the widgets
+}