summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-06 13:53:15 -0600
committerJeff Carr <[email protected]>2024-01-06 13:53:15 -0600
commitb3dfc689abe6699112518ddaf5e12aa87ef931f8 (patch)
tree2f5e14ac484ac45e52e58a57dd95f904a0d38094
parentd075b29aff66e784a615a0a3e436ae7433556789 (diff)
sierpinski carpet mode
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--box.go6
-rw-r--r--button.go6
-rw-r--r--checkbox.go6
-rw-r--r--common.go91
-rw-r--r--dropdown.go12
-rw-r--r--grid.go6
-rw-r--r--group.go6
-rw-r--r--image.go6
-rw-r--r--int.go27
-rw-r--r--label.go9
-rw-r--r--main.go1
-rw-r--r--node.go1
-rw-r--r--slider.go10
-rw-r--r--spinner.go6
-rw-r--r--structs.go6
-rw-r--r--textbox.go12
-rw-r--r--window.go45
17 files changed, 167 insertions, 89 deletions
diff --git a/box.go b/box.go
index 9c8bda4..0dbc674 100644
--- a/box.go
+++ b/box.go
@@ -8,7 +8,9 @@ func (parent *Node) NewBox(name string, b bool) *Node {
newNode := parent.newNode(name, widget.Box)
newNode.B = b
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/button.go b/button.go
index 246c39c..3feb046 100644
--- a/button.go
+++ b/button.go
@@ -6,8 +6,10 @@ func (parent *Node) NewButton(name string, custom func()) *Node {
newNode := parent.newNode(name, widget.Button)
newNode.Custom = custom
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/checkbox.go b/checkbox.go
index 29722fe..81beb2d 100644
--- a/checkbox.go
+++ b/checkbox.go
@@ -9,7 +9,9 @@ func (n *Node) Checked() bool {
func (n *Node) NewCheckbox(name string) *Node {
newNode := n.newNode(name, widget.Checkbox)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/common.go b/common.go
index e9a493d..614a749 100644
--- a/common.go
+++ b/common.go
@@ -12,26 +12,34 @@ import (
// functions for handling text related GUI elements
func (n *Node) Show() *Node {
- a := newAction(n, widget.Show)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Show)
+ sendAction(a)
+ }
return n
}
func (n *Node) Hide() *Node {
- a := newAction(n, widget.Hide)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Hide)
+ sendAction(a)
+ }
return n
}
func (n *Node) Enable() *Node {
- a := newAction(n, widget.Enable)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Enable)
+ sendAction(a)
+ }
return n
}
func (n *Node) Disable() *Node {
- a := newAction(n, widget.Disable)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Disable)
+ sendAction(a)
+ }
return n
}
@@ -40,8 +48,10 @@ func (n *Node) Add(str string) {
n.S = str
- a := newAction(n, widget.Add)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Add)
+ sendAction(a)
+ }
}
func (n *Node) AddText(str string) {
@@ -50,8 +60,10 @@ func (n *Node) AddText(str string) {
n.Text = str
n.S = str
- a := newAction(n, widget.AddText)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.AddText)
+ sendAction(a)
+ }
}
func (n *Node) SetText(text string) *Node {
@@ -60,8 +72,10 @@ func (n *Node) SetText(text string) *Node {
n.Text = text
n.S = text
- a := newAction(n, widget.SetText)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.SetText)
+ sendAction(a)
+ }
return n
}
@@ -86,8 +100,10 @@ func (n *Node) Set(val any) {
log.Error(errors.New("Set() unknown type"), "v =", v)
}
- a := newAction(n, widget.Set)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.Set)
+ sendAction(a)
+ }
}
func (n *Node) AppendText(str string) {
@@ -95,8 +111,10 @@ func (n *Node) AppendText(str string) {
n.Text = tmp
n.S = tmp
- a := newAction(n, widget.SetText)
- sendAction(a)
+ if ! n.hidden {
+ a := newAction(n, widget.SetText)
+ sendAction(a)
+ }
}
// THESE TWO FUNCTIONS ARE TERRIBLY NAMED AND NEED TO BE FIXED
@@ -169,33 +187,48 @@ func commonCallback(n *Node) {
}
func (n *Node) Margin() *Node {
- a := newAction(n, widget.Margin)
- sendAction(a)
+ n.margin = true
+ if ! n.hidden {
+ a := newAction(n, widget.Margin)
+ sendAction(a)
+ }
return n
}
func (n *Node) Unmargin() *Node {
- a := newAction(n, widget.Unmargin)
- sendAction(a)
+ n.margin = false
+ if ! n.hidden {
+ a := newAction(n, widget.Unmargin)
+ sendAction(a)
+ }
return n
}
func (n *Node) Pad() *Node {
- a := newAction(n, widget.Pad)
- sendAction(a)
+ n.pad = true
+ if ! n.hidden {
+ a := newAction(n, widget.Pad)
+ sendAction(a)
+ }
return n
}
func (n *Node) Unpad() *Node {
- a := newAction(n, widget.Unpad)
- sendAction(a)
+ n.pad = false
+ if ! n.hidden {
+ a := newAction(n, widget.Unpad)
+ sendAction(a)
+ }
return n
}
func (n *Node) Expand() *Node {
- a := newAction(n, widget.Pad)
- a.Expand = true
- sendAction(a)
+ n.expand = true
+ if ! n.hidden {
+ a := newAction(n, widget.Pad)
+ a.Expand = true
+ sendAction(a)
+ }
return n
}
diff --git a/dropdown.go b/dropdown.go
index 8afc19c..3d5a15c 100644
--- a/dropdown.go
+++ b/dropdown.go
@@ -22,8 +22,10 @@ func (n *Node) SetDropdownName(name string) {
func (n *Node) NewDropdown(name string) *Node {
newNode := n.newNode(name, widget.Dropdown)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
@@ -31,8 +33,10 @@ func (n *Node) NewDropdown(name string) *Node {
func (n *Node) NewCombobox(name string) *Node {
newNode := n.newNode(name, widget.Combobox)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/grid.go b/grid.go
index e5d5e42..e1eb7ac 100644
--- a/grid.go
+++ b/grid.go
@@ -31,8 +31,10 @@ func (n *Node) NewGrid(name string, w int, h int) *Node {
newNode.NextW = 1
newNode.NextH = 1
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
// by default, always pad grids
newNode.Pad()
diff --git a/group.go b/group.go
index 9971d63..e4fa7ca 100644
--- a/group.go
+++ b/group.go
@@ -11,8 +11,10 @@ func (parent *Node) NewGroup(name string) *Node {
var newNode *Node
newNode = parent.newNode(name, widget.Group)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
// by default, always pad groups
newNode.Pad()
diff --git a/image.go b/image.go
index 8963e54..bd6b972 100644
--- a/image.go
+++ b/image.go
@@ -8,7 +8,9 @@ func (parent *Node) NewImage(name string) *Node {
var newNode *Node
newNode = parent.newNode(name, widget.Image)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/int.go b/int.go
deleted file mode 100644
index 09e1ec7..0000000
--- a/int.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package gui
-
-/*
- Get the int from the gui toolkit
- because eventually this gui package should become it's own seperate go routine and never interact from the
- gui subroutine back into the upstream application using the gui package
-
- TODO: instead store the int in the Node structure? (this is probably a better idea)
- because technically every interaction with the toolkit has to go through the Queue() goroutine.
- Is it "has to go" or "should go"? Probably it makes sense to strictly inforce it. No "callback" functions. IPC only (go channels)
-*/
-/*
-func (n *Node) Int() int {
- return n.widget.I
-}
-
-// which name to use?
-func (n *Node) Value() int {
- return n.Int()
-}
-
-func (n *Node) SetValue(i int) {
- log(debugGui, "gui.SetValue() START")
- // FIXME: this needs to be redone
- // n.toolkit.SetValue(i)
-}
-*/
diff --git a/label.go b/label.go
index 99ed9d8..a91b794 100644
--- a/label.go
+++ b/label.go
@@ -6,9 +6,10 @@ import (
func (parent *Node) NewLabel(text string) *Node {
newNode := parent.newNode(text, widget.Label)
- a := newAction(newNode, widget.Add)
- a.Text = text
- a.S = text
- sendAction(a)
+
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/main.go b/main.go
index cefcdca..19570d8 100644
--- a/main.go
+++ b/main.go
@@ -24,6 +24,7 @@ func init() {
// Populates the top of the binary tree
me.rootNode = addNode("guiBinaryTree")
me.rootNode.WidgetType = widget.Root
+ me.rootNode.hidden = false // always send the rootNode to the toolkits
// used to pass debugging flags to the toolkit plugins
me.flag = me.rootNode.newNode("flag", 0)
diff --git a/node.go b/node.go
index 518b768..b45269e 100644
--- a/node.go
+++ b/node.go
@@ -19,6 +19,7 @@ func (n *Node) newNode(title string, t widget.WidgetType) *Node {
}
newN.AtW = n.NextW
newN.AtH = n.NextH
+ newN.hidden = n.hidden // by default, use the value from above
n.children = append(n.children, newN)
newN.parent = n
diff --git a/slider.go b/slider.go
index 6638cd3..fd2b207 100644
--- a/slider.go
+++ b/slider.go
@@ -14,10 +14,12 @@ func (parent *Node) NewSlider(name string, x int, y int) *Node {
newNode.X = x
newNode.Y = y
- a := newAction(newNode, widget.Add)
- a.X = x
- a.Y = y
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ a.X = x
+ a.Y = y
+ sendAction(a)
+ }
return newNode
}
diff --git a/spinner.go b/spinner.go
index 0de54f6..301ed61 100644
--- a/spinner.go
+++ b/spinner.go
@@ -15,7 +15,9 @@ func (parent *Node) NewSpinner(name string, x int, y int) *Node {
newNode.X = x
newNode.Y = y
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/structs.go b/structs.go
index 792bcc8..308aeb7 100644
--- a/structs.go
+++ b/structs.go
@@ -48,7 +48,11 @@ type guiConfig struct {
// The Node is a binary tree. This is how all GUI elements are stored
// simply the name and the size of whatever GUI element exists
type Node struct {
- id int
+ id int // should be unique
+ hidden bool // Sierpinski Carpet mode. It's there, but you can't see it.
+ pad bool // the toolkit may use this. it's up to the toolkit
+ margin bool // the toolkit may use this. it's up to the toolkit
+ expand bool // the toolkit may use this. it's up to the toolkit
WidgetType widget.WidgetType
diff --git a/textbox.go b/textbox.go
index fec0c2e..16837c0 100644
--- a/textbox.go
+++ b/textbox.go
@@ -13,8 +13,10 @@ func (parent *Node) NewTextbox(name string) *Node {
log.Log(GUI, "NewTextbox changed =", name)
}
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
@@ -27,7 +29,9 @@ func (parent *Node) NewEntryLine(name string) *Node {
log.Log(GUI, "NewTextbox changed =", name)
}
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
return newNode
}
diff --git a/window.go b/window.go
index a0676b2..54d4331 100644
--- a/window.go
+++ b/window.go
@@ -16,7 +16,48 @@ func (parent *Node) NewWindow(title string) *Node {
log.Info("NewWindow()", title)
- a := newAction(newNode, widget.Add)
- sendAction(a)
+ if ! newNode.hidden {
+ a := newAction(newNode, widget.Add)
+ sendAction(a)
+ }
+ return newNode
+}
+
+// allow window create without actually sending it to the toolkit
+func (parent *Node) RawWindow(title string) *Node {
+ var newNode *Node
+
+ // Windows are created off of the master node of the Binary Tree
+ newNode = parent.newNode(title, widget.Window)
+ newNode.Custom = StandardExit
+ newNode.hidden = true
+
+ log.Info("RawWindow()", title)
return newNode
}
+
+// TODO: should do this recursively
+func (n *Node) UnDraw() *Node {
+ if ! n.hidden {
+ n.Hide()
+ }
+ n.hidden = true
+ return n
+}
+
+// TODO: should do this recursively
+func (n *Node) Draw() *Node {
+ n.hidden = false
+
+ a := newAction(n, widget.Add)
+ sendAction(a)
+ return n
+}
+
+// if the toolkit supports a gui with pixels, it might honor this. no promises
+// consider this a 'recommendation' or developer 'preference' to the toolkit
+func (n *Node) PixelSize(w, h int) *Node {
+ n.width = w
+ n.height = w
+ return n
+}