From 8f9e47c11711b629ff7351c0626c85d3e8aa0979 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 5 Feb 2024 01:08:12 -0600 Subject: [PATCH] stdout window remembers where it was Signed-off-by: Jeff Carr --- click.go | 78 +++++++++++++++------------------------------------ draw.go | 38 +++++++++++++++++++++++++ showStdout.go | 18 ++++++++++-- structs.go | 6 ++-- view.go | 5 ---- widget.go | 5 +++- 6 files changed, 83 insertions(+), 67 deletions(-) create mode 100644 draw.go diff --git a/click.go b/click.go index abb1ac9..431d27d 100644 --- a/click.go +++ b/click.go @@ -20,46 +20,42 @@ func (w *guiWidget) doWidgetClick() { log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") case widget.Window: log.Log(NOW, "doWidgetClick() START on window", w.String()) - if me.currentWindow == w.node { + // if the user clicked on the current window, do nothing + /* Ignore this for now and redraw the window anyway + if me.currentWindow == w { if !w.active { return } } - if me.currentWindow != nil { - var curw *guiWidget - curw = me.currentWindow.TK.(*guiWidget) - // curw.unsetCurrent() - curw.setColor(&colorWindow) - curw.hideWidgets() - } - me.currentWindow = w.node + */ + // if there is a current window, hide it + if me.currentWindow != nil { + me.currentWindow.setColor(&colorWindow) + me.currentWindow.hideWidgets() + me.currentWindow.isCurrent = false + } + + // now set this window as the current window + me.currentWindow = w + w.isCurrent = true + + // draw the current window log.Log(NOW, "doWidgetClick() set currentWindow to", w.String()) w.setColor(&colorActiveW) - + w.DrawAt(3, 2) + w.placeWidgets(3, 2) // compute the sizes & places for each widget w.active = false - // w.dumpTree("before") - w.placeWidgets(3, 2) w.showWidgets() - - hideFake() - showDebug = true - - // w.dumpTree("after") + /* + hideFake() + showDebug = true + */ case widget.Group: - // n.placeWidgets(p.tk.startH, newH) - // w.dumpTree("click start") if w.active { w.active = false w.placeWidgets(w.startW, w.startH) w.showWidgets() - /* - for _, child := range w.children { - log.Log(INFO, "START W,H", startW, startH) - child.placeWidgets(startW, startH) - child.showWidgets() - } - */ } else { w.active = true for _, child := range w.children { @@ -111,36 +107,6 @@ func (w *guiWidget) doWidgetClick() { } } -var toggle bool = true - -func (w *guiWidget) toggleTree() { - if toggle { - w.drawTree(toggle) - toggle = false - } else { - w.hideWidgets() - toggle = true - } -} - -// display the widgets in the binary tree -func (w *guiWidget) drawTree(draw bool) { - if w == nil { - return - } - w.showWidgetPlacement("drawTree()") - if draw { - // w.textResize() - w.showView() - } else { - w.deleteView() - } - - for _, child := range w.children { - child.drawTree(draw) - } -} - func click(g *gocui.Gui, v *gocui.View) error { mouseW, mouseH := me.baseGui.MousePosition() diff --git a/draw.go b/draw.go new file mode 100644 index 0000000..db22fe2 --- /dev/null +++ b/draw.go @@ -0,0 +1,38 @@ +package main + +var toggle bool = true + +func (w *guiWidget) DrawAt(offsetW, offsetH int) { + w.setColor(&colorActiveW) + w.placeWidgets(offsetW, offsetH) // compute the sizes & places for each widget + w.active = false + w.showWidgets() +} + +func (w *guiWidget) toggleTree() { + if toggle { + w.drawTree(toggle) + toggle = false + } else { + w.hideWidgets() + toggle = true + } +} + +// display the widgets in the binary tree +func (w *guiWidget) drawTree(draw bool) { + if w == nil { + return + } + w.showWidgetPlacement("drawTree()") + if draw { + // w.textResize() + w.showView() + } else { + w.deleteView() + } + + for _, child := range w.children { + child.drawTree(draw) + } +} diff --git a/showStdout.go b/showStdout.go index 06feb78..13dd61a 100644 --- a/showStdout.go +++ b/showStdout.go @@ -19,6 +19,8 @@ func moveMsg(g *gocui.Gui) { movingMsg = true } g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0) + me.startOutputW = mx-xOffset + me.startOutputH = my-yOffset g.SetViewOnBottom("msg") } @@ -61,8 +63,10 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { var tk *guiWidget tk = me.logStdout.TK.(*guiWidget) - tk.gocuiSize.w0 = maxX - 32 - tk.gocuiSize.h0 = maxY / 2 + // tk.gocuiSize.w0 = maxX - 32 + // tk.gocuiSize.h0 = maxY / 2 + tk.gocuiSize.w0 = me.startOutputW + tk.gocuiSize.h0 = me.startOutputH tk.gocuiSize.w1 = tk.gocuiSize.w0 + outputW tk.gocuiSize.h1 = tk.gocuiSize.h0 + outputH } @@ -76,7 +80,15 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { // help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0) // v, err = g.SetView("msg", 3, 3, 30, 30, 0) - v, err = g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0) + if me.startOutputW == 0 { + me.startOutputW = maxX - 32 + } + if me.startOutputW == 0 { + me.startOutputH = maxY / 2 + } + + // v, err = g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0) + v, err = g.SetView("msg", me.startOutputW, me.startOutputH, maxX/2+outputW, maxY/2+outputH, 0) if errors.Is(err, gocui.ErrUnknownView) { log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err) } diff --git a/structs.go b/structs.go index cd5bdb2..365a43c 100644 --- a/structs.go +++ b/structs.go @@ -30,7 +30,7 @@ var showHelp bool = true var redoWidgets bool = true // This is the window that is currently active -var currentWindow *tree.Node +// var currentWindow *tree.Node type config struct { baseGui *gocui.Gui // the main gocui handle @@ -40,8 +40,10 @@ type config struct { myTree *tree.TreeInfo ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed - currentWindow *tree.Node // this is the current tab or window to show + currentWindow *guiWidget // this is the current tab or window to show logStdout *tree.Node // where to show STDOUT + startOutputW int + startOutputH int helpLabel *gocui.View // this is a floating widget that we show whenever the user clicks on a diff --git a/view.go b/view.go index 0f4563f..6c9f692 100644 --- a/view.go +++ b/view.go @@ -62,11 +62,6 @@ func (w *guiWidget) showView() { log.Log(INFO, "showView() labelN =", w.labelN) w.recreateView() - /* - w.textResize() - w.v.Clear() - fmt.Fprint(w.v, w.labelN) - */ } // create or recreate the gocui widget visible diff --git a/widget.go b/widget.go index 10f1af9..d87d35e 100644 --- a/widget.go +++ b/widget.go @@ -106,7 +106,10 @@ func (tk *guiWidget) Visible() bool { } func (tk *guiWidget) Show() { - tk.showView() + if tk.IsCurrent() { + tk.showView() + } else { + } } func (tk *guiWidget) Hide() {