summaryrefslogtreecommitdiff
path: root/andlabs/place.go
diff options
context:
space:
mode:
Diffstat (limited to 'andlabs/place.go')
-rw-r--r--andlabs/place.go94
1 files changed, 94 insertions, 0 deletions
diff --git a/andlabs/place.go b/andlabs/place.go
new file mode 100644
index 0000000..59a55d9
--- /dev/null
+++ b/andlabs/place.go
@@ -0,0 +1,94 @@
+package main
+
+import (
+ "github.com/andlabs/ui"
+ _ "github.com/andlabs/ui/winmanifest"
+
+
+ "go.wit.com/log"
+ "go.wit.com/gui/widget"
+)
+
+// This routine is very specific to this toolkit
+// It's annoying and has to be copied to each widget when there are changes
+// it could be 'simplfied' maybe or made to be more generic, but this is as far as I've gotten
+// it's probably not worth working much more on this toolkit, the andlabs/ui has been great and got me here!
+// but it's time to write direct GTK, QT, macos and windows toolkit plugins
+// -- jcarr 2023/03/09
+
+// Grid numbering examples by (X,Y)
+// ---------
+// -- (1) --
+// -- (2) --
+// ---------
+//
+// -----------------------------
+// -- (1,1) -- (1,2) -- (1,3) --
+// -- (2,1) -- (2,2) -- (2,3) --
+// -----------------------------
+
+// internally for andlabs/ui
+// (x&y flipped and start at zero)
+// -----------------------------
+// -- (0,0) -- (1,0) -- (1,0) --
+// -- (0,1) -- (1,1) -- (1,1) --
+// -----------------------------
+func (p *node) place(n *node) bool {
+ log.Log(INFO, "place() START", n.WidgetType, n.Name)
+
+ if (p.tk == nil) {
+ log.Log(ERROR, "p.tk == nil", p.Name, p.ParentId, p.WidgetType, p.tk)
+ log.Log(ERROR, "n = ", n.Name, n.ParentId, n.WidgetType, n.tk)
+ panic("p.tk == nil")
+ }
+
+ log.Log(INFO, "place() switch", p.WidgetType)
+ switch p.WidgetType {
+ case widget.Grid:
+ log.Log(INFO, "place() Grid try at Parent X,Y =", n.X, n.Y)
+ n.tk.gridX = n.AtW - 1
+ n.tk.gridY = n.AtH - 1
+ log.Log(INFO, "place() Grid try at gridX,gridY", n.tk.gridX, n.tk.gridY)
+ // at the very end, subtract 1 from X & Y since andlabs/ui starts counting at zero
+ p.tk.uiGrid.Append(n.tk.uiControl,
+ n.tk.gridX, n.tk.gridY, 1, 1,
+ false, ui.AlignFill, false, ui.AlignFill)
+ return true
+ case widget.Group:
+ if (p.tk.uiBox == nil) {
+ log.Log(WARN, "place() andlabs hack group to use add a box", n.Name, n.WidgetType, "horizontal =", n.horizontal)
+ p.tk.uiBox = n.rawBox()
+ p.tk.uiGroup.SetChild(p.tk.uiBox)
+ }
+ p.tk.uiBox.Append(n.tk.uiControl, stretchy)
+ return true
+ case widget.Tab:
+ if (p.tk.uiTab == nil) {
+ log.Log(ERROR, "p.tk.uiTab == nil for n.WidgetId =", n.WidgetId, "p.tk =", p.tk)
+ panic("p.tk.uiTab == nil")
+ }
+ if (n.tk.uiControl == nil) {
+ log.Log(ERROR, "n.tk.uiControl == nil for n.WidgetId =", n.WidgetId, "n.tk =", n.tk)
+ panic("n.tk.uiControl == nil")
+ }
+ log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab")
+ // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() node=", n.WidgetId, n.Name, n.Text, n.WidgetType)
+ // log.Log(ERROR, "THIS SHOULD NEVER HAPPEN ??????? trying to place() on parent=", p.WidgetId, p.Name, p.Text, p.WidgetType)
+ // panic("n.tk.uiControl == nil")
+ p.tk.uiTab.Append(n.Text, n.tk.uiControl)
+ p.tk.boxC += 1
+ return true
+ case widget.Box:
+ log.Log(INFO, "place() uiBox =", p.tk.uiBox)
+ log.Log(INFO, "place() uiControl =", n.tk.uiControl)
+ p.tk.uiBox.Append(n.tk.uiControl, stretchy)
+ p.tk.boxC += 1
+ return true
+ case widget.Window:
+ p.tk.uiWindow.SetChild(n.tk.uiControl)
+ return true
+ default:
+ log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
+ }
+ return false
+}