make a common.go for the toolkits
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
de771dbe98
commit
90c020369a
|
@ -19,3 +19,6 @@ log:
|
|||
|
||||
gocui: build
|
||||
./cloudflare -gui gocui >/tmp/witgui.log.stderr 2>&1
|
||||
|
||||
quiet:
|
||||
./cloudflare >/tmp/witgui.log.stderr 2>&1
|
||||
|
|
|
@ -195,7 +195,7 @@ func rawAction(a toolkit.Action) {
|
|||
return
|
||||
}
|
||||
|
||||
n := rootNode.findWidgetId(a.WidgetId)
|
||||
n := me.rootNode.findWidgetId(a.WidgetId)
|
||||
|
||||
if (a.ActionType == toolkit.Add) {
|
||||
ui.QueueMain(func() {
|
||||
|
@ -208,12 +208,12 @@ func rawAction(a toolkit.Action) {
|
|||
|
||||
if (a.ActionType == toolkit.Dump) {
|
||||
log(debugNow, "rawAction() Dump =", a.ActionType, a.WidgetType, n.Name)
|
||||
rootNode.listChildren(true)
|
||||
me.rootNode.listChildren(true)
|
||||
return
|
||||
}
|
||||
|
||||
if (n == nil) {
|
||||
rootNode.listChildren(true)
|
||||
me.rootNode.listChildren(true)
|
||||
log(true, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
|
||||
log(true, "rawAction() ERROR findWidgetId found nil for id =", a.WidgetId)
|
||||
log(true, "rawAction() ERROR findWidgetId found nil", a.ActionType, a.WidgetType)
|
||||
|
@ -256,7 +256,7 @@ func rawAction(a toolkit.Action) {
|
|||
n.Delete()
|
||||
case toolkit.Move:
|
||||
log(debugNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
|
||||
newParent := rootNode.findWidgetId(a.ParentId)
|
||||
newParent := me.rootNode.findWidgetId(a.ParentId)
|
||||
n.move(newParent)
|
||||
default:
|
||||
log(debugError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
|
||||
|
|
|
@ -17,10 +17,10 @@ func actionDump(b bool, a *toolkit.Action) {
|
|||
|
||||
func add(a toolkit.Action) {
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
rootNode = addWidget(&a, nil)
|
||||
me.rootNode = addWidget(&a)
|
||||
return
|
||||
}
|
||||
n := addWidget(&a, nil)
|
||||
n := addWidget(&a)
|
||||
|
||||
p := n.parent
|
||||
switch n.WidgetType {
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
func (p *node) newBox(n *node) {
|
||||
log(debugToolkit, "newBox()", n.Name)
|
||||
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
var box *ui.Box
|
||||
|
||||
log(debugToolkit, "rawBox() create", n.Name)
|
||||
|
|
|
@ -14,7 +14,7 @@ func (p *node) newButton(n *node) {
|
|||
return
|
||||
}
|
||||
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
|
||||
b := ui.NewButton(n.Text)
|
||||
newt.uiButton = b
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newCheckbox(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
log(debugToolkit, "newCheckbox()", n.Name, n.WidgetType)
|
||||
|
||||
newt.uiCheckbox = ui.NewCheckbox(n.Text)
|
||||
|
@ -22,6 +22,6 @@ func (p *node) newCheckbox(n *node) {
|
|||
p.place(n)
|
||||
}
|
||||
|
||||
func (t *andlabsT) checked() bool {
|
||||
func (t *guiWidget) checked() bool {
|
||||
return t.uiCheckbox.Checked()
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newCombobox(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
log(debugToolkit, "newCombobox() START", n.Name)
|
||||
|
||||
cb := ui.NewEditableCombobox()
|
||||
|
@ -26,7 +26,7 @@ func (p *node) newCombobox(n *node) {
|
|||
p.place(n)
|
||||
}
|
||||
|
||||
func (t *andlabsT) AddComboboxName(title string) {
|
||||
func (t *guiWidget) AddComboboxName(title string) {
|
||||
t.uiEditableCombobox.Append(title)
|
||||
if (t.val == nil) {
|
||||
log(debugToolkit, "make map didn't work")
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *node) findWidgetId(id int) *node {
|
||||
if (n == nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.WidgetId == id {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.findWidgetId(id)
|
||||
if (newN != nil) {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addWidget(a *toolkit.Action, tk *andlabsT) *node {
|
||||
n := new(node)
|
||||
n.WidgetType = a.WidgetType
|
||||
n.WidgetId = a.WidgetId
|
||||
n.ParentId = a.ParentId
|
||||
|
||||
// copy the data from the action message
|
||||
n.Name = a.Name
|
||||
n.Text = a.Text
|
||||
n.I = a.I
|
||||
n.S = a.S
|
||||
n.B = a.B
|
||||
n.X = a.X
|
||||
n.Y = a.Y
|
||||
|
||||
n.W = a.W
|
||||
n.H = a.H
|
||||
n.AtW = a.AtW
|
||||
n.AtH = a.AtH
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = tk
|
||||
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
log(logInfo, "addWidget() Root")
|
||||
return n
|
||||
}
|
||||
|
||||
if (rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||
log(logError, "addWidget() WidgetId already exists", a.WidgetId)
|
||||
return rootNode.findWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = rootNode.findWidgetId(a.ParentId)
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *node) doUserEvent() {
|
||||
if (callback == nil) {
|
||||
log(debugError, "doUserEvent() callback == nil", n.WidgetId)
|
||||
return
|
||||
}
|
||||
var a toolkit.Action
|
||||
a.WidgetId = n.WidgetId
|
||||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.S = n.S
|
||||
a.I = n.I
|
||||
a.B = n.B
|
||||
a.ActionType = toolkit.User
|
||||
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
|
||||
callback <- a
|
||||
log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
|
||||
return
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../nocui/common.go
|
|
@ -49,7 +49,7 @@ func ShowDebug () {
|
|||
log(true, "debugError =", debugError)
|
||||
}
|
||||
|
||||
func (t *andlabsT) Dump(b bool) {
|
||||
func (t *guiWidget) Dump(b bool) {
|
||||
if ! b {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func BlankWindow(w *ui.Window) *ui.Box {
|
|||
return hbox
|
||||
}
|
||||
|
||||
func (t *andlabsT) DemoNumbersPage() {
|
||||
func (t *guiWidget) DemoNumbersPage() {
|
||||
var w *ui.Window
|
||||
|
||||
log(debugToolkit, "Starting wit/gui toolkit andlabs/ui DemoNumbersPage()")
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newDropdown(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
log(debugToolkit, "gui.Toolbox.newDropdown() START", n.Name)
|
||||
|
||||
cb := ui.NewCombobox()
|
||||
|
@ -34,7 +34,7 @@ func (p *node) newDropdown(n *node) {
|
|||
p.place(n)
|
||||
}
|
||||
|
||||
func (t *andlabsT) addDropdownName(title string) {
|
||||
func (t *guiWidget) addDropdownName(title string) {
|
||||
t.uiCombobox.Append(title)
|
||||
if (t.val == nil) {
|
||||
log(debugToolkit, "make map didn't work")
|
||||
|
@ -50,7 +50,7 @@ func (t *andlabsT) addDropdownName(title string) {
|
|||
t.c = t.c + 1
|
||||
}
|
||||
|
||||
func (t *andlabsT) SetDropdown(i int) {
|
||||
func (t *guiWidget) SetDropdown(i int) {
|
||||
t.uiCombobox.SetSelected(i)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
// -- (1,2) -- (2,1) -- (3,1) --
|
||||
// -----------------------------
|
||||
func (p *node) newGrid(n *node) {
|
||||
var newt *andlabsT
|
||||
var newt *guiWidget
|
||||
log(debugToolkit, "newGrid()", n.WidgetId, "to", n.ParentId)
|
||||
|
||||
newt = new(andlabsT)
|
||||
newt = new(guiWidget)
|
||||
|
||||
c := ui.NewGrid()
|
||||
newt.uiGrid = c
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
func (p *node) newGroup(n *node) {
|
||||
log(debugToolkit, "NewGroup()", n.Name)
|
||||
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
|
||||
log(debugToolkit, "NewGroup() create", n.Name)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// make new Image using andlabs/ui
|
||||
func (p *node) newImage(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
var img *ui.Image
|
||||
|
||||
log(debugToolkit, "rawImage() create", n.Name)
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
func (p *node) newLabel(n *node) {
|
||||
log(logInfo, "NewLabel()", n.Name)
|
||||
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
c := ui.NewLabel(n.Name)
|
||||
newt.uiLabel = c
|
||||
newt.uiControl = c
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
var pluginChan chan toolkit.Action
|
||||
|
||||
// the starting point of the binary tree
|
||||
var rootNode *node
|
||||
// var rootNode *node
|
||||
|
||||
var uiMainUndef bool = true
|
||||
var uiMain sync.Once
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newSlider(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
|
||||
s := ui.NewSlider(n.X, n.Y)
|
||||
newt.uiSlider = s
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newSpinner(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
|
||||
s := ui.NewSpinbox(n.X, n.Y)
|
||||
newt.uiSpinbox = s
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
package main
|
||||
|
||||
import "git.wit.org/wit/gui/toolkit"
|
||||
// import "git.wit.org/wit/gui/toolkit"
|
||||
|
||||
import "github.com/andlabs/ui"
|
||||
import _ "github.com/andlabs/ui/winmanifest"
|
||||
|
||||
// var andlabs map[int]*andlabsT
|
||||
// var callback func(int) bool
|
||||
var callback chan toolkit.Action
|
||||
// var callback chan toolkit.Action
|
||||
|
||||
// It's probably a terrible idea to call this 'me'
|
||||
var me config
|
||||
|
||||
type config struct {
|
||||
rootNode *node // the base of the binary tree. it should have id == 0
|
||||
}
|
||||
|
||||
/*
|
||||
type node struct {
|
||||
parent *node
|
||||
children []*node
|
||||
|
@ -41,15 +49,16 @@ type node struct {
|
|||
// the internal plugin toolkit structure
|
||||
tk *andlabsT
|
||||
}
|
||||
*/
|
||||
|
||||
// stores the raw toolkit internals
|
||||
type andlabsT struct {
|
||||
type guiWidget struct {
|
||||
Width int
|
||||
Height int
|
||||
|
||||
// tw *toolkit.Widget
|
||||
parent *andlabsT
|
||||
children []*andlabsT
|
||||
parent *guiWidget
|
||||
children []*guiWidget
|
||||
|
||||
// used to track if a tab has a child widget yet
|
||||
child bool
|
||||
|
|
|
@ -20,8 +20,11 @@ import (
|
|||
any existing tabs rather than adding a new one
|
||||
*/
|
||||
func (p *node) newTab(n *node) {
|
||||
var newt *andlabsT
|
||||
var newt *guiWidget
|
||||
|
||||
if (p == nil) {
|
||||
log(debugError, "newTab() p == nil. how the fuck does this happen?", n.WidgetId, n.ParentId)
|
||||
}
|
||||
if (p.WidgetType != toolkit.Window) {
|
||||
log(debugError, "newTab() uiWindow == nil. I can't add a toolbar without window", n.WidgetId, n.ParentId)
|
||||
return
|
||||
|
@ -40,8 +43,8 @@ func (p *node) newTab(n *node) {
|
|||
log(debugToolkit, "newTab() GOOD. This should be an additional tab:", n.WidgetId, n.ParentId)
|
||||
if (n.WidgetType == toolkit.Tab) {
|
||||
// andlabs doesn't have multiple tab widgets so make a fake one?
|
||||
// this makes a andlabsT internal structure with the parent values
|
||||
newt = new(andlabsT)
|
||||
// this makes a guiWidget internal structure with the parent values
|
||||
newt = new(guiWidget)
|
||||
newt.uiWindow = t.uiWindow
|
||||
newt.uiTab = t.uiTab
|
||||
} else {
|
||||
|
@ -63,8 +66,8 @@ func tabSetMargined(tab *ui.Tab, b bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func rawTab(w *ui.Window, name string) *andlabsT {
|
||||
var newt andlabsT
|
||||
func rawTab(w *ui.Window, name string) *guiWidget {
|
||||
var newt guiWidget
|
||||
log(debugToolkit, "rawTab() START", name)
|
||||
|
||||
if (w == nil) {
|
||||
|
@ -83,8 +86,8 @@ func rawTab(w *ui.Window, name string) *andlabsT {
|
|||
return &newt
|
||||
}
|
||||
|
||||
func (t *andlabsT) appendTab(name string) *andlabsT {
|
||||
var newT andlabsT
|
||||
func (t *guiWidget) appendTab(name string) *guiWidget {
|
||||
var newT guiWidget
|
||||
log(debugToolkit, "appendTab() ADD", name)
|
||||
|
||||
if (t.uiTab == nil) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
func (p *node) newTextbox(n *node) {
|
||||
newt := new(andlabsT)
|
||||
newt := new(guiWidget)
|
||||
|
||||
if (n.X == 1) {
|
||||
e := ui.NewEntry()
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// this is specific to the nocui toolkit
|
||||
func initWidget(n *node) *guiWidget {
|
||||
var w *guiWidget
|
||||
w = new(guiWidget)
|
||||
// Set(w, "default")
|
||||
|
||||
if n.WidgetType == toolkit.Root {
|
||||
log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
||||
n.WidgetId = 0
|
||||
me.rootNode = n
|
||||
return w
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Box) {
|
||||
if (n.B) {
|
||||
n.horizontal = true
|
||||
} else {
|
||||
n.horizontal = false
|
||||
}
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
|
@ -5,18 +5,18 @@ import (
|
|||
_ "github.com/andlabs/ui/winmanifest"
|
||||
)
|
||||
|
||||
func (t *andlabsT) MessageWindow(msg1 string, msg2 string) {
|
||||
func (t *guiWidget) MessageWindow(msg1 string, msg2 string) {
|
||||
ui.MsgBox(t.uiWindow, msg1, msg2)
|
||||
}
|
||||
|
||||
func (t *andlabsT) ErrorWindow(msg1 string, msg2 string) {
|
||||
func (t *guiWidget) ErrorWindow(msg1 string, msg2 string) {
|
||||
ui.MsgBoxError(t.uiWindow, msg1, msg2)
|
||||
}
|
||||
|
||||
func newWindow(n *node) {
|
||||
var newt *andlabsT
|
||||
var newt *guiWidget
|
||||
|
||||
newt = new(andlabsT)
|
||||
newt = new(guiWidget)
|
||||
|
||||
// menubar bool is if the OS defined border on the window should be used
|
||||
win := ui.NewWindow(n.Name, n.X, n.Y, menubar)
|
||||
|
|
|
@ -1,211 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func makeWidget(n *node) *cuiWidget {
|
||||
var w *cuiWidget
|
||||
w = new(cuiWidget)
|
||||
// Set(w, "default")
|
||||
|
||||
w.frame = true
|
||||
|
||||
// set the name used by gocui to the id
|
||||
w.cuiName = strconv.Itoa(n.WidgetId)
|
||||
|
||||
if n.WidgetType == toolkit.Root {
|
||||
log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
||||
n.WidgetId = 0
|
||||
me.rootNode = n
|
||||
return w
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Box) {
|
||||
if (n.B) {
|
||||
n.horizontal = true
|
||||
} else {
|
||||
n.horizontal = false
|
||||
}
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Grid) {
|
||||
w.widths = make(map[int]int) // how tall each row in the grid is
|
||||
w.heights = make(map[int]int) // how wide each column in the grid is
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
func setupCtrlDownWidget() {
|
||||
a := new(toolkit.Action)
|
||||
a.Name = "ctrlDown"
|
||||
a.WidgetType = toolkit.Dialog
|
||||
a.WidgetId = -1
|
||||
a.ParentId = 0
|
||||
n := addNode(a)
|
||||
|
||||
me.ctrlDown = n
|
||||
}
|
||||
|
||||
func (n *node) deleteView() {
|
||||
w := n.tk
|
||||
if (w.v != nil) {
|
||||
w.v.Visible = false
|
||||
return
|
||||
}
|
||||
// make sure the view isn't really there
|
||||
me.baseGui.DeleteView(w.cuiName)
|
||||
w.v = nil
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *node) findWidgetId(id int) *node {
|
||||
if (n == nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.WidgetId == id {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.findWidgetId(id)
|
||||
if (newN != nil) {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *node) findWidgetName(name string) *node {
|
||||
if (n == nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.tk.cuiName == name {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.findWidgetName(name)
|
||||
if (newN != nil) {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *node) IsCurrent() bool {
|
||||
w := n.tk
|
||||
if (n.WidgetType == toolkit.Tab) {
|
||||
return w.isCurrent
|
||||
}
|
||||
if (n.WidgetType == toolkit.Window) {
|
||||
return w.isCurrent
|
||||
}
|
||||
if (n.WidgetType == toolkit.Root) {
|
||||
return false
|
||||
}
|
||||
return n.parent.IsCurrent()
|
||||
}
|
||||
|
||||
func (n *node) Visible() bool {
|
||||
if (n == nil) {
|
||||
return false
|
||||
}
|
||||
if (n.tk == nil) {
|
||||
return false
|
||||
}
|
||||
if (n.tk.v == nil) {
|
||||
return false
|
||||
}
|
||||
return n.tk.v.Visible
|
||||
}
|
||||
|
||||
func (n *node) SetVisible(b bool) {
|
||||
if (n == nil) {
|
||||
return
|
||||
}
|
||||
if (n.tk == nil) {
|
||||
return
|
||||
}
|
||||
if (n.tk.v == nil) {
|
||||
return
|
||||
}
|
||||
n.tk.v.Visible = b
|
||||
}
|
||||
|
||||
func addNode(a *toolkit.Action) *node {
|
||||
n := new(node)
|
||||
n.WidgetType = a.WidgetType
|
||||
n.WidgetId = a.WidgetId
|
||||
n.ParentId = a.ParentId
|
||||
|
||||
// copy the data from the action message
|
||||
n.Name = a.Name
|
||||
n.Text = a.Text
|
||||
n.I = a.I
|
||||
n.S = a.S
|
||||
n.B = a.B
|
||||
|
||||
n.X = a.X
|
||||
n.Y = a.Y
|
||||
|
||||
n.W = a.W
|
||||
n.H = a.H
|
||||
n.AtW = a.AtW
|
||||
n.AtH = a.AtH
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = makeWidget(n)
|
||||
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
log(logInfo, "addNode() Root")
|
||||
return n
|
||||
}
|
||||
|
||||
if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||
log(logError, "addNode() WidgetId already exists", a.WidgetId)
|
||||
return me.rootNode.findWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = me.rootNode.findWidgetId(a.ParentId)
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
//w := n.tk
|
||||
//w.parent = n.parent.tk
|
||||
//w.parent.children = append(w.parent.children, w)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func addDropdown() *node {
|
||||
n := new(node)
|
||||
n.WidgetType = toolkit.Flag
|
||||
n.WidgetId = -2
|
||||
n.ParentId = 0
|
||||
|
||||
// copy the data from the action message
|
||||
n.Name = "DropBox"
|
||||
n.Text = "DropBox text"
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = new(cuiWidget)
|
||||
n.tk.frame = true
|
||||
|
||||
// set the name used by gocui to the id
|
||||
n.tk.cuiName = "-1 dropbox"
|
||||
|
||||
n.tk.color = &colorFlag
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = me.rootNode
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
}
|
||||
return n
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../nocui/common.go
|
|
@ -63,9 +63,11 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
|||
w, h := g.MousePosition()
|
||||
log(true, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", w, h)
|
||||
if (me.ddClicked) {
|
||||
me.ddClicked = false
|
||||
log(true, "mouseUp() ddview is the thing that was clicked", w, h)
|
||||
log(true, "mouseUp() find out what the string is here", w, h, me.ddview.tk.gocuiSize.h1)
|
||||
|
||||
var newZone string = ""
|
||||
if (me.ddNode != nil) {
|
||||
value := h - me.ddview.tk.gocuiSize.h0 - 1
|
||||
log(true, "mouseUp() me.ddview.tk.gocuiSize.h1 =", me.ddview.tk.gocuiSize.h1)
|
||||
|
@ -74,10 +76,19 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
|||
log(true, "mouseUp() value =", value, "valsLen =", valsLen)
|
||||
log(true, "mouseUp() me.ddNode.vals =", me.ddNode.vals)
|
||||
if ((value >= 0) && (value < valsLen)) {
|
||||
str := me.ddNode.vals[value]
|
||||
log(true, "mouseUp() value =", value, "str =", str)
|
||||
newZone = me.ddNode.vals[value]
|
||||
log(true, "mouseUp() value =", value, "newZone =", newZone)
|
||||
}
|
||||
}
|
||||
hideDDview()
|
||||
if (newZone != "") {
|
||||
if (me.ddNode != nil) {
|
||||
me.ddNode.SetText(newZone)
|
||||
me.ddNode.S = newZone
|
||||
me.ddNode.doUserEvent()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
/*
|
||||
// if there is a drop down view active, treat it like a dialog box and close it
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
func action(a *toolkit.Action) {
|
||||
log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
||||
n := me.rootNode.findWidgetId(a.WidgetId)
|
||||
var w *cuiWidget
|
||||
var w *guiWidget
|
||||
if (n != nil) {
|
||||
w = n.tk
|
||||
}
|
||||
|
@ -98,20 +98,3 @@ func (n *node) Set(val any) {
|
|||
log(logError, "Set() unknown type =", val, v)
|
||||
}
|
||||
}
|
||||
|
||||
// this passes the user event back from the plugin
|
||||
func (n *node) doUserEvent() {
|
||||
if (me.callback == nil) {
|
||||
log(logError, "doUserEvent() no callback channel was configured")
|
||||
return
|
||||
}
|
||||
var a toolkit.Action
|
||||
a.WidgetId = n.WidgetId
|
||||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.B = n.B
|
||||
a.ActionType = toolkit.User
|
||||
log(logInfo, "doUserEvent() START: send a button click callback()", a.WidgetId, a.Name)
|
||||
me.callback <- a
|
||||
log(logInfo, "doUserEvent() END: sent a button click callback()", a.WidgetId, a.Name)
|
||||
}
|
||||
|
|
|
@ -96,49 +96,6 @@ var (
|
|||
globalMouseDown, msgMouseDown, movingMsg bool
|
||||
)
|
||||
|
||||
// this is the standard binary tree structure for toolkits
|
||||
type node struct {
|
||||
parent *node
|
||||
children []*node
|
||||
|
||||
WidgetId int // widget ID
|
||||
WidgetType toolkit.WidgetType
|
||||
ParentId int // parent ID
|
||||
|
||||
Name string
|
||||
Text string
|
||||
|
||||
// This is how the values are passed back and forth
|
||||
// values from things like checkboxes & dropdown's
|
||||
B bool
|
||||
I int
|
||||
S string
|
||||
|
||||
A any // switch to this or deprecate this? pros/cons?
|
||||
|
||||
// This is used for things like a slider(0,100)
|
||||
X int
|
||||
Y int
|
||||
|
||||
// This is for the grid size & widget position
|
||||
W int
|
||||
H int
|
||||
AtW int
|
||||
AtH int
|
||||
|
||||
vals []string // dropdown menu items
|
||||
|
||||
// horizontal=true means layout widgets like books on a bookshelf
|
||||
// horizontal=false means layout widgets like books in a stack
|
||||
horizontal bool `default:false`
|
||||
|
||||
hasTabs bool // does the window have tabs?
|
||||
currentTab bool // the visible tab
|
||||
|
||||
// the internal plugin toolkit structure
|
||||
tk *cuiWidget
|
||||
}
|
||||
|
||||
// this is the gocui way
|
||||
// corner starts at in the upper left corner
|
||||
type rectType struct {
|
||||
|
@ -153,7 +110,7 @@ func (r *rectType) Height() int {
|
|||
return r.h1 - r.h0
|
||||
}
|
||||
|
||||
type cuiWidget struct {
|
||||
type guiWidget struct {
|
||||
// the gocui package variables
|
||||
v *gocui.View // this is nil if the widget is not displayed
|
||||
cuiName string // what gocui uses to reference the widget
|
||||
|
@ -189,7 +146,7 @@ type cuiWidget struct {
|
|||
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
|
||||
// be called to clear the view's buffer.
|
||||
|
||||
func (w *cuiWidget) Write(p []byte) (n int, err error) {
|
||||
func (w *guiWidget) Write(p []byte) (n int, err error) {
|
||||
w.tainted = true
|
||||
me.writeMutex.Lock()
|
||||
defer me.writeMutex.Unlock()
|
||||
|
|
|
@ -7,14 +7,14 @@ import (
|
|||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func (w *cuiWidget) Width() int {
|
||||
func (w *guiWidget) Width() int {
|
||||
if w.frame {
|
||||
return w.gocuiSize.w1 - w.gocuiSize.w0
|
||||
}
|
||||
return w.gocuiSize.w1 - w.gocuiSize.w0 - 1
|
||||
}
|
||||
|
||||
func (w *cuiWidget) Height() int {
|
||||
func (w *guiWidget) Height() int {
|
||||
if w.frame {
|
||||
return w.gocuiSize.h1 - w.gocuiSize.h0
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func initWidget(n *node) *guiWidget {
|
||||
var w *guiWidget
|
||||
w = new(guiWidget)
|
||||
// Set(w, "default")
|
||||
|
||||
w.frame = true
|
||||
|
||||
// set the name used by gocui to the id
|
||||
w.cuiName = strconv.Itoa(n.WidgetId)
|
||||
|
||||
if n.WidgetType == toolkit.Root {
|
||||
log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
||||
n.WidgetId = 0
|
||||
me.rootNode = n
|
||||
return w
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Box) {
|
||||
if (n.B) {
|
||||
n.horizontal = true
|
||||
} else {
|
||||
n.horizontal = false
|
||||
}
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Grid) {
|
||||
w.widths = make(map[int]int) // how tall each row in the grid is
|
||||
w.heights = make(map[int]int) // how wide each column in the grid is
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
||||
|
||||
func setupCtrlDownWidget() {
|
||||
a := new(toolkit.Action)
|
||||
a.Name = "ctrlDown"
|
||||
a.WidgetType = toolkit.Dialog
|
||||
a.WidgetId = -1
|
||||
a.ParentId = 0
|
||||
n := addNode(a)
|
||||
|
||||
me.ctrlDown = n
|
||||
}
|
||||
|
||||
func (n *node) deleteView() {
|
||||
w := n.tk
|
||||
if (w.v != nil) {
|
||||
w.v.Visible = false
|
||||
return
|
||||
}
|
||||
// make sure the view isn't really there
|
||||
me.baseGui.DeleteView(w.cuiName)
|
||||
w.v = nil
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *node) findWidgetName(name string) *node {
|
||||
if (n == nil) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.tk.cuiName == name {
|
||||
return n
|
||||
}
|
||||
|
||||
for _, child := range n.children {
|
||||
newN := child.findWidgetName(name)
|
||||
if (newN != nil) {
|
||||
return newN
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *node) IsCurrent() bool {
|
||||
w := n.tk
|
||||
if (n.WidgetType == toolkit.Tab) {
|
||||
return w.isCurrent
|
||||
}
|
||||
if (n.WidgetType == toolkit.Window) {
|
||||
return w.isCurrent
|
||||
}
|
||||
if (n.WidgetType == toolkit.Root) {
|
||||
return false
|
||||
}
|
||||
return n.parent.IsCurrent()
|
||||
}
|
||||
|
||||
func (n *node) Visible() bool {
|
||||
if (n == nil) {
|
||||
return false
|
||||
}
|
||||
if (n.tk == nil) {
|
||||
return false
|
||||
}
|
||||
if (n.tk.v == nil) {
|
||||
return false
|
||||
}
|
||||
return n.tk.v.Visible
|
||||
}
|
||||
|
||||
func (n *node) SetVisible(b bool) {
|
||||
if (n == nil) {
|
||||
return
|
||||
}
|
||||
if (n.tk == nil) {
|
||||
return
|
||||
}
|
||||
if (n.tk.v == nil) {
|
||||
return
|
||||
}
|
||||
n.tk.v.Visible = b
|
||||
}
|
||||
|
||||
func addDropdown() *node {
|
||||
n := new(node)
|
||||
n.WidgetType = toolkit.Flag
|
||||
n.WidgetId = -2
|
||||
n.ParentId = 0
|
||||
|
||||
// copy the data from the action message
|
||||
n.Name = "DropBox"
|
||||
n.Text = "DropBox text"
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = new(guiWidget)
|
||||
n.tk.frame = true
|
||||
|
||||
// set the name used by gocui to the id
|
||||
n.tk.cuiName = "-1 dropbox"
|
||||
|
||||
n.tk.color = &colorFlag
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = me.rootNode
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
}
|
||||
return n
|
||||
}
|
|
@ -1,9 +1,68 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
These code should be common to all gui plugins
|
||||
|
||||
There are some helper functions that are probably going to be
|
||||
the same everywhere. Mostly due to handling the binary tree structure
|
||||
and the channel communication
|
||||
|
||||
For now, it's just a symlink to the 'master' version in
|
||||
./toolkit/nocui/common.go
|
||||
*/
|
||||
|
||||
import (
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// this is the channel that sends the events from the user clicking or typing
|
||||
// back to the program using this golang package
|
||||
var callback chan toolkit.Action
|
||||
|
||||
type node struct {
|
||||
parent *node
|
||||
children []*node
|
||||
|
||||
WidgetId int // widget ID
|
||||
WidgetType toolkit.WidgetType
|
||||
ParentId int // parent ID
|
||||
|
||||
Name string
|
||||
Text string
|
||||
|
||||
// This is how the values are passed back and forth
|
||||
// values from things like checkboxes & dropdown's
|
||||
B bool
|
||||
I int
|
||||
S string
|
||||
|
||||
A any // switch to this or deprecate this? pros/cons?
|
||||
|
||||
// This is used for things like a slider(0,100)
|
||||
X int
|
||||
Y int
|
||||
|
||||
// This is for the grid size & widget position
|
||||
W int
|
||||
H int
|
||||
AtW int
|
||||
AtH int
|
||||
|
||||
vals []string // dropdown menu items
|
||||
|
||||
// horizontal=true means layout widgets like books on a bookshelf
|
||||
// horizontal=false means layout widgets like books in a stack
|
||||
horizontal bool `default:false`
|
||||
|
||||
hasTabs bool // does the window have tabs?
|
||||
currentTab bool // the visible tab
|
||||
|
||||
// the internal plugin toolkit structure
|
||||
// in the gtk plugin, it has gtk things like margin & border settings
|
||||
// in the text console one, it has text console things like colors for menus & buttons
|
||||
tk *guiWidget
|
||||
}
|
||||
|
||||
// searches the binary tree for a WidgetId
|
||||
func (n *node) findWidgetId(id int) *node {
|
||||
if (n == nil) {
|
||||
|
@ -45,22 +104,87 @@ func addWidget(a *toolkit.Action) *node {
|
|||
n.AtH = a.AtH
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = new(nocuiT)
|
||||
n.tk = new(guiWidget)
|
||||
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
log(logInfo, "addWidget() Root")
|
||||
return n
|
||||
}
|
||||
|
||||
if (rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||
if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||
log(logError, "addWidget() WidgetId already exists", a.WidgetId)
|
||||
return rootNode.findWidgetId(a.WidgetId)
|
||||
return me.rootNode.findWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = rootNode.findWidgetId(a.ParentId)
|
||||
n.parent = me.rootNode.findWidgetId(a.ParentId)
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *node) doUserEvent() {
|
||||
if (callback == nil) {
|
||||
log(logError, "doUserEvent() callback == nil", n.WidgetId)
|
||||
return
|
||||
}
|
||||
var a toolkit.Action
|
||||
a.WidgetId = n.WidgetId
|
||||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.S = n.S
|
||||
a.I = n.I
|
||||
a.B = n.B
|
||||
a.ActionType = toolkit.User
|
||||
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
|
||||
callback <- a
|
||||
log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
|
||||
return
|
||||
}
|
||||
|
||||
func addNode(a *toolkit.Action) *node {
|
||||
n := new(node)
|
||||
n.WidgetType = a.WidgetType
|
||||
n.WidgetId = a.WidgetId
|
||||
n.ParentId = a.ParentId
|
||||
|
||||
// copy the data from the action message
|
||||
n.Name = a.Name
|
||||
n.Text = a.Text
|
||||
n.I = a.I
|
||||
n.S = a.S
|
||||
n.B = a.B
|
||||
|
||||
n.X = a.X
|
||||
n.Y = a.Y
|
||||
|
||||
n.W = a.W
|
||||
n.H = a.H
|
||||
n.AtW = a.AtW
|
||||
n.AtH = a.AtH
|
||||
|
||||
// store the internal toolkit information
|
||||
n.tk = initWidget(n)
|
||||
// n.tk = new(guiWidget)
|
||||
|
||||
if (a.WidgetType == toolkit.Root) {
|
||||
log(logInfo, "addNode() Root")
|
||||
return n
|
||||
}
|
||||
|
||||
if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
|
||||
log(logError, "addNode() WidgetId already exists", a.WidgetId)
|
||||
return me.rootNode.findWidgetId(a.WidgetId)
|
||||
}
|
||||
|
||||
// add this new widget on the binary tree
|
||||
n.parent = me.rootNode.findWidgetId(a.ParentId)
|
||||
if n.parent != nil {
|
||||
n.parent.children = append(n.parent.children, n)
|
||||
//w := n.tk
|
||||
//w.parent = n.parent.tk
|
||||
//w.parent.children = append(w.parent.children, w)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
|
|
@ -45,22 +45,3 @@ func (n *node) doWidgetClick() {
|
|||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (n *node) doUserEvent() {
|
||||
if (callback == nil) {
|
||||
log(logError, "doUserEvent() callback == nil", n.WidgetId)
|
||||
return
|
||||
}
|
||||
var a toolkit.Action
|
||||
a.WidgetId = n.WidgetId
|
||||
a.Name = n.Name
|
||||
a.Text = n.Text
|
||||
a.S = n.S
|
||||
a.I = n.I
|
||||
a.B = n.B
|
||||
a.ActionType = toolkit.User
|
||||
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
|
||||
callback <- a
|
||||
log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,47 +1,19 @@
|
|||
package main
|
||||
|
||||
import "git.wit.org/wit/gui/toolkit"
|
||||
|
||||
var callback chan toolkit.Action
|
||||
|
||||
type node struct {
|
||||
parent *node
|
||||
children []*node
|
||||
|
||||
WidgetId int // widget ID
|
||||
WidgetType toolkit.WidgetType
|
||||
ParentId int // parent ID
|
||||
|
||||
Name string
|
||||
Text string
|
||||
|
||||
// This is how the values are passed back and forth
|
||||
// values from things like checkboxes & dropdown's
|
||||
B bool
|
||||
I int
|
||||
S string
|
||||
|
||||
A any // switch to this or deprecate this? pros/cons?
|
||||
|
||||
// This is used for things like a slider(0,100)
|
||||
X int
|
||||
Y int
|
||||
|
||||
// This is for the grid size & widget position
|
||||
W int
|
||||
H int
|
||||
AtW int
|
||||
AtH int
|
||||
|
||||
// the internal plugin toolkit structure
|
||||
tk *nocuiT
|
||||
}
|
||||
// import "git.wit.org/wit/gui/toolkit"
|
||||
|
||||
// stores the raw toolkit internals
|
||||
type nocuiT struct {
|
||||
type guiWidget struct {
|
||||
Width int
|
||||
Height int
|
||||
|
||||
c int
|
||||
val map[int]string
|
||||
}
|
||||
|
||||
// It's probably a terrible idea to call this 'me'
|
||||
var me config
|
||||
|
||||
type config struct {
|
||||
rootNode *node // the base of the binary tree. it should have id == 0
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// this is specific to the nocui toolkit
|
||||
func initWidget(n *node) *guiWidget {
|
||||
var w *guiWidget
|
||||
w = new(guiWidget)
|
||||
// Set(w, "default")
|
||||
|
||||
if n.WidgetType == toolkit.Root {
|
||||
log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
|
||||
n.WidgetId = 0
|
||||
me.rootNode = n
|
||||
return w
|
||||
}
|
||||
|
||||
if (n.WidgetType == toolkit.Box) {
|
||||
if (n.B) {
|
||||
n.horizontal = true
|
||||
} else {
|
||||
n.horizontal = false
|
||||
}
|
||||
}
|
||||
|
||||
return w
|
||||
}
|
Loading…
Reference in New Issue