summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-05-09 18:34:09 -0500
committerJeff Carr <[email protected]>2023-05-09 18:34:09 -0500
commitb392c40969e105b00efa262042d647303d6fbc2c (patch)
tree95e25e5e288c096df69c36e2293af5ebc17a1d78
parent706bcef867ff2a26ab62a1e3d668ac441575df62 (diff)
andlabs: now attempt grid placement
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--grid.go29
-rw-r--r--node.go6
-rw-r--r--plugin.go5
-rw-r--r--tab.go4
-rw-r--r--toolkit/widget.go4
5 files changed, 33 insertions, 15 deletions
diff --git a/grid.go b/grid.go
index b773b8b..67a2924 100644
--- a/grid.go
+++ b/grid.go
@@ -42,23 +42,28 @@ func (n *Node) NewGrid(name string, w int, h int) *Node {
}
// true if the grid already have a child at W,H
-func (n *Node) gridCollision(w int, h int) bool {
+func (n *Node) gridCollision() bool {
for _, child := range n.children {
- if ((child.AtW == w) && (child.AtH == h)) {
+ if ((child.AtW == n.NextW) && (child.AtH == n.NextH)) {
return true
}
}
return false
}
-// increments NextW & NextH
-func (n *Node) gridIncrement(w int, h int) bool {
- for _, child := range n.children {
- if ((child.AtW == w) && (child.AtH == h)) {
- return true
- }
+// keeps incrementing NextW & NextH until there is not a widget
+func (n *Node) gridIncrement() {
+ if ! n.gridCollision() {
+ return
}
- return false
+
+ n.NextH += 1
+ if (n.NextH > n.Y) {
+ n.NextW += 1
+ n.NextH = 1
+ }
+
+ n.gridIncrement()
}
func (n *Node) At(w int, h int) *Node {
@@ -69,9 +74,9 @@ func (n *Node) At(w int, h int) *Node {
n.NextW = w
n.NextH = h
- // TODO: check for a collision here
- if n.gridCollision(w,h) {
- // TODO: find free next w,h
+ n.gridIncrement()
+ if (n.NextW != w) || (n.NextH != h) {
+ log(logError, "At() (W,H)", w, h, " was moved to avoid a collision (W,H) =", n.NextW, n.NextH)
}
return n
}
diff --git a/node.go b/node.go
index f9b35a9..93d0ca8 100644
--- a/node.go
+++ b/node.go
@@ -12,6 +12,12 @@ func (n *Node) newNode(title string, t toolkit.WidgetType, custom func()) *Node
newN.WidgetType = t
newN.Custom = custom
+ if n.WidgetType == toolkit.Grid {
+ n.gridIncrement()
+ }
+ newN.AtW = n.NextW
+ newN.AtH = n.NextH
+
n.children = append(n.children, newN)
newN.parent = n
return newN
diff --git a/plugin.go b/plugin.go
index 31b47c3..eba3256 100644
--- a/plugin.go
+++ b/plugin.go
@@ -212,6 +212,9 @@ func newAction(n *Node, atype toolkit.ActionType) *toolkit.Action {
a.Name = n.Name
a.Text = n.Text
a.WidgetId = n.id
+ if (n.parent != nil) {
+ a.ParentId = n.parent.id
+ }
a.WidgetType = n.WidgetType
return &a
@@ -233,7 +236,7 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
if (where != nil) {
a.ParentId = where.id
if (where.WidgetType == toolkit.Grid) {
- placeGrid(a, n, where)
+ n.gridIncrement()
}
}
diff --git a/tab.go b/tab.go
index 0669cf6..59f6496 100644
--- a/tab.go
+++ b/tab.go
@@ -22,8 +22,8 @@ func (n *Node) NewTab(text string) *Node {
log(logError, "NewTab() parent =", n.parent)
if (n.parent.WidgetType == toolkit.Root) {
// also broken
- log(logError, "NewTab() TODO: make a window here", n)
- panic("NewTab did not get passed a window")
+ log(logError, "NewTab() TODO: make or find a window here", n)
+ panic("NewTab() did not get passed a window")
}
// go up the binary tree until we find a window widget to add a tab too
return n.parent.NewTab(text)
diff --git a/toolkit/widget.go b/toolkit/widget.go
index 38d4afc..4806f1c 100644
--- a/toolkit/widget.go
+++ b/toolkit/widget.go
@@ -38,6 +38,10 @@ type Action struct {
X int
Y int
+ // This is used for the widget's grid position
+ W int
+ H int
+
// Put space around elements to improve look & feel
Margin bool