2023-03-01 11:35:36 -06:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2023-03-12 08:47:16 -05:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2023-03-01 11:35:36 -06:00
|
|
|
)
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// global var for checking to see if this
|
|
|
|
// window/tab for debugging a widget exists
|
|
|
|
// check the binary tree instead (?) for a window called "Widgets" (bad idea)
|
|
|
|
var bugWidget *Node
|
|
|
|
|
|
|
|
// the widget all these actions are run against
|
|
|
|
var activeWidget *Node
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
// for testing move, this is the node things are put on
|
|
|
|
var activeJunk *Node
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// the label where the user can see which widget is active
|
|
|
|
var activeLabel *Node
|
|
|
|
var activeLabelType *Node
|
2023-03-23 12:35:12 -05:00
|
|
|
var activeLabelNewName *Node
|
|
|
|
var activeLabelNewType *Node
|
|
|
|
var activeLabelNewX *Node
|
|
|
|
var activeLabelNewY *Node
|
|
|
|
var activeLabelNewB *Node
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// tmp junk
|
2023-03-03 14:41:38 -06:00
|
|
|
var debugGrid *Node
|
2023-03-12 08:47:16 -05:00
|
|
|
var debugGridLabel *Node
|
|
|
|
var debugWidgetBut1, debugWidgetBut2 *Node
|
|
|
|
|
|
|
|
func setActiveWidget(w *Node) {
|
|
|
|
if (w == nil) {
|
|
|
|
log(debugError, "setActiveWidget() was sent nil !!!")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
activeWidget = w
|
|
|
|
log(true, "The Widget is set to", w.id, w.Name)
|
2023-03-12 09:42:16 -05:00
|
|
|
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
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
title := "ID =" + strconv.Itoa(w.id) + " " + w.Name
|
2023-03-12 08:47:16 -05:00
|
|
|
activeLabel.SetText(title)
|
2023-04-23 07:37:24 -05:00
|
|
|
activeLabelType.SetText("widget.Type = " + w.WidgetType.String())
|
2023-03-12 08:47:16 -05:00
|
|
|
return
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
func DebugWidgetWindow(w *Node) {
|
|
|
|
if (bugWidget != nil) {
|
|
|
|
// this window was already created. Just change the widget we are working against
|
|
|
|
setActiveWidget(w)
|
|
|
|
return
|
|
|
|
}
|
2023-03-01 11:35:36 -06:00
|
|
|
|
|
|
|
// Either:
|
|
|
|
// make a new window
|
|
|
|
// make a new tab in the existing window
|
2023-03-12 08:47:16 -05:00
|
|
|
if (makeTabs) {
|
2023-04-28 10:35:57 -05:00
|
|
|
bugWidget = me.rootNode.NewWindow("Widgets")
|
2023-03-12 08:47:16 -05:00
|
|
|
bugWidget.Custom = bugWidget.StandardClose
|
2023-03-01 11:35:36 -06:00
|
|
|
} else {
|
2023-03-12 08:47:16 -05:00
|
|
|
bugWidget = bugWin.NewTab("Widgets")
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
g := bugWidget.NewGroup("widget:")
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
g2 := g.NewGroup("widget:")
|
|
|
|
activeLabel = g2.NewLabel("undef")
|
|
|
|
g2 = g.NewGroup("type:")
|
|
|
|
activeLabelType = g2.NewLabel("undef")
|
|
|
|
g2 = g.NewGroup("New name:")
|
|
|
|
activeLabelNewName = g2.NewCombobox("newthing")
|
|
|
|
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")
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
// common things that should work against each widget
|
|
|
|
g = bugWidget.NewGroup("common things")
|
|
|
|
g.NewButton("Enable()", func () {
|
2023-03-23 12:35:12 -05:00
|
|
|
activeWidget.Enable()
|
|
|
|
})
|
|
|
|
g.NewButton("Disable()", func () {
|
|
|
|
activeWidget.Disable()
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Show()", func () {
|
2023-03-23 12:35:12 -05:00
|
|
|
activeWidget.Show()
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Hide()", func () {
|
2023-03-23 12:35:12 -05:00
|
|
|
activeWidget.Hide()
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Dump()", func () {
|
2023-04-28 10:30:27 -05:00
|
|
|
activeWidget.Dump()
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
g = bugWidget.NewGroup("add things")
|
|
|
|
g.debugAddWidgetButton()
|
|
|
|
g.NewLabel("experiments:")
|
|
|
|
g.debugAddWidgetButtons()
|
2023-03-12 08:47:16 -05:00
|
|
|
|
|
|
|
g = bugWidget.NewGroup("change things")
|
2023-03-23 12:35:12 -05:00
|
|
|
g.NewButton("AddText()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
activeWidget.S = activeLabelNewName.S
|
|
|
|
a := newAction(activeWidget, toolkit.AddText)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("SetText()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
activeWidget.S = activeLabelNewName.S
|
|
|
|
a := newAction(activeWidget, toolkit.SetText)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Margin()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Margin)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Unmargin()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Unmargin)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Pad()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Pad)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Unpad()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Unpad)
|
|
|
|
sendAction(a)
|
2023-03-23 12:35:12 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Move(junk)", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Move)
|
|
|
|
sendAction(a)
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Delete()", func () {
|
2023-05-09 19:24:37 -05:00
|
|
|
a := newAction(activeWidget, toolkit.Delete)
|
|
|
|
sendAction(a)
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
2023-03-01 11:35:36 -06:00
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
g = bugWidget.NewGroup("not working?")
|
2023-03-23 12:35:12 -05:00
|
|
|
activeJunk = bugWidget.NewGroup("junk:")
|
|
|
|
activeJunk.NewLabel("test junk")
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-03-12 09:42:16 -05:00
|
|
|
if (activeWidget == nil) {
|
2023-04-28 10:35:57 -05:00
|
|
|
setActiveWidget(me.rootNode)
|
2023-03-12 09:42:16 -05:00
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) debugAddWidgetButtons() {
|
|
|
|
n.NewButton("Dropdown", func () {
|
|
|
|
a := activeWidget.NewDropdown("tmp dropdown")
|
2023-03-23 12:35:12 -05:00
|
|
|
a.AddText("this is better than tcl/tk")
|
2023-03-29 23:03:04 -05:00
|
|
|
a.AddText("make something for tim for qflow")
|
2023-03-23 12:35:12 -05:00
|
|
|
a.AddText("and for riscv")
|
2023-03-03 14:41:38 -06:00
|
|
|
a.Custom = func () {
|
2023-04-23 07:37:24 -05:00
|
|
|
log("custom dropdown() a =", a.Name, a.S, "id=", a.id)
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|
|
|
|
})
|
2023-03-12 08:47:16 -05:00
|
|
|
n.NewButton("Combobox", func () {
|
|
|
|
a := activeWidget.NewCombobox("tmp combobox")
|
2023-03-23 12:35:12 -05:00
|
|
|
a.AddText("mirrors.wit.com")
|
2023-03-29 23:03:04 -05:00
|
|
|
a.AddText("go.wit.com")
|
2023-03-03 14:41:38 -06:00
|
|
|
a.Custom = func () {
|
2023-04-23 07:37:24 -05:00
|
|
|
log("custom combobox() a =", a.Name, a.S, "id=", a.id)
|
2023-03-03 14:41:38 -06:00
|
|
|
}
|
|
|
|
})
|
2023-03-12 08:47:16 -05:00
|
|
|
n.NewButton("Grid", func () {
|
2023-03-03 14:41:38 -06:00
|
|
|
// Grid numbering by (X,Y)
|
|
|
|
// -----------------------------
|
|
|
|
// -- (1,1) -- (2,1) -- (3,1) --
|
|
|
|
// -- (1,2) -- (2,1) -- (3,1) --
|
|
|
|
// -----------------------------
|
|
|
|
|
2023-03-12 08:47:16 -05:00
|
|
|
// SetDebug(true)
|
|
|
|
debugGrid = activeWidget.NewGrid("tmp grid", 2, 3)
|
|
|
|
debugGridLabel = debugGrid.NewLabel("mirrors.wit.com")
|
2023-03-29 23:03:04 -05:00
|
|
|
/*
|
2023-03-23 12:35:12 -05: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)")
|
2023-03-29 23:03:04 -05:00
|
|
|
*/
|
2023-03-12 08:47:16 -05:00
|
|
|
// SetDebug(false)
|
|
|
|
DebugWidgetWindow(debugGrid)
|
2023-03-03 14:41:38 -06:00
|
|
|
})
|
2023-03-12 08:47:16 -05:00
|
|
|
n.NewButton("Image", func () {
|
|
|
|
activeWidget.NewImage("image")
|
2023-03-03 14:41:38 -06:00
|
|
|
})
|
2023-03-12 08:47:16 -05:00
|
|
|
n.NewButton("Box(horizontal)", func () {
|
|
|
|
a := activeWidget.NewBox("hBox", true)
|
2023-03-23 12:35:12 -05:00
|
|
|
a.NewLabel("hBox")
|
|
|
|
a.NewLabel("hBox 2")
|
2023-03-03 14:41:38 -06:00
|
|
|
})
|
2023-03-12 08:47:16 -05:00
|
|
|
n.NewButton("Box(vertical)", func () {
|
2023-03-23 12:35:12 -05:00
|
|
|
a := activeWidget.NewBox("vBox", false)
|
|
|
|
a.NewLabel("vBox")
|
|
|
|
a.NewLabel("vBox 2")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Node) debugAddWidgetButton() {
|
|
|
|
activeLabelNewType = n.NewDropdown("tmp dropdown")
|
|
|
|
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 () {
|
2023-04-23 07:37:24 -05:00
|
|
|
name := activeLabelNewName.S
|
|
|
|
newX := activeLabelNewX.I
|
|
|
|
newY := activeLabelNewY.I
|
|
|
|
newB := activeLabelNewB.B
|
2023-03-23 12:35:12 -05:00
|
|
|
|
|
|
|
if (newY == -1) {
|
2023-05-09 17:48:21 -05:00
|
|
|
name = name + " (" + strconv.Itoa(activeWidget.NextW) + "," + strconv.Itoa(activeWidget.NextH) + ")"
|
2023-03-23 12:35:12 -05:00
|
|
|
} else {
|
|
|
|
activeWidget.SetNext(newX, newY)
|
|
|
|
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
|
|
|
|
}
|
|
|
|
log("New Name =", name)
|
2023-04-23 07:37:24 -05:00
|
|
|
log("New Type =", activeLabelNewType.S)
|
2023-03-23 12:35:12 -05:00
|
|
|
log("New X =", newX)
|
|
|
|
log("New Y =", newY)
|
2023-05-09 17:48:21 -05:00
|
|
|
log("activeWidget.NextW =", activeWidget.NextW)
|
|
|
|
log("activeWidget.NextH =", activeWidget.NextH)
|
|
|
|
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (W,H) =", activeWidget.NextW, activeWidget.NextH)
|
2023-04-28 10:30:27 -05:00
|
|
|
activeWidget.Dump()
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2023-04-23 07:37:24 -05:00
|
|
|
// activeWidget.X = newX
|
|
|
|
// activeWidget.Y = newY
|
2023-03-23 12:35:12 -05:00
|
|
|
|
2023-04-23 07:37:24 -05:00
|
|
|
switch activeLabelNewType.S {
|
2023-03-23 12:35:12 -05:00
|
|
|
case "Grid":
|
|
|
|
activeWidget.NewGrid(name, newX, newY)
|
|
|
|
case "Group":
|
|
|
|
activeWidget.NewGroup(name)
|
|
|
|
case "Box":
|
|
|
|
activeWidget.NewBox(name, newB)
|
|
|
|
case "Button":
|
|
|
|
var n *Node
|
|
|
|
n = activeWidget.NewButton(name, func () {
|
|
|
|
log("got to button", name, n.id)
|
|
|
|
})
|
|
|
|
case "Checkbox":
|
|
|
|
a := activeWidget.NewCheckbox(name)
|
|
|
|
a.Custom = func () {
|
2023-04-23 07:37:24 -05:00
|
|
|
log("custom checkox func a=", a.B, "id=", a.id)
|
2023-03-23 12:35:12 -05:00
|
|
|
}
|
|
|
|
case "Dropdown":
|
|
|
|
a := activeWidget.NewDropdown(name)
|
|
|
|
a.AddText(name + " yay")
|
|
|
|
a.AddText(name + " haha")
|
|
|
|
a.Custom = func () {
|
2023-04-23 07:37:24 -05:00
|
|
|
log("WTF a=", a.B, "id=", a.id)
|
2023-03-23 12:35:12 -05:00
|
|
|
}
|
|
|
|
case "Combobox":
|
|
|
|
a := activeWidget.NewCombobox(name)
|
|
|
|
a.AddText(name + " foo")
|
|
|
|
a.AddText(name + " bar")
|
|
|
|
case "Label":
|
2023-04-08 11:06:50 -05:00
|
|
|
activeWidget.NewLabel(name)
|
2023-03-23 12:35:12 -05:00
|
|
|
case "Textbox":
|
|
|
|
activeWidget.NewTextbox(name)
|
|
|
|
case "Slider":
|
|
|
|
activeWidget.NewSlider(name, newX, newY)
|
|
|
|
case "Spinner":
|
|
|
|
activeWidget.NewSpinner(name, newX, newY)
|
|
|
|
default:
|
|
|
|
log(debugError, "make what type?")
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
2023-03-03 14:41:38 -06:00
|
|
|
})
|
2023-03-01 11:35:36 -06:00
|
|
|
}
|