2024-01-03 12:33:25 -06:00
|
|
|
package debugger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2024-01-18 01:34:32 -06:00
|
|
|
"strconv"
|
2024-01-03 12:33:25 -06:00
|
|
|
|
2024-01-18 22:36:35 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 01:34:32 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
2024-01-18 22:36:35 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-03 12:33:25 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
func setActiveWidget(w *gui.Node) {
|
|
|
|
if (w == nil) {
|
|
|
|
log.Log(debugError, "setActiveWidget() was sent nil !!!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
activeWidget = w
|
|
|
|
log.Log(true, "The Widget is set to", w.id, w.Name)
|
|
|
|
if (activeLabel == nil) {
|
|
|
|
// the debug window doesn't exist yet so you can't display the change
|
|
|
|
// TODO: make a fake binary tree for this(?)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
title := "ID =" + strconv.Itoa(w.id) + " " + w.Name
|
|
|
|
activeLabel.SetText(title)
|
|
|
|
activeLabelType.SetText("widget.Type = " + w.WidgetType.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2024-01-20 20:24:58 -06:00
|
|
|
func DebugWidgetWindow() *gadgets.BasicWindow {
|
|
|
|
p := gui.TreeRoot()
|
2024-01-04 23:28:55 -06:00
|
|
|
var w *gadgets.BasicWindow
|
|
|
|
w = gadgets.NewBasicWindow(p, "Widgets")
|
2024-01-05 16:56:03 -06:00
|
|
|
w.Draw()
|
2024-01-03 12:33:25 -06:00
|
|
|
|
2024-01-04 23:28:55 -06:00
|
|
|
g := w.Box().NewGroup("widget:").Pad()
|
2024-01-03 12:33:25 -06:00
|
|
|
|
|
|
|
g2 := g.NewGroup("widget:")
|
|
|
|
activeLabel = g2.NewLabel("undef")
|
|
|
|
g2 = g.NewGroup("type:")
|
|
|
|
activeLabelType = g2.NewLabel("undef")
|
|
|
|
g2 = g.NewGroup("New name:")
|
2024-01-17 22:43:57 -06:00
|
|
|
activeLabelNewName = g2.NewCombobox()
|
2024-01-03 12:33:25 -06:00
|
|
|
activeLabelNewName.AddText("penguin")
|
|
|
|
activeLabelNewName.AddText("snow")
|
|
|
|
activeLabelNewName.AddText("GO")
|
|
|
|
activeLabelNewName.AddText("debian")
|
|
|
|
activeLabelNewName.AddText("RiscV")
|
|
|
|
|
|
|
|
g2 = g.NewGroup("At X:")
|
|
|
|
activeLabelNewX = g2.NewSpinner("tmp spinner", -1, 100)
|
|
|
|
|
|
|
|
g2 = g.NewGroup("At Y:")
|
|
|
|
activeLabelNewY = g2.NewSpinner("tmp spinner", -1, 100)
|
|
|
|
|
|
|
|
g2 = g.NewGroup("bool B:")
|
|
|
|
activeLabelNewB = g2.NewCheckbox("tmp bool")
|
|
|
|
|
|
|
|
// common things that should work against each widget
|
2024-01-04 23:28:55 -06:00
|
|
|
g = w.Box().NewGroup("common things")
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Enable()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Enable()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Disable()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Disable()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Show()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Show()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Hide()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Hide()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Dump()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Dump()
|
|
|
|
})
|
|
|
|
|
2024-01-04 23:28:55 -06:00
|
|
|
g = w.Box().NewGroup("add things")
|
2024-01-03 12:33:25 -06:00
|
|
|
debugAddWidgetButton(g)
|
|
|
|
g.NewLabel("experiments:")
|
|
|
|
debugAddWidgetButtons(g)
|
|
|
|
|
2024-01-04 23:28:55 -06:00
|
|
|
g = w.Box().NewGroup("change things")
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("AddText()", func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
activeWidget.AddText(activeLabelNewName.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
/*
|
2024-01-18 01:34:32 -06:00
|
|
|
activeWidget.S = activeLabelNewName.S
|
|
|
|
a := newAction(activeWidget, toolkit.AddText)
|
|
|
|
sendAction(a)
|
2024-01-03 12:33:25 -06:00
|
|
|
*/
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("SetText()", func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
activeWidget.SetText(activeLabelNewName.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
/*
|
2024-01-18 01:34:32 -06:00
|
|
|
activeWidget.S = activeLabelNewName.String()
|
|
|
|
a := newAction(activeWidget, toolkit.SetText)
|
|
|
|
sendAction(a)
|
2024-01-03 12:33:25 -06:00
|
|
|
*/
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Margin()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Margin()
|
|
|
|
/*
|
2024-01-18 01:34:32 -06:00
|
|
|
a := newAction(activeWidget, toolkit.Margin)
|
|
|
|
sendAction(a)
|
2024-01-03 12:33:25 -06:00
|
|
|
*/
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Unmargin()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Unmargin()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Pad()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Pad()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Unpad()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Unpad()
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Move(junk)", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
log.Warn("gui.Node Move() not implemented yet")
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
g.NewButton("Delete()", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Delete(activeWidget)
|
|
|
|
})
|
|
|
|
|
2024-01-04 23:28:55 -06:00
|
|
|
g = w.Box().NewGroup("not working?")
|
|
|
|
activeJunk = w.Box().NewGroup("junk:")
|
2024-01-03 12:33:25 -06:00
|
|
|
activeJunk.NewLabel("test junk")
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
if activeWidget == nil {
|
2024-01-20 20:24:58 -06:00
|
|
|
setActiveWidget(me.treeRoot)
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
2024-01-04 23:28:55 -06:00
|
|
|
|
|
|
|
return w
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func debugAddWidgetButtons(n *gui.Node) {
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Dropdown", func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
a := activeWidget.NewDropdown()
|
2024-01-03 12:33:25 -06:00
|
|
|
a.AddText("this is better than tcl/tk")
|
|
|
|
a.AddText("make something for tim for qflow")
|
|
|
|
a.AddText("and for riscv")
|
2024-01-18 01:34:32 -06:00
|
|
|
a.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Log(WARN, "custom dropdown() a =", a.GetProgName(), a.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Combobox", func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
a := activeWidget.NewCombobox()
|
2024-01-03 12:33:25 -06:00
|
|
|
a.AddText("mirrors.wit.com")
|
|
|
|
a.AddText("go.wit.com")
|
2024-01-18 01:34:32 -06:00
|
|
|
a.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Log(WARN, "custom combobox() a =", a.GetProgName(), a.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Grid", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
// Grid numbering by (X,Y)
|
|
|
|
// -----------------------------
|
|
|
|
// -- (1,1) -- (2,1) -- (3,1) --
|
|
|
|
// -- (1,2) -- (2,1) -- (3,1) --
|
|
|
|
// -----------------------------
|
|
|
|
|
|
|
|
// SetDebug(true)
|
|
|
|
debugGrid = activeWidget.NewGrid("tmp grid", 2, 3)
|
|
|
|
debugGridLabel = debugGrid.NewLabel("mirrors.wit.com")
|
|
|
|
/*
|
2024-01-18 01:34:32 -06:00
|
|
|
debugGrid.SetNext(0,1)
|
|
|
|
debugGrid.NewLabel("foo (0,1)")
|
|
|
|
debugGrid.SetNext(1,1)
|
|
|
|
debugGrid.NewLabel("foo (1,1)")
|
|
|
|
debugGrid.SetNext(2,1)
|
|
|
|
debugGrid.NewLabel("foo (2,1)")
|
2024-01-03 12:33:25 -06:00
|
|
|
*/
|
|
|
|
// SetDebug(false)
|
2024-01-20 20:24:58 -06:00
|
|
|
DebugWidgetWindow()
|
2024-01-03 12:33:25 -06:00
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Image", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.NewImage("image")
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Box(horizontal)", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
a := activeWidget.NewBox("hBox", true)
|
|
|
|
a.NewLabel("hBox")
|
|
|
|
a.NewLabel("hBox 2")
|
|
|
|
})
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Box(vertical)", func() {
|
2024-01-03 12:33:25 -06:00
|
|
|
a := activeWidget.NewBox("vBox", false)
|
|
|
|
a.NewLabel("vBox")
|
|
|
|
a.NewLabel("vBox 2")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func debugAddWidgetButton(n *gui.Node) {
|
2024-01-17 22:43:57 -06:00
|
|
|
activeLabelNewType = n.NewDropdown()
|
2024-01-03 12:33:25 -06:00
|
|
|
activeLabelNewType.AddText("Window")
|
|
|
|
activeLabelNewType.AddText("Tab")
|
|
|
|
activeLabelNewType.AddText("Frame")
|
|
|
|
activeLabelNewType.AddText("Grid")
|
|
|
|
activeLabelNewType.AddText("Group")
|
|
|
|
activeLabelNewType.AddText("Box")
|
|
|
|
activeLabelNewType.AddText("Button")
|
|
|
|
activeLabelNewType.AddText("Checkbox")
|
|
|
|
activeLabelNewType.AddText("Dropdown")
|
|
|
|
activeLabelNewType.AddText("Combobox")
|
|
|
|
activeLabelNewType.AddText("Label")
|
|
|
|
activeLabelNewType.AddText("Textbox")
|
|
|
|
activeLabelNewType.AddText("Slider")
|
|
|
|
activeLabelNewType.AddText("Spinner")
|
|
|
|
activeLabelNewType.AddText("Image")
|
|
|
|
activeLabelNewType.AddText("Area")
|
|
|
|
activeLabelNewType.AddText("Form")
|
|
|
|
activeLabelNewType.AddText("Font")
|
|
|
|
activeLabelNewType.AddText("Color")
|
|
|
|
activeLabelNewType.AddText("Dialog")
|
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
n.NewButton("Add", func() {
|
|
|
|
name := activeLabelNewName.String()
|
|
|
|
newX := widget.GetInt(activeLabelNewX.String())
|
|
|
|
newY := widget.GetInt(activeLabelNewY.String())
|
|
|
|
newB := widget.GetBool(activeLabelNewB.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
|
2024-01-18 01:34:32 -06:00
|
|
|
if newY == -1 {
|
2024-01-03 12:33:25 -06:00
|
|
|
name = name + " (" + strconv.Itoa(activeWidget.NextW) + "," + strconv.Itoa(activeWidget.NextH) + ")"
|
|
|
|
} else {
|
2024-01-13 21:29:40 -06:00
|
|
|
// activeWidget.SetNext(newX, newY)
|
2024-01-03 12:33:25 -06:00
|
|
|
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
|
|
|
|
}
|
2024-01-08 22:33:18 -06:00
|
|
|
log.Log(INFO, "New Name =", name)
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Log(INFO, "New Type =", activeLabelNewType.String())
|
2024-01-08 22:33:18 -06:00
|
|
|
log.Log(INFO, "New X =", newX)
|
|
|
|
log.Log(INFO, "New Y =", newY)
|
|
|
|
log.Log(INFO, "activeWidget.NextW =", activeWidget.NextW)
|
|
|
|
log.Log(INFO, "activeWidget.NextH =", activeWidget.NextH)
|
|
|
|
log.Log(INFO, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (W,H) =", activeWidget.NextW, activeWidget.NextH)
|
2024-01-03 12:33:25 -06:00
|
|
|
activeWidget.Dump()
|
|
|
|
|
|
|
|
// activeWidget.X = newX
|
|
|
|
// activeWidget.Y = newY
|
|
|
|
|
2024-01-17 22:43:57 -06:00
|
|
|
switch activeLabelNewType.String() {
|
2024-01-03 12:33:25 -06:00
|
|
|
case "Grid":
|
|
|
|
activeWidget.NewGrid(name, newX, newY)
|
|
|
|
case "Group":
|
|
|
|
activeWidget.NewGroup(name)
|
|
|
|
case "Box":
|
|
|
|
activeWidget.NewBox(name, newB)
|
|
|
|
case "Button":
|
2024-01-18 01:34:32 -06:00
|
|
|
activeWidget.NewButton(name, func() {
|
2024-01-08 22:33:18 -06:00
|
|
|
log.Log(WARN, "got to button", name)
|
2024-01-03 12:33:25 -06:00
|
|
|
})
|
|
|
|
case "Checkbox":
|
2024-01-17 22:43:57 -06:00
|
|
|
a := activeWidget.NewCheckbox("DBG")
|
2024-01-18 01:34:32 -06:00
|
|
|
a.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Log(WARN, "custom checkox func a=", a.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
case "Dropdown":
|
2024-01-17 22:43:57 -06:00
|
|
|
a := activeWidget.NewDropdown()
|
2024-01-03 12:33:25 -06:00
|
|
|
a.AddText(name + " yay")
|
|
|
|
a.AddText(name + " haha")
|
2024-01-18 01:34:32 -06:00
|
|
|
a.Custom = func() {
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Log(WARN, "WTF a=", a.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
case "Combobox":
|
2024-01-17 22:43:57 -06:00
|
|
|
a := activeWidget.NewCombobox()
|
2024-01-03 12:33:25 -06:00
|
|
|
a.AddText(name + " foo")
|
|
|
|
a.AddText(name + " bar")
|
|
|
|
case "Label":
|
|
|
|
activeWidget.NewLabel(name)
|
|
|
|
case "Textbox":
|
|
|
|
activeWidget.NewTextbox(name)
|
|
|
|
case "Slider":
|
|
|
|
activeWidget.NewSlider(name, newX, newY)
|
|
|
|
case "Spinner":
|
|
|
|
activeWidget.NewSpinner(name, newX, newY)
|
|
|
|
default:
|
2024-01-17 22:43:57 -06:00
|
|
|
log.Error(errors.New("make what type?"), activeLabelNewType.String())
|
2024-01-03 12:33:25 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|