nocui compiles against 'go.wit.com/gui/widget'

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-05 13:24:20 -06:00
parent 78654f6fdc
commit b9868cc873
7 changed files with 78 additions and 282 deletions

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
func (n *node) show(b bool) { func (n *node) show(b bool) {
@ -10,24 +10,24 @@ func (n *node) show(b bool) {
func (n *node) enable(b bool) { func (n *node) enable(b bool) {
} }
func (n *node) pad(at toolkit.ActionType) { func (n *node) pad(at widget.ActionType) {
switch n.WidgetType { switch n.WidgetType {
case toolkit.Group: case widget.Group:
switch at { switch at {
case toolkit.Margin: case widget.Margin:
// SetMargined(true) // SetMargined(true)
case toolkit.Unmargin: case widget.Unmargin:
// SetMargined(false) // SetMargined(false)
case toolkit.Pad: case widget.Pad:
// SetMargined(true) // SetMargined(true)
case toolkit.Unpad: case widget.Unpad:
// SetMargined(false) // SetMargined(false)
} }
case toolkit.Tab: case widget.Tab:
case toolkit.Window: case widget.Window:
case toolkit.Grid: case widget.Grid:
case toolkit.Box: case widget.Box:
case toolkit.Textbox: case widget.Textbox:
log(logError, "TODO: implement ActionType =", at) log(logError, "TODO: implement ActionType =", at)
default: default:
log(logError, "TODO: implement pad() for", at) log(logError, "TODO: implement pad() for", at)
@ -38,14 +38,14 @@ func (n *node) move(newParent *node) {
p := n.parent p := n.parent
switch p.WidgetType { switch p.WidgetType {
case toolkit.Group: case widget.Group:
case toolkit.Tab: case widget.Tab:
// tabSetMargined(tParent.uiTab, true) // tabSetMargined(tParent.uiTab, true)
case toolkit.Window: case widget.Window:
// t.uiWindow.SetBorderless(false) // t.uiWindow.SetBorderless(false)
case toolkit.Grid: case widget.Grid:
// t.uiGrid.SetPadded(true) // t.uiGrid.SetPadded(true)
case toolkit.Box: case widget.Box:
log(logInfo, "TODO: move() where =", p.ParentId) log(logInfo, "TODO: move() where =", p.ParentId)
log(logInfo, "TODO: move() for widget =", n.WidgetId) log(logInfo, "TODO: move() for widget =", n.WidgetId)
default: default:
@ -60,15 +60,15 @@ func (n *node) Delete() {
log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId) log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
switch p.WidgetType { switch p.WidgetType {
case toolkit.Group: case widget.Group:
// tParent.uiGroup.SetMargined(true) // tParent.uiGroup.SetMargined(true)
case toolkit.Tab: case widget.Tab:
// tabSetMargined(tParent.uiTab, true) // tabSetMargined(tParent.uiTab, true)
case toolkit.Window: case widget.Window:
// t.uiWindow.SetBorderless(false) // t.uiWindow.SetBorderless(false)
case toolkit.Grid: case widget.Grid:
// t.uiGrid.SetPadded(true) // t.uiGrid.SetPadded(true)
case toolkit.Box: case widget.Box:
log(logNow, "tWidget.boxC =", p.Name) log(logNow, "tWidget.boxC =", p.Name)
log(logNow, "is there a tParent parent? =", p.parent) log(logNow, "is there a tParent parent? =", p.parent)
// this didn't work: // this didn't work:
@ -81,11 +81,11 @@ func (n *node) Delete() {
} }
} }
func doAction(a *toolkit.Action) { func doAction(a *widget.Action) {
log(logNow, "doAction() START a.ActionType =", a.ActionType) log(logNow, "doAction() START a.ActionType =", a.ActionType)
log(logNow, "doAction() START a.S =", a.S) log(logNow, "doAction() START a.S =", a.S)
if (a.ActionType == toolkit.InitToolkit) { if (a.ActionType == widget.InitToolkit) {
// TODO: make sure to only do this once // TODO: make sure to only do this once
// go uiMain.Do(func() { // go uiMain.Do(func() {
// ui.Main(demoUI) // ui.Main(demoUI)
@ -97,11 +97,11 @@ func doAction(a *toolkit.Action) {
log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId) log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType { switch a.WidgetType {
case toolkit.Root: case widget.Root:
me.rootNode = addNode(a) me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode") log(logNow, "doAction() found rootNode")
return return
case toolkit.Flag: case widget.Flag:
// flag(&a) // flag(&a)
return return
} }
@ -109,40 +109,40 @@ func doAction(a *toolkit.Action) {
n := me.rootNode.findWidgetId(a.WidgetId) n := me.rootNode.findWidgetId(a.WidgetId)
switch a.ActionType { switch a.ActionType {
case toolkit.Add: case widget.Add:
addNode(a) addNode(a)
case toolkit.Show: case widget.Show:
n.show(true) n.show(true)
case toolkit.Hide: case widget.Hide:
n.show(false) n.show(false)
case toolkit.Enable: case widget.Enable:
n.enable(true) n.enable(true)
case toolkit.Disable: case widget.Disable:
n.enable(false) n.enable(false)
case toolkit.Get: case widget.Get:
// n.setText(a.S) // n.setText(a.S)
case toolkit.GetText: case widget.GetText:
switch a.WidgetType { switch a.WidgetType {
case toolkit.Textbox: case widget.Textbox:
a.S = n.S a.S = n.S
} }
case toolkit.Set: case widget.Set:
// n.setText(a.S) // n.setText(a.S)
case toolkit.SetText: case widget.SetText:
// n.setText(a.S) // n.setText(a.S)
case toolkit.AddText: case widget.AddText:
// n.setText(a.S) // n.setText(a.S)
case toolkit.Margin: case widget.Margin:
n.pad(toolkit.Unmargin) n.pad(widget.Unmargin)
case toolkit.Unmargin: case widget.Unmargin:
n.pad(toolkit.Margin) n.pad(widget.Margin)
case toolkit.Pad: case widget.Pad:
n.pad(toolkit.Pad) n.pad(widget.Pad)
case toolkit.Unpad: case widget.Unpad:
n.pad(toolkit.Unpad) n.pad(widget.Unpad)
case toolkit.Delete: case widget.Delete:
n.Delete() n.Delete()
case toolkit.Move: case widget.Move:
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType) log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := me.rootNode.findWidgetId(a.ParentId) newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent) n.move(newParent)

View File

@ -12,22 +12,22 @@ package main
*/ */
import ( import (
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
// this is the channel we send user events like // this is the channel we send user events like
// mouse clicks or keyboard events back to the program // mouse clicks or keyboard events back to the program
var callback chan toolkit.Action var callback chan widget.Action
// this is the channel we get requests to make widgets // this is the channel we get requests to make widgets
var pluginChan chan toolkit.Action var pluginChan chan widget.Action
type node struct { type node struct {
parent *node parent *node
children []*node children []*node
WidgetId int // widget ID WidgetId int // widget ID
WidgetType toolkit.WidgetType WidgetType widget.WidgetType
ParentId int // parent ID ParentId int // parent ID
Name string Name string
@ -90,21 +90,21 @@ func (n *node) doUserEvent() {
log(logError, "doUserEvent() callback == nil", n.WidgetId) log(logError, "doUserEvent() callback == nil", n.WidgetId)
return return
} }
var a toolkit.Action var a widget.Action
a.WidgetId = n.WidgetId a.WidgetId = n.WidgetId
a.Name = n.Name a.Name = n.Name
a.Text = n.Text a.Text = n.Text
a.S = n.S a.S = n.S
a.I = n.I a.I = n.I
a.B = n.B a.B = n.B
a.ActionType = toolkit.User a.ActionType = widget.User
log(logInfo, "doUserEvent() START: send a user event to the callback channel") log(logInfo, "doUserEvent() START: send a user event to the callback channel")
callback <- a callback <- a
log(logInfo, "doUserEvent() END: sent a user event to the callback channel") log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
return return
} }
func addNode(a *toolkit.Action) *node { func addNode(a *widget.Action) *node {
n := new(node) n := new(node)
n.WidgetType = a.WidgetType n.WidgetType = a.WidgetType
n.WidgetId = a.WidgetId n.WidgetId = a.WidgetId
@ -129,7 +129,7 @@ func addNode(a *toolkit.Action) *node {
n.tk = initWidget(n) n.tk = initWidget(n)
// n.tk = new(guiWidget) // n.tk = new(guiWidget)
if (a.WidgetType == toolkit.Root) { if (a.WidgetType == widget.Root) {
log(logInfo, "addNode() Root") log(logInfo, "addNode() Root")
return n return n
} }
@ -157,10 +157,10 @@ func addNode(a *toolkit.Action) *node {
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) // Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
// //
// this sets the channel to send user events back from the plugin // this sets the channel to send user events back from the plugin
func Callback(guiCallback chan toolkit.Action) { func Callback(guiCallback chan widget.Action) {
callback = guiCallback callback = guiCallback
} }
func PluginChannel() chan toolkit.Action { func PluginChannel() chan widget.Action {
return pluginChan return pluginChan
} }

View File

@ -1,46 +1,46 @@
package main package main
import ( import (
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
func (n *node) doWidgetClick() { func (n *node) doWidgetClick() {
switch n.WidgetType { switch n.WidgetType {
case toolkit.Root: case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT // THIS IS THE BEGINING OF THE LAYOUT
// rootNode.nextW = 0 // rootNode.nextW = 0
// rootNode.nextH = 0 // rootNode.nextH = 0
// rootNode.redoTabs(true) // rootNode.redoTabs(true)
case toolkit.Flag: case widget.Flag:
// me.rootNode.redoColor(true) // me.rootNode.redoColor(true)
// rootNode.dumpTree(true) // rootNode.dumpTree(true)
case toolkit.Window: case widget.Window:
// setCurrentWindow(w) // setCurrentWindow(w)
n.doUserEvent() n.doUserEvent()
case toolkit.Tab: case widget.Tab:
// setCurrentTab(w) // setCurrentTab(w)
case toolkit.Group: case widget.Group:
// n.placeWidgets() // n.placeWidgets()
// n.toggleTree() // n.toggleTree()
case toolkit.Checkbox: case widget.Checkbox:
if (n.B) { if (n.B) {
// n.setCheckbox(false) // n.setCheckbox(false)
} else { } else {
// n.setCheckbox(true) // n.setCheckbox(true)
} }
n.doUserEvent() n.doUserEvent()
case toolkit.Grid: case widget.Grid:
// rootNode.hideWidgets() // rootNode.hideWidgets()
// n.placeGrid() // n.placeGrid()
// n.showWidgets() // n.showWidgets()
case toolkit.Box: case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()") // n.showWidgetPlacement(logNow, "drawTree()")
if (n.B) { if (n.B) {
log(true, "BOX IS HORIZONTAL", n.Name) log(true, "BOX IS HORIZONTAL", n.Name)
} else { } else {
log(true, "BOX IS VERTICAL", n.Name) log(true, "BOX IS VERTICAL", n.Name)
} }
case toolkit.Button: case widget.Button:
n.doUserEvent() n.doUserEvent()
default: default:
} }

View File

@ -2,7 +2,7 @@ package main
import ( import (
"sync" "sync"
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
var muAction sync.Mutex var muAction sync.Mutex
@ -31,11 +31,11 @@ func catchActionChannel() {
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.) // Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
// //
// this sets the channel to send user events back from the plugin // this sets the channel to send user events back from the plugin
func Callback(guiCallback chan toolkit.Action) { func Callback(guiCallback chan widget.Action) {
callback = guiCallback callback = guiCallback
} }
func PluginChannel() chan toolkit.Action { func PluginChannel() chan widget.Action {
return pluginChan return pluginChan
} }
*/ */
@ -46,7 +46,7 @@ func init() {
log(logInfo, "Init()") log(logInfo, "Init()")
// andlabs = make(map[int]*andlabsT) // andlabs = make(map[int]*andlabsT)
pluginChan = make(chan toolkit.Action, 1) pluginChan = make(chan widget.Action, 1)
log(logNow, "Init() start channel reciever") log(logNow, "Init() start channel reciever")
go catchActionChannel() go catchActionChannel()

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"strconv" "strconv"
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
func simpleStdin() { func simpleStdin() {
@ -23,8 +23,8 @@ func simpleStdin() {
log(true, "show buttons") log(true, "show buttons")
me.rootNode.showButtons() me.rootNode.showButtons()
case "d": case "d":
var a toolkit.Action var a widget.Action
a.ActionType = toolkit.EnableDebug a.ActionType = widget.EnableDebug
callback <- a callback <- a
case "": case "":
fmt.Println("") fmt.Println("")
@ -45,7 +45,7 @@ func simpleStdin() {
} }
func (n *node) showButtons() { func (n *node) showButtons() {
if n.WidgetType == toolkit.Button { if n.WidgetType == widget.Button {
n.dumpWidget("Button:") n.dumpWidget("Button:")
} }

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"go.wit.com/gui/toolkits" "go.wit.com/gui/widget"
) )
// this is specific to the nocui toolkit // this is specific to the nocui toolkit
@ -10,14 +10,14 @@ func initWidget(n *node) *guiWidget {
w = new(guiWidget) w = new(guiWidget)
// Set(w, "default") // Set(w, "default")
if n.WidgetType == toolkit.Root { if n.WidgetType == widget.Root {
log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId) log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId)
n.WidgetId = 0 n.WidgetId = 0
me.rootNode = n me.rootNode = n
return w return w
} }
if (n.WidgetType == toolkit.Box) { if (n.WidgetType == widget.Box) {
if (n.B) { if (n.B) {
n.horizontal = true n.horizontal = true
} else { } else {

204
widget.go
View File

@ -1,204 +0,0 @@
package toolkit
// passes information between the toolkit library (plugin)
//
// This is the only thing that is passed between the toolkit plugin
//
// what names should be used? This is not part of [[Graphical Widget]]
// Event() seems like a good name.
// Event is used too much: web dev, cloud, etc
// I'm using "Action". Maybe it should really be
// "Interaction" as per wikipedia [[User interface]]
//
// TODO: convert this to a protobuf (?)
//
type WidgetType int // Button, Menu, Checkbox, etc.
type ActionType int // Add, SetText, Click, Hide, Append, Delete, etc
type Action struct {
ActionType ActionType
WidgetType WidgetType
WidgetId int
ParentId int
Text string // what is visable to the user
Name string // a name useful for programming
// This is how the values are passed back and forth
// values from things like checkboxes & dropdown's
B bool
I int
S string
// 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
// Put space around elements to improve look & feel
Margin bool
// Make widgets fill up the space available
Expand bool
A any // switch to this or deprecate this? pros/cons?
}
const (
Unknown WidgetType = iota
Root // the master 'root' node of the binary tree
Flag // used to send configuration values to plugins
Window // in certain gui's (ncurses), these are tabs
Tab // internally, this is a window
Frame // deprecate?
Grid // like drawers in a chest
Group // like the 'Appetizers' section on a menu
Box // a vertical or horizontal stack of widgets
Button
Checkbox // select 'on' or 'off'
Dropdown
Combobox // dropdown with edit=true
Label
Textbox // is this a Label with edit=true
Slider // like a progress bar
Spinner // like setting the oven temperature
Separator // TODO
Image // TODO
Area // TODO
Form // TODO
Font // TODO
Color // TODO
Dialog // TODO
Stdout // can be used to capture and display log output
)
const (
Add ActionType = iota
Delete
Get
Set
GetText
SetText
AddText
Show
Hide
Enable
Disable
Margin
Unmargin
Pad
Unpad
Append
Move
Dump
User // the user did something (mouse, keyboard, etc)
InitToolkit // initializes the toolkit
CloseToolkit // closes the toolkit
UserQuit // the user closed the GUI
EnableDebug // open the debugging window
)
func (s WidgetType) String() string {
switch s {
case Root:
return "Root"
case Flag:
return "Flag"
case Window:
return "Window"
case Tab:
return "Tab"
case Frame:
return "Frame"
case Grid:
return "Grid"
case Group:
return "Group"
case Box:
return "Box"
case Button:
return "Button"
case Checkbox:
return "Checkbox"
case Dropdown:
return "Dropdown"
case Combobox:
return "Combobox"
case Label:
return "Label"
case Textbox:
return "Textbox"
case Slider:
return "Slider"
case Spinner:
return "Spinner"
case Separator:
return "Separator"
case Image:
return "Image"
case Area:
return "Area"
case Form:
return "Form"
case Font:
return "Font"
case Color:
return "Color"
case Dialog:
return "Dialog"
case Stdout:
return "Stdout"
case Unknown:
return "Unknown"
}
return "WidgetType.String() Error"
}
func (s ActionType) String() string {
switch s {
case Add:
return "Add"
case Delete:
return "Delete"
case Get:
return "Get"
case Set:
return "Set"
case GetText:
return "GetText"
case SetText:
return "SetText"
case AddText:
return "AddText"
case Show:
return "Show"
case Hide:
return "Hide"
case Enable:
return "Enable"
case Disable:
return "Disable"
case Margin:
return "Margin"
case Unmargin:
return "Unmargin"
case Pad:
return "Pad"
case Unpad:
return "Unpad"
case Append:
return "Append"
case Move:
return "Move"
case Dump:
return "Dump"
}
return "ActionType.String() Error"
}