summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nocui/action.go94
-rw-r--r--nocui/common.go20
-rw-r--r--nocui/event.go20
-rw-r--r--nocui/main.go8
-rw-r--r--nocui/stdin.go8
-rw-r--r--nocui/widget.go6
-rw-r--r--widget.go204
7 files changed, 78 insertions, 282 deletions
diff --git a/nocui/action.go b/nocui/action.go
index b746c25..19a42b4 100644
--- a/nocui/action.go
+++ b/nocui/action.go
@@ -1,7 +1,7 @@
package main
import (
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
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) pad(at toolkit.ActionType) {
+func (n *node) pad(at widget.ActionType) {
switch n.WidgetType {
- case toolkit.Group:
+ case widget.Group:
switch at {
- case toolkit.Margin:
+ case widget.Margin:
// SetMargined(true)
- case toolkit.Unmargin:
+ case widget.Unmargin:
// SetMargined(false)
- case toolkit.Pad:
+ case widget.Pad:
// SetMargined(true)
- case toolkit.Unpad:
+ case widget.Unpad:
// SetMargined(false)
}
- case toolkit.Tab:
- case toolkit.Window:
- case toolkit.Grid:
- case toolkit.Box:
- case toolkit.Textbox:
+ case widget.Tab:
+ case widget.Window:
+ case widget.Grid:
+ case widget.Box:
+ case widget.Textbox:
log(logError, "TODO: implement ActionType =", at)
default:
log(logError, "TODO: implement pad() for", at)
@@ -38,14 +38,14 @@ func (n *node) move(newParent *node) {
p := n.parent
switch p.WidgetType {
- case toolkit.Group:
- case toolkit.Tab:
+ case widget.Group:
+ case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
- case toolkit.Window:
+ case widget.Window:
// t.uiWindow.SetBorderless(false)
- case toolkit.Grid:
+ case widget.Grid:
// t.uiGrid.SetPadded(true)
- case toolkit.Box:
+ case widget.Box:
log(logInfo, "TODO: move() where =", p.ParentId)
log(logInfo, "TODO: move() for widget =", n.WidgetId)
default:
@@ -60,15 +60,15 @@ func (n *node) Delete() {
log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
switch p.WidgetType {
- case toolkit.Group:
+ case widget.Group:
// tParent.uiGroup.SetMargined(true)
- case toolkit.Tab:
+ case widget.Tab:
// tabSetMargined(tParent.uiTab, true)
- case toolkit.Window:
+ case widget.Window:
// t.uiWindow.SetBorderless(false)
- case toolkit.Grid:
+ case widget.Grid:
// t.uiGrid.SetPadded(true)
- case toolkit.Box:
+ case widget.Box:
log(logNow, "tWidget.boxC =", p.Name)
log(logNow, "is there a tParent parent? =", p.parent)
// 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.S =", a.S)
- if (a.ActionType == toolkit.InitToolkit) {
+ if (a.ActionType == widget.InitToolkit) {
// TODO: make sure to only do this once
// go uiMain.Do(func() {
// ui.Main(demoUI)
@@ -97,11 +97,11 @@ func doAction(a *toolkit.Action) {
log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
- case toolkit.Root:
+ case widget.Root:
me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode")
return
- case toolkit.Flag:
+ case widget.Flag:
// flag(&a)
return
}
@@ -109,40 +109,40 @@ func doAction(a *toolkit.Action) {
n := me.rootNode.findWidgetId(a.WidgetId)
switch a.ActionType {
- case toolkit.Add:
+ case widget.Add:
addNode(a)
- case toolkit.Show:
+ case widget.Show:
n.show(true)
- case toolkit.Hide:
+ case widget.Hide:
n.show(false)
- case toolkit.Enable:
+ case widget.Enable:
n.enable(true)
- case toolkit.Disable:
+ case widget.Disable:
n.enable(false)
- case toolkit.Get:
+ case widget.Get:
// n.setText(a.S)
- case toolkit.GetText:
+ case widget.GetText:
switch a.WidgetType {
- case toolkit.Textbox:
+ case widget.Textbox:
a.S = n.S
}
- case toolkit.Set:
+ case widget.Set:
// n.setText(a.S)
- case toolkit.SetText:
+ case widget.SetText:
// n.setText(a.S)
- case toolkit.AddText:
+ case widget.AddText:
// n.setText(a.S)
- case toolkit.Margin:
- n.pad(toolkit.Unmargin)
- case toolkit.Unmargin:
- n.pad(toolkit.Margin)
- case toolkit.Pad:
- n.pad(toolkit.Pad)
- case toolkit.Unpad:
- n.pad(toolkit.Unpad)
- case toolkit.Delete:
+ case widget.Margin:
+ n.pad(widget.Unmargin)
+ case widget.Unmargin:
+ n.pad(widget.Margin)
+ case widget.Pad:
+ n.pad(widget.Pad)
+ case widget.Unpad:
+ n.pad(widget.Unpad)
+ case widget.Delete:
n.Delete()
- case toolkit.Move:
+ case widget.Move:
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
diff --git a/nocui/common.go b/nocui/common.go
index 91b34dd..077055e 100644
--- a/nocui/common.go
+++ b/nocui/common.go
@@ -12,22 +12,22 @@ package main
*/
import (
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
// this is the channel we send user events like
// 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
-var pluginChan chan toolkit.Action
+var pluginChan chan widget.Action
type node struct {
parent *node
children []*node
WidgetId int // widget ID
- WidgetType toolkit.WidgetType
+ WidgetType widget.WidgetType
ParentId int // parent ID
Name string
@@ -90,21 +90,21 @@ func (n *node) doUserEvent() {
log(logError, "doUserEvent() callback == nil", n.WidgetId)
return
}
- var a toolkit.Action
+ var a widget.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
+ a.ActionType = widget.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 {
+func addNode(a *widget.Action) *node {
n := new(node)
n.WidgetType = a.WidgetType
n.WidgetId = a.WidgetId
@@ -129,7 +129,7 @@ func addNode(a *toolkit.Action) *node {
n.tk = initWidget(n)
// n.tk = new(guiWidget)
- if (a.WidgetType == toolkit.Root) {
+ if (a.WidgetType == widget.Root) {
log(logInfo, "addNode() Root")
return n
}
@@ -157,10 +157,10 @@ func addNode(a *toolkit.Action) *node {
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// 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
}
-func PluginChannel() chan toolkit.Action {
+func PluginChannel() chan widget.Action {
return pluginChan
}
diff --git a/nocui/event.go b/nocui/event.go
index 103e1b1..406e634 100644
--- a/nocui/event.go
+++ b/nocui/event.go
@@ -1,46 +1,46 @@
package main
import (
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
func (n *node) doWidgetClick() {
switch n.WidgetType {
- case toolkit.Root:
+ case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT
// rootNode.nextW = 0
// rootNode.nextH = 0
// rootNode.redoTabs(true)
- case toolkit.Flag:
+ case widget.Flag:
// me.rootNode.redoColor(true)
// rootNode.dumpTree(true)
- case toolkit.Window:
+ case widget.Window:
// setCurrentWindow(w)
n.doUserEvent()
- case toolkit.Tab:
+ case widget.Tab:
// setCurrentTab(w)
- case toolkit.Group:
+ case widget.Group:
// n.placeWidgets()
// n.toggleTree()
- case toolkit.Checkbox:
+ case widget.Checkbox:
if (n.B) {
// n.setCheckbox(false)
} else {
// n.setCheckbox(true)
}
n.doUserEvent()
- case toolkit.Grid:
+ case widget.Grid:
// rootNode.hideWidgets()
// n.placeGrid()
// n.showWidgets()
- case toolkit.Box:
+ case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()")
if (n.B) {
log(true, "BOX IS HORIZONTAL", n.Name)
} else {
log(true, "BOX IS VERTICAL", n.Name)
}
- case toolkit.Button:
+ case widget.Button:
n.doUserEvent()
default:
}
diff --git a/nocui/main.go b/nocui/main.go
index dfaf50c..2188928 100644
--- a/nocui/main.go
+++ b/nocui/main.go
@@ -2,7 +2,7 @@ package main
import (
"sync"
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
var muAction sync.Mutex
@@ -31,11 +31,11 @@ func catchActionChannel() {
// Linux, MacOS and Windows work (they all work differently. suprise. surprise.)
//
// 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
}
-func PluginChannel() chan toolkit.Action {
+func PluginChannel() chan widget.Action {
return pluginChan
}
*/
@@ -46,7 +46,7 @@ func init() {
log(logInfo, "Init()")
// andlabs = make(map[int]*andlabsT)
- pluginChan = make(chan toolkit.Action, 1)
+ pluginChan = make(chan widget.Action, 1)
log(logNow, "Init() start channel reciever")
go catchActionChannel()
diff --git a/nocui/stdin.go b/nocui/stdin.go
index 2c16e24..0cf2783 100644
--- a/nocui/stdin.go
+++ b/nocui/stdin.go
@@ -7,7 +7,7 @@ import (
"strings"
"strconv"
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
func simpleStdin() {
@@ -23,8 +23,8 @@ func simpleStdin() {
log(true, "show buttons")
me.rootNode.showButtons()
case "d":
- var a toolkit.Action
- a.ActionType = toolkit.EnableDebug
+ var a widget.Action
+ a.ActionType = widget.EnableDebug
callback <- a
case "":
fmt.Println("")
@@ -45,7 +45,7 @@ func simpleStdin() {
}
func (n *node) showButtons() {
- if n.WidgetType == toolkit.Button {
+ if n.WidgetType == widget.Button {
n.dumpWidget("Button:")
}
diff --git a/nocui/widget.go b/nocui/widget.go
index 71082a6..989634d 100644
--- a/nocui/widget.go
+++ b/nocui/widget.go
@@ -1,7 +1,7 @@
package main
import (
- "go.wit.com/gui/toolkits"
+ "go.wit.com/gui/widget"
)
// this is specific to the nocui toolkit
@@ -10,14 +10,14 @@ func initWidget(n *node) *guiWidget {
w = new(guiWidget)
// Set(w, "default")
- if n.WidgetType == toolkit.Root {
+ if n.WidgetType == widget.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.WidgetType == widget.Box) {
if (n.B) {
n.horizontal = true
} else {
diff --git a/widget.go b/widget.go
deleted file mode 100644
index 02dbe3f..0000000
--- a/widget.go
+++ /dev/null
@@ -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"
-}