277 lines
7.3 KiB
Go
277 lines
7.3 KiB
Go
package debugger
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/log"
|
|
"go.wit.com/widget"
|
|
)
|
|
|
|
/*
|
|
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
|
|
}
|
|
*/
|
|
|
|
func DebugWidgetWindow() *gadgets.BasicWindow {
|
|
p := gui.TreeRoot()
|
|
var w *gadgets.BasicWindow
|
|
w = gadgets.NewBasicWindow(p, "Widgets")
|
|
w.Draw()
|
|
|
|
g := w.Box().NewGroup("widget:").Pad()
|
|
|
|
g2 := g.NewGroup("widget:")
|
|
activeLabel = g2.NewLabel("undef")
|
|
g2 = g.NewGroup("type:")
|
|
activeLabelType = g2.NewLabel("undef")
|
|
g2 = g.NewGroup("New name:")
|
|
activeLabelNewName = g2.NewCombobox()
|
|
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
|
|
g = w.Box().NewGroup("common things")
|
|
g.NewButton("Enable()", func() {
|
|
activeWidget.Enable()
|
|
})
|
|
g.NewButton("Disable()", func() {
|
|
activeWidget.Disable()
|
|
})
|
|
g.NewButton("Show()", func() {
|
|
activeWidget.Show()
|
|
})
|
|
g.NewButton("Hide()", func() {
|
|
activeWidget.Hide()
|
|
})
|
|
g.NewButton("Dump()", func() {
|
|
activeWidget.Dump()
|
|
})
|
|
|
|
g = w.Box().NewGroup("add things")
|
|
debugAddWidgetButton(g)
|
|
g.NewLabel("experiments:")
|
|
debugAddWidgetButtons(g)
|
|
|
|
g = w.Box().NewGroup("change things")
|
|
g.NewButton("AddText()", func() {
|
|
activeWidget.AddText(activeLabelNewName.String())
|
|
/*
|
|
activeWidget.S = activeLabelNewName.S
|
|
a := newAction(activeWidget, toolkit.AddText)
|
|
sendAction(a)
|
|
*/
|
|
})
|
|
g.NewButton("SetText()", func() {
|
|
activeWidget.SetText(activeLabelNewName.String())
|
|
/*
|
|
activeWidget.S = activeLabelNewName.String()
|
|
a := newAction(activeWidget, toolkit.SetText)
|
|
sendAction(a)
|
|
*/
|
|
})
|
|
g.NewButton("Margin()", func() {
|
|
activeWidget.Margin()
|
|
/*
|
|
a := newAction(activeWidget, toolkit.Margin)
|
|
sendAction(a)
|
|
*/
|
|
})
|
|
g.NewButton("Unmargin()", func() {
|
|
activeWidget.Unmargin()
|
|
})
|
|
g.NewButton("Pad()", func() {
|
|
activeWidget.Pad()
|
|
})
|
|
g.NewButton("Unpad()", func() {
|
|
activeWidget.Unpad()
|
|
})
|
|
g.NewButton("Move(junk)", func() {
|
|
log.Warn("gui.Node Move() not implemented yet")
|
|
})
|
|
g.NewButton("Delete()", func() {
|
|
activeWidget.Delete(activeWidget)
|
|
})
|
|
|
|
g = w.Box().NewGroup("not working?")
|
|
activeJunk = w.Box().NewGroup("junk:")
|
|
activeJunk.NewLabel("test junk")
|
|
|
|
if activeWidget == nil {
|
|
setActiveWidget(me.treeRoot)
|
|
}
|
|
|
|
return w
|
|
}
|
|
|
|
func debugAddWidgetButtons(n *gui.Node) {
|
|
n.NewButton("Dropdown", func() {
|
|
a := activeWidget.NewDropdown()
|
|
a.AddText("this is better than tcl/tk")
|
|
a.AddText("make something for tim for qflow")
|
|
a.AddText("and for riscv")
|
|
a.Custom = func() {
|
|
log.Log(WARN, "custom dropdown() a =", a.GetProgName(), a.String())
|
|
}
|
|
})
|
|
n.NewButton("Combobox", func() {
|
|
a := activeWidget.NewCombobox()
|
|
a.AddText("mirrors.wit.com")
|
|
a.AddText("go.wit.com")
|
|
a.Custom = func() {
|
|
log.Log(WARN, "custom combobox() a =", a.GetProgName(), a.String())
|
|
}
|
|
})
|
|
n.NewButton("Grid", func() {
|
|
// 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")
|
|
/*
|
|
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)")
|
|
*/
|
|
// SetDebug(false)
|
|
DebugWidgetWindow()
|
|
})
|
|
n.NewButton("Image", func() {
|
|
activeWidget.NewImage("image")
|
|
})
|
|
n.NewButton("Box(horizontal)", func() {
|
|
a := activeWidget.NewBox("hBox", true)
|
|
a.NewLabel("hBox")
|
|
a.NewLabel("hBox 2")
|
|
})
|
|
n.NewButton("Box(vertical)", func() {
|
|
a := activeWidget.NewBox("vBox", false)
|
|
a.NewLabel("vBox")
|
|
a.NewLabel("vBox 2")
|
|
})
|
|
}
|
|
|
|
func debugAddWidgetButton(n *gui.Node) {
|
|
activeLabelNewType = n.NewDropdown()
|
|
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")
|
|
|
|
n.NewButton("Add", func() {
|
|
name := activeLabelNewName.String()
|
|
newX := widget.GetInt(activeLabelNewX.String())
|
|
newY := widget.GetInt(activeLabelNewY.String())
|
|
newB := widget.GetBool(activeLabelNewB.String())
|
|
|
|
if newY == -1 {
|
|
name = name + " (" + strconv.Itoa(activeWidget.NextW) + "," + strconv.Itoa(activeWidget.NextH) + ")"
|
|
} else {
|
|
// activeWidget.SetNext(newX, newY)
|
|
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
|
|
}
|
|
log.Log(INFO, "New Name =", name)
|
|
log.Log(INFO, "New Type =", activeLabelNewType.String())
|
|
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)
|
|
activeWidget.Dump()
|
|
|
|
// activeWidget.X = newX
|
|
// activeWidget.Y = newY
|
|
|
|
switch activeLabelNewType.String() {
|
|
case "Grid":
|
|
activeWidget.NewGrid(name, newX, newY)
|
|
case "Group":
|
|
activeWidget.NewGroup(name)
|
|
case "Box":
|
|
activeWidget.NewBox(name, newB)
|
|
case "Button":
|
|
activeWidget.NewButton(name, func() {
|
|
log.Log(WARN, "got to button", name)
|
|
})
|
|
case "Checkbox":
|
|
a := activeWidget.NewCheckbox("DBG")
|
|
a.Custom = func() {
|
|
log.Log(WARN, "custom checkox func a=", a.String())
|
|
}
|
|
case "Dropdown":
|
|
a := activeWidget.NewDropdown()
|
|
a.AddText(name + " yay")
|
|
a.AddText(name + " haha")
|
|
a.Custom = func() {
|
|
log.Log(WARN, "WTF a=", a.String())
|
|
}
|
|
case "Combobox":
|
|
a := activeWidget.NewCombobox()
|
|
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:
|
|
log.Error(errors.New("make what type?"), activeLabelNewType.String())
|
|
}
|
|
})
|
|
}
|