From d5be773817445f19b98267d69849571fc9d84390 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 28 Jan 2024 11:07:51 -0600 Subject: [PATCH] builds and runs Signed-off-by: Jeff Carr --- click.go | 146 +++++++++++++++++++++++------------------------------ color.go | 18 ++----- place.go | 72 ++++++++++++-------------- structs.go | 2 +- widget.go | 35 ------------- 5 files changed, 99 insertions(+), 174 deletions(-) diff --git a/click.go b/click.go index 7121b0b..f815aa6 100644 --- a/click.go +++ b/click.go @@ -10,7 +10,7 @@ import ( ) // set isCurrent = false everywhere -func unsetCurrent(w *guiWidget) { +func (w *guiWidget) unsetCurrent() { w.isCurrent = false if w.node.WidgetType == widget.Tab { @@ -19,56 +19,51 @@ func unsetCurrent(w *guiWidget) { } for _, child := range w.children { - unsetCurrent(child) + child.unsetCurrent() } } // when adding a new widget, this will update the display // of the current widgets if that widget is supposed // to be in current display -func updateCurrent(n *tree.Node) { - var w *guiWidget - w = n.TK.(*guiWidget) - +func (w *guiWidget) updateCurrent() { log.Log(NOW, "updateCurrent()", w.String()) - if n.WidgetType == widget.Tab { + if w.WidgetType == widget.Tab { if w.IsCurrent() { // n.tk.color = &colorActiveT - setColor(n, &colorActiveT) + w.setColor(&colorActiveT) w.hideView() w.showView() - setCurrentTab(n) + w.setCurrentTab() } else { // n.tk.color = &colorTab // n.setColor() } return } - if n.WidgetType == widget.Window { + if w.WidgetType == widget.Window { if w.IsCurrent() { // setCurrentWindow(n) } return } - if n.WidgetType == widget.Root { + if w.WidgetType == widget.Root { return } - updateCurrent(n.Parent) + w.parent.updateCurrent() } // shows the widgets in a window -func setCurrentWindow(n *tree.Node) { - var w *guiWidget - w = n.TK.(*guiWidget) +func (w *guiWidget) setCurrentWindow() { if w.IsCurrent() { return } - if n.WidgetType != widget.Window { + if w.WidgetType != widget.Window { return } var rootTK *guiWidget rootTK = me.treeRoot.TK.(*guiWidget) - unsetCurrent(rootTK) + rootTK.unsetCurrent() if w.hasTabs { // set isCurrent = true on the first tab @@ -82,53 +77,49 @@ func setCurrentWindow(n *tree.Node) { } // shows the widgets in a tab -func setCurrentTab(n *tree.Node) { - var w, p, rootTK *guiWidget - w = n.TK.(*guiWidget) - if n.WidgetType != widget.Tab { +func (w *guiWidget) setCurrentTab() { + var p, rootTK *guiWidget + if w.WidgetType != widget.Tab { return } rootTK = me.treeRoot.TK.(*guiWidget) - unsetCurrent(rootTK) + rootTK.unsetCurrent() w.isCurrent = true - p = n.Parent.TK.(*guiWidget) + p = w.parent p.isCurrent = true - log.Log(NOW, "setCurrent()", n.String()) + log.Log(NOW, "setCurrent()", w.String()) } -func doWidgetClick(n *tree.Node) { - switch n.WidgetType { +func (w *guiWidget) doWidgetClick() { + switch w.WidgetType { case widget.Root: // THIS IS THE BEGINING OF THE LAYOUT - log.Log(NOW, "doWidgetClick()", n.String()) + log.Log(NOW, "doWidgetClick()", w.String()) redoWindows(0, 0) case widget.Flag: - log.Log(NOW, "doWidgetClick() FLAG widget name =", n.String()) + log.Log(NOW, "doWidgetClick() FLAG widget name =", w.String()) log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") case widget.Window: - if me.currentWindow == n { + if me.currentWindow == w.node { return } if me.currentWindow != nil { - var w *guiWidget - w = me.currentWindow.TK.(*guiWidget) - unsetCurrent(w) - setColor(me.currentWindow, &colorWindow) - w.hideWidgets() + var curw *guiWidget + curw = me.currentWindow.TK.(*guiWidget) + curw.unsetCurrent() + curw.setColor(&colorWindow) + curw.hideWidgets() } - me.currentWindow = n - // setCurrentWindow(n) // probably delete this - setColor(n, &colorActiveW) + me.currentWindow = w.node - var w *guiWidget - w = n.TK.(*guiWidget) + w.setColor(&colorActiveW) w.hideWidgets() w.redoTabs(me.TabW, me.TabH) for _, child := range w.children { if child.currentTab == true { log.Log(NOW, "FOUND CURRENT TAB", child.String()) - setCurrentTab(child.node) - placeWidgets(child.node, me.RawW, me.RawH) + child.setCurrentTab() + child.placeWidgets(me.RawW, me.RawH) child.showWidgets() return } @@ -138,37 +129,31 @@ func doWidgetClick(n *tree.Node) { } */ case widget.Tab: - var w *guiWidget - w = n.TK.(*guiWidget) if w.IsCurrent() { return // do nothing if you reclick on the already selected tab } // find the window and disable the active tab - p := n.Parent + p := w.parent if p != nil { - var w *guiWidget - w = p.TK.(*guiWidget) - w.hideWidgets() - w.redoTabs(me.TabW, me.TabH) - unsetCurrent(w) + p.hideWidgets() + p.redoTabs(me.TabW, me.TabH) + p.unsetCurrent() for _, child := range w.children { - if child.node.WidgetType == widget.Tab { - setColor(child.node, &colorTab) + if child.WidgetType == widget.Tab { + child.setColor(&colorTab) child.currentTab = false } } } w.currentTab = true - setColor(n, &colorActiveT) - setCurrentTab(n) - placeWidgets(n, me.RawW, me.RawH) + w.setColor(&colorActiveT) + w.setCurrentTab() + w.placeWidgets(me.RawW, me.RawH) w.showWidgets() case widget.Group: // n.placeWidgets(p.tk.startH, newH) - toggleTree(n) + w.toggleTree() case widget.Checkbox: - var w *guiWidget - w = n.TK.(*guiWidget) if widget.GetBool(w.value) { w.setCheckbox(false) } else { @@ -177,30 +162,26 @@ func doWidgetClick(n *tree.Node) { // n.doUserEvent() me.myTree.SendUserEvent(me.treeRoot) case widget.Grid: - newR := realGocuiSize(n) + newR := w.realGocuiSize() // w,h := n.logicalSize() // w := newR.w1 - newR.w0 // h := newR.h1 - newR.h0 - placeGrid(n, newR.w0, newR.h0) - var w *guiWidget - w = n.TK.(*guiWidget) + w.placeGrid(newR.w0, newR.h0) w.showWidgets() case widget.Box: - var w *guiWidget - w = n.TK.(*guiWidget) // w.showWidgetPlacement(logNow, "drawTree()") if w.direction == widget.Horizontal { - log.Log(NOW, "BOX IS HORIZONTAL", n.String()) + log.Log(NOW, "BOX IS HORIZONTAL", w.String()) } else { - log.Log(NOW, "BOX IS VERTICAL", n.String()) + log.Log(NOW, "BOX IS VERTICAL", w.String()) } - placeWidgets(n, me.RawW, me.RawH) - toggleTree(n) + w.placeWidgets(me.RawW, me.RawH) + w.toggleTree() case widget.Button: // doUserEvent(n) - me.myTree.SendUserEvent(n) + me.myTree.SendUserEvent(w.node) case widget.Dropdown: log.Log(NOW, "do the dropdown here") if me.ddview == nil { @@ -235,10 +216,10 @@ func doWidgetClick(n *tree.Node) { } else { var dnsList string for i, s := range tk.vals { - log.Log(NOW, "AddText()", n.String(), i, s) + log.Log(NOW, "AddText()", w.String(), i, s) dnsList += s + "\n" } - me.ddNode = n + me.ddNode = w.node log.Log(NOW, "new dns list should be set to:", dnsList) tk.labelN = dnsList tk.SetText(dnsList) @@ -253,11 +234,9 @@ func doWidgetClick(n *tree.Node) { var toggle bool = true -func toggleTree(n *tree.Node) { - var w *guiWidget - w = n.TK.(*guiWidget) +func (w *guiWidget) toggleTree() { if toggle { - drawTree(n, toggle) + w.drawTree(toggle) toggle = false } else { w.hideWidgets() @@ -266,13 +245,11 @@ func toggleTree(n *tree.Node) { } // display the widgets in the binary tree -func drawTree(n *tree.Node, draw bool) { - var w *guiWidget - w = n.TK.(*guiWidget) +func (w *guiWidget) drawTree(draw bool) { if w == nil { return } - showWidgetPlacement(n, true, "drawTree()") + w.showWidgetPlacement(true, "drawTree()") if draw { // w.textResize() w.showView() @@ -281,7 +258,7 @@ func drawTree(n *tree.Node, draw bool) { } for _, child := range w.children { - drawTree(child.node, draw) + child.drawTree(draw) } } @@ -294,14 +271,14 @@ func click(g *gocui.Gui, v *gocui.View) error { n := findUnderMouse() var w *guiWidget w = n.TK.(*guiWidget) - if n != nil { - log.Log(NOW, "click() Found widget =", n.WidgetId, n.String(), ",", w.labelN) - if n.String() == "DropBox" { + if w != nil { + log.Log(NOW, "click() Found widget =", w.node.WidgetId, w.String(), ",", w.labelN) + if w.String() == "DropBox" { log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?") log.Log(NOW, "click() set a global dropdown clicked flag=true here") me.ddClicked = true } - doWidgetClick(n) + w.doWidgetClick() } else { log.Log(NOW, "click() could not find node name =", v.Name()) } @@ -381,7 +358,8 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error { found = me.treeRoot } tk.labelN = found.String() - newR := realGocuiSize(found) + foundtk := found.TK.(*guiWidget) + newR := foundtk.realGocuiSize() tk.gocuiSize.w0 = newR.w0 tk.gocuiSize.h0 = newR.h0 tk.gocuiSize.w1 = newR.w1 diff --git a/color.go b/color.go index 4c9ffe6..e02e747 100644 --- a/color.go +++ b/color.go @@ -6,7 +6,6 @@ import ( "github.com/awesome-gocui/gocui" "go.wit.com/log" - "go.wit.com/toolkits/tree" ) //w.v.SelBgColor = gocui.ColorCyan @@ -67,10 +66,7 @@ var colorNone colorT = colorT{none, none, none, none, none, "debug none"} // TODO: maybe enough of us could actually do that if we made it a goal. // TODO: start with riscv boards and fix it universally there // TODO: so just a small little 'todo' item here -func setColor(n *tree.Node, newColor *colorT) { - var tk *guiWidget - tk = n.TK.(*guiWidget) - +func (tk *guiWidget) setColor(newColor *colorT) { if tk.color == newColor { // nothing to do since the colors have nto changed return @@ -87,15 +83,11 @@ func setColor(n *tree.Node, newColor *colorT) { tk.recreateView() } -func setDefaultWidgetColor(n *tree.Node) { - var w *guiWidget - w = n.TK.(*guiWidget) +func (w *guiWidget) setDefaultWidgetColor() { w.showView() } -func setDefaultHighlight(n *tree.Node) { - var w *guiWidget - w = n.TK.(*guiWidget) +func (w *guiWidget) setDefaultHighlight() { if w.v == nil { log.Log(ERROR, "SetColor() failed on view == nil") return @@ -117,8 +109,8 @@ func (w *guiWidget) redoColor(draw bool) { } log.Sleep(.05) - setDefaultHighlight(w.node) - setDefaultWidgetColor(w.node) + w.setDefaultHighlight() + w.setDefaultWidgetColor() for _, child := range w.children { child.redoColor(draw) diff --git a/place.go b/place.go index 9543e07..b6b96da 100644 --- a/place.go +++ b/place.go @@ -8,29 +8,26 @@ import ( "go.wit.com/widget" ) -func placeBox(n *tree.Node, startW int, startH int) { - var tk *guiWidget - tk = n.TK.(*guiWidget) - - if n.WidgetType != widget.Box { +func (tk *guiWidget) placeBox(startW int, startH int) { + if tk.WidgetType != widget.Box { return } - showWidgetPlacement(n, true, "boxS()") + tk.showWidgetPlacement(true, "boxS()") newW := startW newH := startH for _, child := range tk.children { - placeWidgets(child.node, newW, newH) + child.placeWidgets(newW, newH) // n.showWidgetPlacement(logNow, "boxS()") - newR := realGocuiSize(child.node) + newR := child.realGocuiSize() w := newR.w1 - newR.w0 h := newR.h1 - newR.h0 if child.direction == widget.Horizontal { - log.Log(NOW, "BOX IS HORIZONTAL", n.String(), "newWH()", newW, newH, "child()", w, h, child.String()) + log.Log(NOW, "BOX IS HORIZONTAL", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String()) // expand based on the child width newW += w } else { - log.Log(NOW, "BOX IS VERTICAL ", n.String(), "newWH()", newW, newH, "child()", w, h, child.String()) + log.Log(NOW, "BOX IS VERTICAL ", tk.String(), "newWH()", newW, newH, "child()", w, h, child.String()) // expand based on the child height newH += h } @@ -39,46 +36,43 @@ func placeBox(n *tree.Node, startW int, startH int) { // just compute this every time? // newR := n.realGocuiSize() - showWidgetPlacement(n, true, "boxE()") + tk.showWidgetPlacement(true, "boxE()") } -func placeWidgets(n *tree.Node, startW int, startH int) { - if n == nil { +func (tk *guiWidget) placeWidgets(startW int, startH int) { + if tk == nil { return } if me.treeRoot == nil { return } - var tk *guiWidget - tk = n.TK.(*guiWidget) - - switch n.WidgetType { + switch tk.WidgetType { case widget.Window: for _, child := range tk.children { - placeWidgets(child.node, me.RawW, me.RawH) + child.placeWidgets(me.RawW, me.RawH) return } case widget.Tab: for _, child := range tk.children { - placeWidgets(child.node, me.RawW, me.RawH) + child.placeWidgets(me.RawW, me.RawH) return } case widget.Grid: - placeGrid(n, startW, startH) + tk.placeGrid(startW, startH) case widget.Box: - placeBox(n, startW, startH) + tk.placeBox(startW, startH) case widget.Group: // move the group to the parent's next location tk.gocuiSetWH(startW, startH) - showWidgetPlacement(n, true, "group()") + tk.showWidgetPlacement(true, "group()") newW := startW + me.GroupPadW newH := startH + 3 // normal hight of the group label // now move all the children aka: run place() on them for _, child := range tk.children { - placeWidgets(child.node, newW, newH) - newR := realGocuiSize(child.node) + child.placeWidgets(newW, newH) + newR := child.realGocuiSize() // w := newR.w1 - newR.w0 h := newR.h1 - newR.h0 @@ -91,17 +85,15 @@ func placeWidgets(n *tree.Node, startW int, startH int) { } } -func placeGrid(n *tree.Node, startW int, startH int) { - var w *guiWidget - w = n.TK.(*guiWidget) - showWidgetPlacement(n, true, "grid0:") - if n.WidgetType != widget.Grid { +func (w *guiWidget) placeGrid(startW int, startH int) { + w.showWidgetPlacement(true, "grid0:") + if w.WidgetType != widget.Grid { return } // first compute the max sizes of the rows and columns for _, child := range w.children { - newR := realGocuiSize(child.node) + newR := child.realGocuiSize() childW := newR.w1 - newR.w0 childH := newR.h1 - newR.h0 @@ -118,7 +110,7 @@ func placeGrid(n *tree.Node, startW int, startH int) { // find the width and height offset of the grid for AtW,AtH for _, child := range w.children { - showWidgetPlacement(w.node, true, "grid1:") + child.showWidgetPlacement(true, "grid1:") var totalW, totalH int for i, w := range w.widths { @@ -137,15 +129,15 @@ func placeGrid(n *tree.Node, startW int, startH int) { newH := startH + totalH log.Log(INFO, "placeGrid:", child.String(), "new()", newW, newH, "At()", child.AtW, child.AtH) - placeWidgets(child.node, newW, newH) - showWidgetPlacement(child.node, true, "grid2:") + child.placeWidgets(newW, newH) + child.showWidgetPlacement(true, "grid2:") } - showWidgetPlacement(n, true, "grid3:") + w.showWidgetPlacement(true, "grid3:") } // computes the real, actual size of all the gocli objects in a widget -func realGocuiSize(n *tree.Node) *rectType { - var f func(n *tree.Node, r *rectType) +func (w *guiWidget) realGocuiSize() *rectType { + var f func(tk *guiWidget, r *rectType) newR := new(rectType) // initialize the values to opposite newR.w0 = 80 @@ -159,9 +151,7 @@ func realGocuiSize(n *tree.Node) *rectType { newR.h1 = 0 // expand the rectangle to the biggest thing displayed - f = func(n *tree.Node, r *rectType) { - var tk *guiWidget - tk = n.TK.(*guiWidget) + f = func(tk *guiWidget, r *rectType) { newR := tk.gocuiSize if !tk.isFake { if r.w0 > newR.w0 { @@ -178,10 +168,10 @@ func realGocuiSize(n *tree.Node) *rectType { } } for _, child := range tk.children { - f(child.node, r) + f(child, r) } } - f(n, newR) + f(w, newR) return newR } diff --git a/structs.go b/structs.go index a3b9d89..dc519a9 100644 --- a/structs.go +++ b/structs.go @@ -33,7 +33,7 @@ var redoWidgets bool = true var currentWindow *tree.Node type config struct { - baseGui *gocui.Gui // the main gocui handle + baseGui *gocui.Gui // the main gocui handle // rootNode *node // the base of the binary tree. it should have id == 0 treeRoot *tree.Node // the base of the binary tree. it should have id == 0 diff --git a/widget.go b/widget.go index b1bb7bb..9626861 100644 --- a/widget.go +++ b/widget.go @@ -72,27 +72,6 @@ func (w *guiWidget) deleteView() { w.v = nil } -/* -// searches the binary tree for a WidgetId -func findWidgetName(n *tree.Node, 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 (w *guiWidget) IsCurrent() bool { if w.node.WidgetType == widget.Tab { return w.isCurrent @@ -120,20 +99,6 @@ func (tk *guiWidget) Visible() bool { return tk.v.Visible } -/* -func Visible(n *tree.Node) bool { - if n == nil { - return false - } - if n.TK == nil { - return false - } - var w *guiWidget - w = n.TK.(*guiWidget) - return w.Visible() -} -*/ - func (w *guiWidget) SetVisible(b bool) { if w.v == nil { return