2022-11-13 08:53:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-03-12 08:47:16 -05:00
|
|
|
// if you include more than just this import
|
|
|
|
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
|
2022-11-13 08:53:03 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Quit() {
|
2023-04-03 10:26:47 -05:00
|
|
|
me.baseGui.Close()
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-04-05 13:06:42 -05:00
|
|
|
// set the widget start width & height
|
|
|
|
// re-run this when things change to recalibrate the position of the gocui view rect
|
|
|
|
func (w *cuiWidget) setStartWH() {
|
|
|
|
log(logInfo, "setStartWH() w.id =", w.id, "w.name", w.name)
|
|
|
|
switch w.widgetType {
|
|
|
|
case toolkit.Root:
|
|
|
|
log(logInfo, "setStartWH() rootNode w.id =", w.id, "w.name", w.name)
|
|
|
|
w.isFake = true
|
|
|
|
w.setFake()
|
2023-04-05 17:29:52 -05:00
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
|
|
|
case toolkit.Flag:
|
|
|
|
w.isFake = true
|
|
|
|
w.setFake()
|
2023-04-05 17:29:52 -05:00
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
|
|
|
case toolkit.Window:
|
2023-04-05 17:29:52 -05:00
|
|
|
w.setTabWH()
|
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
|
|
|
case toolkit.Tab:
|
2023-04-05 17:29:52 -05:00
|
|
|
w.setTabWH()
|
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
2023-04-05 19:03:01 -05:00
|
|
|
case toolkit.Box:
|
|
|
|
w.isFake = true
|
|
|
|
w.setFake()
|
2023-04-05 21:15:05 -05:00
|
|
|
w.startW = w.parent.startW
|
|
|
|
w.startH = w.parent.startH
|
2023-04-05 19:03:01 -05:00
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 19:33:31 -05:00
|
|
|
return
|
2023-04-05 19:03:01 -05:00
|
|
|
case toolkit.Grid:
|
|
|
|
w.isFake = true
|
|
|
|
w.setFake()
|
2023-04-05 21:15:05 -05:00
|
|
|
w.startW = w.parent.startW
|
|
|
|
w.startH = w.parent.startH
|
2023-04-05 19:33:31 -05:00
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
|
|
|
case toolkit.Group:
|
2023-04-05 21:15:05 -05:00
|
|
|
w.startW = w.parent.startW + 4
|
|
|
|
w.startH = w.parent.startH + 3
|
|
|
|
|
|
|
|
t := len(w.text)
|
|
|
|
w.gocuiSize.width = t + me.buttonPadding
|
|
|
|
w.gocuiSize.height = me.defaultHeight
|
|
|
|
w.gocuiSize.startW = w.startW
|
|
|
|
w.gocuiSize.startH = w.startH
|
|
|
|
|
2023-04-05 19:33:31 -05:00
|
|
|
w.setWH()
|
|
|
|
w.showWidgetPlacement(logNow, "StartWH:")
|
2023-04-05 21:15:05 -05:00
|
|
|
w.drawView()
|
2023-04-05 13:06:42 -05:00
|
|
|
return
|
2023-04-05 19:33:31 -05:00
|
|
|
default:
|
2023-04-05 21:15:05 -05:00
|
|
|
w.startW = w.parent.startW
|
|
|
|
w.startH = w.parent.startH
|
2023-04-05 19:33:31 -05:00
|
|
|
w.setWH()
|
2023-04-05 13:06:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-05 21:15:05 -05:00
|
|
|
/*
|
|
|
|
func (w *cuiWidget) setStartFromParent() {
|
|
|
|
p := w.parent
|
|
|
|
switch p.widgetType {
|
|
|
|
case toolkit.Box:
|
|
|
|
w.getBoxWH()
|
|
|
|
case toolkit.Group:
|
|
|
|
w.getGroupWH()
|
|
|
|
case toolkit.Grid:
|
|
|
|
w.getGridWH()
|
|
|
|
default:
|
|
|
|
w.gocuiSize.startW = p.startW
|
|
|
|
w.gocuiSize.startH = p.startH
|
|
|
|
}
|
|
|
|
w.gocuiSize.startW = w.startW
|
|
|
|
w.gocuiSize.startH = w.startH
|
|
|
|
|
|
|
|
w.startW = w.gocuiSize.startW
|
|
|
|
w.startH = w.gocuiSize.startH
|
|
|
|
w.showWidgetPlacement(logNow, "sSFP:")
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func Action(a *toolkit.Action) {
|
|
|
|
log(logInfo, "Action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
|
|
|
w := findWidget(a.WidgetId, me.rootNode)
|
|
|
|
switch a.ActionType {
|
|
|
|
case toolkit.Add:
|
|
|
|
w = setupWidget(a)
|
2023-04-05 13:06:42 -05:00
|
|
|
w.setStartWH()
|
2023-04-03 10:26:47 -05:00
|
|
|
case toolkit.Show:
|
|
|
|
if (a.B) {
|
|
|
|
w.drawView()
|
|
|
|
} else {
|
|
|
|
w.hideWidgets()
|
|
|
|
}
|
|
|
|
case toolkit.Set:
|
|
|
|
w.Set(a.A)
|
|
|
|
case toolkit.SetText:
|
|
|
|
w.SetText(a.S)
|
|
|
|
case toolkit.AddText:
|
|
|
|
w.AddText(a.S)
|
|
|
|
case toolkit.Move:
|
|
|
|
log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
|
|
|
|
default:
|
|
|
|
log(logError, "Action() Unknown =", a.ActionType, a.WidgetType, a.Name)
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
log(logInfo, "Action() END")
|
2022-11-13 08:53:03 -06:00
|
|
|
}
|
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func (w *cuiWidget) AddText(text string) {
|
|
|
|
if (w == nil) {
|
|
|
|
log(logNow, "widget is nil")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
w.vals = append(w.vals, text)
|
|
|
|
for i, s := range w.vals {
|
|
|
|
log(logNow, "AddText()", w.name, i, s)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
w.SetText(text)
|
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func (w *cuiWidget) SetText(text string) {
|
|
|
|
if (w == nil) {
|
|
|
|
log(logNow, "widget is nil")
|
2023-03-12 08:47:16 -05:00
|
|
|
return
|
|
|
|
}
|
2023-04-03 10:26:47 -05:00
|
|
|
w.text = text
|
|
|
|
w.s = text
|
|
|
|
w.textResize()
|
2023-04-03 11:52:54 -05:00
|
|
|
w.deleteView()
|
2023-04-03 10:26:47 -05:00
|
|
|
w.drawView()
|
|
|
|
}
|
2023-03-12 08:47:16 -05:00
|
|
|
|
2023-04-03 10:26:47 -05:00
|
|
|
func (w *cuiWidget) Set(val any) {
|
|
|
|
log(logInfo, "Set() value =", val)
|
|
|
|
var a toolkit.Action
|
|
|
|
a.ActionType = toolkit.Set
|
|
|
|
|
|
|
|
switch v := val.(type) {
|
|
|
|
case bool:
|
|
|
|
w.b = val.(bool)
|
|
|
|
case string:
|
|
|
|
w.SetText(val.(string))
|
|
|
|
case int:
|
|
|
|
w.i = val.(int)
|
2023-03-12 08:47:16 -05:00
|
|
|
default:
|
2023-04-03 10:26:47 -05:00
|
|
|
log(logError, "Set() unknown type =", v, "a =", a)
|
2023-03-12 08:47:16 -05:00
|
|
|
}
|
|
|
|
}
|