diff options
| author | Jeff Carr <[email protected]> | 2023-12-02 19:02:51 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2023-12-02 19:02:51 -0600 |
| commit | 7880d9df6de1040258bea966f040e12be6205af1 (patch) | |
| tree | bb0f3d74eb4e3b5094bfe78e936679efb940cacf /toolkit/gocui/tab.go | |
| parent | 19e6ea76f3c09fe3a5d9a4d4caff7d14571f4ba5 (diff) | |
gocui plugin refactor to a *node binary tree
rename arg '--gui <toolkit>'
add a cloudflare example
fixes since go v1.21 didn't compile anymore due to argv order
more place() changes
recursive size computation
gocui: Major refactor to use the *node binary tree
gocui: refactor place() and size()
gocui: better place() and spacing (tab, buttons, etc)
gocui: better mouse click handling
gocui: switch to using tk.gocuiSize & tk.size
gocui: event handling cleanups
gocui: add window labels work
gocui: struct cleanups
gocui: duplicate binary tree structs removed
gocui: deprecate old children
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui/tab.go')
| -rw-r--r-- | toolkit/gocui/tab.go | 185 |
1 files changed, 80 insertions, 105 deletions
diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go index 8c5b11b..60ee6b3 100644 --- a/toolkit/gocui/tab.go +++ b/toolkit/gocui/tab.go @@ -3,136 +3,111 @@ package main // implements widgets 'Window' and 'Tab' import ( + "strings" "git.wit.org/wit/gui/toolkit" -// "github.com/awesome-gocui/gocui" ) -func (w *cuiWidget) hideWidgets() { - w.isCurrent = false - switch w.widgetType { - case toolkit.Root: - case toolkit.Flag: - case toolkit.Window: - // case toolkit.Tab: - case toolkit.Box: - case toolkit.Grid: - default: - w.deleteView() - } - for _, child := range w.children { - child.hideWidgets() +func (w *cuiWidget) Width() int { + if w.frame { + return w.gocuiSize.w1 - w.gocuiSize.w0 } + return w.gocuiSize.w1 - w.gocuiSize.w0 - 1 } -func (w *cuiWidget) hideFake() { - if (w.isFake) { - w.deleteView() - } - for _, child := range w.children { - child.hideFake() +func (w *cuiWidget) Height() int { + if w.frame { + return w.gocuiSize.h1 - w.gocuiSize.h0 } + return w.gocuiSize.h1 - w.gocuiSize.h0 - 1 } -func (w *cuiWidget) showFake() { - if (w.isFake) { - w.setFake() - w.showWidgetPlacement(logNow, "showFake:") - w.showView() - } - for _, child := range w.children { - child.showFake() +func (n *node) gocuiSetWH(sizeW, sizeH int) { + w := len(n.Text) + lines := strings.Split(n.Text, "\n") + h := len(lines) + + tk := n.tk + if tk.isFake { + tk.gocuiSize.w0 = sizeW + tk.gocuiSize.h0 = sizeH + tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + me.FramePadW + tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH + return } -} -func (w *cuiWidget) showWidgets() { - if (w.isFake) { - // don't display by default + if tk.frame { + tk.size.w0 = sizeW + tk.size.h0 = sizeH + tk.gocuiSize.w0 = tk.size.w0 + tk.gocuiSize.h0 = tk.size.h0 + tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + me.FramePadW + tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH } else { - if w.IsCurrent() { - w.showWidgetPlacement(logInfo, "current:") - w.showView() - } else { - w.showWidgetPlacement(logInfo, "not:") - // w.drawView() - } - } - for _, child := range w.children { - child.showWidgets() + tk.size.w0 = sizeW - 1 + tk.size.h0 = sizeH - 1 + tk.gocuiSize.w0 = tk.size.w0 + tk.gocuiSize.h0 = tk.size.h0 + tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + 1 + tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + 1 } } -func (w *cuiWidget) setWindowWH() { - w.gocuiSize.w0 = me.rootNode.nextW - w.gocuiSize.h0 = me.WindowH - - t := len(w.text) - w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW - w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH - - w.realWidth = w.gocuiSize.Width() - w.realHeight = w.gocuiSize.Height() - - // move the rootNode width over for the next window - me.rootNode.nextW += w.realWidth + me.WindowPadW - - w.nextW = 4 - w.nextH = 2 - - w.showWidgetPlacement(logNow, "setWindowWH:") -} - -func (w *cuiWidget) setTabWH() { - // set the start and size of the tab gocui button - - w.gocuiSize.w0 = w.parent.nextW - w.gocuiSize.h0 = me.TabH - - t := len(w.text) - w.gocuiSize.w1 = w.gocuiSize.w0 + t + me.PadW - w.gocuiSize.h1 = w.gocuiSize.h0 + me.DefaultHeight + me.PadH - - w.realWidth = w.gocuiSize.Width() - w.realHeight = w.gocuiSize.Height() - - w.realWidth += me.FramePadW - w.realHeight += me.FramePadH - - w.parent.nextW += w.realWidth + me.TabPadW - - w.showWidgetPlacement(logNow, "setTabWH:") -} - -func (w *cuiWidget) redoTabs(draw bool) { - if (w.widgetType == toolkit.Window) { - var tabs bool = false - // figure out if the window is just a bunch of tabs - for _, child := range w.children { - if (child.widgetType == toolkit.Tab) { +func redoWindows(nextW int, nextH int) { + for _, n := range me.rootNode.children { + if n.WidgetType != toolkit.Window { + continue + } + w := n.tk + var tabs bool + for _, child := range n.children { + if (child.WidgetType == toolkit.Tab) { tabs = true } } if (tabs) { // window is tabs. Don't show it as a standard button w.frame = false - w.hasTabs = true + n.hasTabs = true } else { - w.frame = true - w.hasTabs = false + w.frame = false + n.hasTabs = false } - w.setWindowWH() - w.deleteView() - w.showView() - } - if (w.widgetType == toolkit.Tab) { - w.setTabWH() - w.deleteView() - // show all the tabs for the current window - if w.parent.isCurrent { - w.showView() + + w.size.w0 = nextW + w.size.h0 = nextH + n.gocuiSetWH(nextW, nextH) + n.deleteView() + n.showView() + + sizeW := w.Width() + me.WindowPadW + sizeH := w.Height() + nextW += sizeW + log(logNow, "redoWindows() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) + + if n.hasTabs { + n.redoTabs(me.TabW, me.TabH) } } +} + +func (p *node) redoTabs(nextW int, nextH int) { + for _, n := range p.children { + if n.WidgetType != toolkit.Tab { + continue + } + w := n.tk + w.frame = true + + w.size.w0 = nextW + w.size.h0 = nextH + n.gocuiSetWH(nextW, nextH) + n.deleteView() + // setCurrentTab(n) + n.showView() - for _, child := range w.children { - child.redoTabs(draw) + sizeW := w.Width() + me.TabPadW + sizeH := w.Height() + log(logNow, "redoTabs() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) + nextW += sizeW } } |
