diff options
Diffstat (limited to 'toolkit/gocui')
| l---------[-rw-r--r--] | toolkit/gocui/common.go | 212 | ||||
| -rw-r--r-- | toolkit/gocui/mouse.go | 15 | ||||
| -rw-r--r-- | toolkit/gocui/plugin.go | 19 | ||||
| -rw-r--r-- | toolkit/gocui/structs.go | 47 | ||||
| -rw-r--r-- | toolkit/gocui/tab.go | 4 | ||||
| -rw-r--r-- | toolkit/gocui/widget.go | 147 |
6 files changed, 166 insertions, 278 deletions
diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go index d3de34c..35417a1 100644..120000 --- a/toolkit/gocui/common.go +++ b/toolkit/gocui/common.go @@ -1,211 +1 @@ -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 -} +../nocui/common.go
\ No newline at end of file diff --git a/toolkit/gocui/mouse.go b/toolkit/gocui/mouse.go index 64786ab..50c2834 100644 --- a/toolkit/gocui/mouse.go +++ b/toolkit/gocui/mouse.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 diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go index 6d597b4..eae811d 100644 --- a/toolkit/gocui/plugin.go +++ b/toolkit/gocui/plugin.go @@ -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) -} diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index 05df963..c61e7ad 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -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() diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go index d910552..3451e5c 100644 --- a/toolkit/gocui/tab.go +++ b/toolkit/gocui/tab.go @@ -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 } diff --git a/toolkit/gocui/widget.go b/toolkit/gocui/widget.go new file mode 100644 index 0000000..4afe08b --- /dev/null +++ b/toolkit/gocui/widget.go @@ -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 +} |
