2024-01-17 23:54:19 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
// "os"
|
|
|
|
"go.wit.com/dev/andlabs/ui"
|
|
|
|
_ "go.wit.com/dev/andlabs/ui/winmanifest"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:27:19 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-17 23:54:19 -06:00
|
|
|
|
|
|
|
"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) {
|
2024-01-21 11:30:12 -06:00
|
|
|
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())
|
2024-01-17 23:54:19 -06:00
|
|
|
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)
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "SPEEDY ptk == nil", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
log.Sleep(1)
|
|
|
|
panic("ptk == nil")
|
|
|
|
}
|
|
|
|
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(INFO, "place() switch", p.WidgetType, n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
switch p.WidgetType {
|
|
|
|
case widget.Grid:
|
|
|
|
tk.gridX = n.State.GridOffset.X - 1
|
|
|
|
tk.gridY = n.State.GridOffset.Y - 1
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(INFO, "place() on Grid at gridX,gridY", tk.gridX, tk.gridY)
|
2024-01-17 23:54:19 -06:00
|
|
|
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 {
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ANDLABS, "place() andlabs hack group to use add a box", n.GetProgName(), n.WidgetType)
|
2024-01-19 18:12:30 -06:00
|
|
|
n.State.Direction = widget.Vertical
|
2024-01-17 23:54:19 -06:00
|
|
|
ptk.uiBox = rawBox(n)
|
|
|
|
ptk.uiGroup.SetChild(ptk.uiBox)
|
|
|
|
}
|
2024-01-18 16:08:04 -06:00
|
|
|
if n.WidgetType == widget.Textbox {
|
|
|
|
ptk.uiBox.Append(tk.uiControl, true)
|
|
|
|
} else {
|
2024-01-19 12:18:11 -06:00
|
|
|
ptk.uiBox.Append(tk.uiControl, n.State.Expand)
|
2024-01-18 16:08:04 -06:00
|
|
|
}
|
2024-01-17 23:54:19 -06:00
|
|
|
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")
|
2024-02-05 15:04:01 -06:00
|
|
|
ptk.uiTab.Append(n.State.Label, tk.uiControl)
|
2024-01-17 23:54:19 -06:00
|
|
|
ptk.boxC += 1
|
|
|
|
return true
|
|
|
|
case widget.Box:
|
|
|
|
log.Log(INFO, "place() uiBox =", ptk.uiBox)
|
|
|
|
log.Log(INFO, "place() uiControl =", tk.uiControl)
|
2024-01-18 16:08:04 -06:00
|
|
|
if n.WidgetType == widget.Textbox {
|
|
|
|
ptk.uiBox.Append(tk.uiControl, true)
|
|
|
|
} else {
|
2024-01-19 12:18:11 -06:00
|
|
|
ptk.uiBox.Append(tk.uiControl, n.State.Expand)
|
2024-01-18 16:08:04 -06:00
|
|
|
}
|
2024-01-17 23:54:19 -06:00
|
|
|
ptk.boxC += 1
|
|
|
|
return true
|
|
|
|
case widget.Window:
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(INFO, "Adding Something to Window", n.WidgetId, n.GetProgName())
|
2024-02-15 08:15:38 -06:00
|
|
|
if n.WidgetType == widget.Window {
|
|
|
|
log.Log(INFO, "TODO: make window in a window a tab", n.WidgetId, n.GetProgName())
|
|
|
|
return true
|
|
|
|
}
|
2024-01-17 23:54:19 -06:00
|
|
|
ptk.uiWindow.SetChild(tk.uiControl)
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
log.Log(ERROR, "place() how? Parent =", p.WidgetId, p.WidgetType)
|
|
|
|
}
|
2024-01-21 11:30:12 -06:00
|
|
|
log.Log(ERROR, "newplace() returned without doing anything", n.WidgetId, n.GetProgName())
|
2024-01-17 23:54:19 -06:00
|
|
|
return false
|
|
|
|
}
|