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)
|
|
|
|
activeLabelType.SetText("widget.Type = " + w.widget.Type.String())
|
|
|
|
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) {
|
|
|
|
Config.Title = "Widgets"
|
2023-03-01 11:35:36 -06:00
|
|
|
Config.Width = 300
|
|
|
|
Config.Height = 400
|
2023-03-12 08:47:16 -05:00
|
|
|
bugWidget = NewWindow()
|
|
|
|
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-03-23 12:35:12 -05:00
|
|
|
activeWidget.Dump(true)
|
|
|
|
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Dump
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, nil)
|
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 () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.AddText
|
2023-03-23 12:35:12 -05:00
|
|
|
a.S = activeLabelNewName.widget.S
|
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("SetText()", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.SetText
|
2023-03-23 12:35:12 -05:00
|
|
|
a.S = activeLabelNewName.widget.S
|
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("Margin()", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Margin
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("Unmargin()", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Unmargin
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("Pad()", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Pad
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("Unpad()", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Unpad
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, nil)
|
|
|
|
})
|
|
|
|
g.NewButton("Move(junk)", func () {
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Move
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, activeJunk)
|
2023-03-12 08:47:16 -05:00
|
|
|
})
|
|
|
|
g.NewButton("Delete()", func () {
|
2023-03-23 12:35:12 -05:00
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Delete
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, activeWidget, activeJunk)
|
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-03-29 23:03:04 -05:00
|
|
|
setActiveWidget(Config.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-03 10:26:47 -05:00
|
|
|
log("custom dropdown() a =", a.Name, a.widget.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-03 10:26:47 -05:00
|
|
|
log("custom combobox() a =", a.Name, a.widget.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 () {
|
|
|
|
name := activeLabelNewName.widget.S
|
|
|
|
newX := activeLabelNewX.widget.I
|
|
|
|
newY := activeLabelNewY.widget.I
|
|
|
|
newB := activeLabelNewB.widget.B
|
|
|
|
|
|
|
|
if (newY == -1) {
|
|
|
|
name = name + " (" + strconv.Itoa(activeWidget.NextX) + "," + strconv.Itoa(activeWidget.NextY) + ")"
|
|
|
|
} else {
|
|
|
|
activeWidget.SetNext(newX, newY)
|
|
|
|
name = name + " (" + strconv.Itoa(newX) + "," + strconv.Itoa(newY) + ")"
|
|
|
|
}
|
|
|
|
log("New Name =", name)
|
|
|
|
log("New Type =", activeLabelNewType.widget.S)
|
|
|
|
log("New X =", newX)
|
|
|
|
log("New Y =", newY)
|
|
|
|
log("activeWidget.NextX =", activeWidget.NextX)
|
|
|
|
log("activeWidget.NextY =", activeWidget.NextY)
|
|
|
|
log(debugNow, "Add() size (X,Y)", activeWidget.X, activeWidget.Y, "put next thing at (X,Y) =", activeWidget.NextX, activeWidget.NextY)
|
|
|
|
activeWidget.Dump(true)
|
|
|
|
|
|
|
|
// activeWidget.widget.X = newX
|
|
|
|
// activeWidget.widget.Y = newY
|
|
|
|
|
|
|
|
switch activeLabelNewType.widget.S {
|
|
|
|
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 () {
|
|
|
|
log("custom checkox func a=", a.widget.B, "id=", a.id)
|
|
|
|
}
|
|
|
|
case "Dropdown":
|
|
|
|
a := activeWidget.NewDropdown(name)
|
|
|
|
a.AddText(name + " yay")
|
|
|
|
a.AddText(name + " haha")
|
|
|
|
a.Custom = func () {
|
|
|
|
log("WTF a=", a.widget.B, "id=", a.id)
|
|
|
|
}
|
|
|
|
case "Combobox":
|
|
|
|
a := activeWidget.NewCombobox(name)
|
|
|
|
a.AddText(name + " foo")
|
|
|
|
a.AddText(name + " bar")
|
|
|
|
case "Label":
|
|
|
|
newNode := activeWidget.New(name, toolkit.Label, nil)
|
|
|
|
|
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Add
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, newNode, activeWidget)
|
|
|
|
// return newNode
|
|
|
|
// activeWidget.NewLabel(name)
|
|
|
|
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
|
|
|
}
|