package main import ( // "os" "go.wit.com/dev/andlabs/ui" _ "go.wit.com/dev/andlabs/ui/winmanifest" "go.wit.com/log" "go.wit.com/widget" "go.wit.com/toolkits/tree" ) // 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 place(p *tree.Node, n *tree.Node) bool { log.Log(INFO, "place() 1 START", n.WidgetType, n.GetProgName(), n.GetLabel()) if !ready(n) { if n.WidgetType == widget.Window { // TODO: figure out window in window placement return true } log.Log(ERROR, "place() 1 START not ready()", n.WidgetType, n.GetProgName(), n.GetLabel()) return false } var tk, ptk *guiWidget tk = n.TK.(*guiWidget) ptk = p.TK.(*guiWidget) if ptk == nil { log.Log(ERROR, "ptk == nil", p.GetProgName(), p.ParentId, p.WidgetType, ptk) log.Log(ERROR, "n = ", n.GetProgName(), n.ParentId, n.WidgetType, tk) log.Log(ERROR, "SPEEDY ptk == nil", n.WidgetId, n.GetProgName()) log.Sleep(1) panic("ptk == nil") } log.Log(INFO, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName()) switch p.WidgetType { case widget.Grid: tk.gridX = n.State.GridOffset.X - 1 tk.gridY = n.State.GridOffset.Y - 1 log.Log(INFO, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY) ptk.uiGrid.Append(tk.uiControl, tk.gridX, tk.gridY, 1, 1, false, ui.AlignFill, false, ui.AlignFill) return true case widget.Group: if ptk.uiBox == nil { log.Log(ANDLABS, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType) n.State.Direction = widget.Vertical ptk.uiBox = rawBox(n) ptk.uiGroup.SetChild(ptk.uiBox) } if n.WidgetType == widget.Textbox { ptk.uiBox.Append(tk.uiControl, true) } else { ptk.uiBox.Append(tk.uiControl, n.State.Expand) } return true case widget.Tab: if ptk.uiTab == nil { log.Log(ERROR, "ptk.uiTab == nil for n.WidgetId =", n.WidgetId, "ptk =", ptk) panic("ptk.uiTab == nil") } if tk.uiControl == nil { log.Log(ERROR, "tk.uiControl == nil for n.WidgetId =", n.WidgetId, "tk =", tk) panic("tk.uiControl == nil") } log.Log(ERROR, "CHECK LOGIC ON THIS. APPENDING directly into a window without a tab") ptk.uiTab.Append(n.State.Label, tk.uiControl) ptk.boxC += 1 return true case widget.Box: log.Log(INFO, "place() uiBox =", ptk.uiBox) log.Log(INFO, "place() uiControl =", tk.uiControl) if n.WidgetType == widget.Textbox { ptk.uiBox.Append(tk.uiControl, true) } else { ptk.uiBox.Append(tk.uiControl, n.State.Expand) } ptk.boxC += 1 return true case widget.Window: log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName()) ptk.uiWindow.SetChild(tk.uiControl) return true default: log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType) } log.Log(ERROR, "newplace() returned without doing anything", n.WidgetId, n.GetProgName()) return false }