stdout window remembers where it was

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-05 01:08:12 -06:00
parent 145bad6c9a
commit 8f9e47c117
6 changed files with 83 additions and 67 deletions

View File

@ -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()

38
draw.go Normal file
View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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() {