code cleanups

This commit is contained in:
Jeff Carr 2025-02-09 12:21:43 -06:00
parent 87d31a3d94
commit c5cada3dc9
7 changed files with 63 additions and 54 deletions

View File

@ -81,7 +81,7 @@ func theNotsure(g *gocui.Gui, v *gocui.View) error {
win := findWindowUnderMouse() win := findWindowUnderMouse()
if win != nil { if win != nil {
win.dumpWidget("found() win. redrawing window:") win.dumpWidget("found() win. redrawing window:")
win.redrawWindow(win.gocuiSize.w0, win.gocuiSize.h0) win.makeWindowActive()
} }
return nil return nil
@ -119,8 +119,6 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
tk.makeWindowActive() tk.makeWindowActive()
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return nil return nil
} }

View File

@ -110,41 +110,47 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
log.Info("never found textbox at", w, h) log.Info("never found textbox at", w, h)
return nil return nil
} }
// figre out what window this is // figre out what window this is
tk := findWindowUnderMouse() win := findWindowUnderMouse()
if tk == nil { if win == nil {
log.Info("mouseDown() nothing to click on at", w, h) log.Info("mouseDown() nothing to click on at", w, h)
return nil return nil
} }
tk.makeWindowActive() return nil
// log.Info("SENDING mouseDown() to findWindowUnderMouse()") // me.mouse.currentDrag = tk
if tk.node.WidgetType == widget.Window {
// check to see if this is a direct click on a widget /*
for _, tk := range tk.findByXYreal(w, h) { if !tk.isWindowActive() {
// tk.dumpWidget("mouseDown()") tk.makeWindowActive()
if tk.node.WidgetType == widget.Button { return nil
// log.Info("SENDING CLICK TO Button") }
tk.doWidgetClick(w, h)
return nil // log.Info("SENDING mouseDown() to findWindowUnderMouse()")
} if tk.node.WidgetType == widget.Window {
if tk.node.WidgetType == widget.Checkbox { // check to see if this is a direct click on a widget
// log.Info("SENDING CLICK TO Checkbox") for _, tk := range tk.findByXYreal(w, h) {
tk.doWidgetClick(w, h) // tk.dumpWidget("mouseDown()")
return nil if tk.node.WidgetType == widget.Button {
} // log.Info("SENDING CLICK TO Button")
if tk.node.WidgetType == widget.Dropdown { tk.doWidgetClick(w, h)
// log.Info("SENDING CLICK TO Dropdown") return nil
tk.doWidgetClick(w, h) }
return nil if tk.node.WidgetType == widget.Checkbox {
} // log.Info("SENDING CLICK TO Checkbox")
if tk.node.WidgetType == widget.Textbox { tk.doWidgetClick(w, h)
// log.Info("SENDING CLICK TO Textbox") return nil
tk.doWidgetClick(w, h) }
return nil if tk.node.WidgetType == widget.Dropdown {
// log.Info("SENDING CLICK TO Dropdown")
tk.doWidgetClick(w, h)
return nil
}
if tk.node.WidgetType == widget.Textbox {
// log.Info("SENDING CLICK TO Textbox")
tk.doWidgetClick(w, h)
return nil
}
} }
} }
} */
me.mouse.currentDrag = tk
return nil
} }

View File

@ -115,9 +115,7 @@ func doMouseClick(w int, h int) {
return return
} }
// log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName) // log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName)
win.redrawWindow(win.gocuiSize.w0, win.gocuiSize.h0) win.makeWindowActive()
me.stdout.outputOnTop = false
setThingsOnTop()
return return
} }
@ -154,9 +152,7 @@ func doMouseDoubleClick(w int, h int) {
for _, tk := range findByXY(w, h) { for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Window { if tk.node.WidgetType == widget.Window {
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0) tk.makeWindowActive()
me.stdout.outputOnTop = false
setThingsOnTop()
return return
} }

View File

@ -143,11 +143,9 @@ func (tk *guiWidget) moveNew() {
// compute the new location based off how far the mouse has moved // compute the new location based off how far the mouse has moved
// since the mouse button was pressed down // since the mouse button was pressed down
newW := tk.lastW + w - me.mouse.downW tk.gocuiSize.w0 = tk.lastW + w - me.mouse.downW
newH := tk.lastH + h - me.mouse.downH tk.gocuiSize.h0 = tk.lastH + h - me.mouse.downH
tk.redrawWindow(newW, newH) tk.makeWindowActive()
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return return
} }
if tk.node.WidgetType == widget.Flag { if tk.node.WidgetType == widget.Flag {

View File

@ -306,12 +306,6 @@ func newWindowTrigger() {
relocateStdoutOffscreen() relocateStdoutOffscreen()
} }
tk.makeWindowActive() tk.makeWindowActive()
// place the new window relative to the mouse
tk.redrawWindow(me.mouse.downW+8, me.mouse.downH-2)
// tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
// log.Log(NOW, "newWindowTrigger() after sleep")
} }
} }
} }

View File

@ -118,6 +118,6 @@ func textboxClosed() {
me.textbox.callerTK.Size() me.textbox.callerTK.Size()
me.textbox.callerTK.placeWidgets(tk.gocuiSize.w0-4, tk.gocuiSize.h0-4) me.textbox.callerTK.placeWidgets(tk.gocuiSize.w0-4, tk.gocuiSize.h0-4)
// tk.dumpWidget("resize:" + tk.String()) // tk.dumpWidget("resize:" + tk.String())
win.redrawWindow(win.gocuiSize.w0, win.gocuiSize.h0) win.makeWindowActive()
} }
} }

View File

@ -115,8 +115,7 @@ func redoWindows(nextW int, nextH int) {
// tk.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH)) // tk.dumpWidget(fmt.Sprintf("redoWindowsS (%d,%d)", nextW, nextH))
if tk.window.wasDragged { if tk.window.wasDragged {
// don't move windows around the user has dragged to a certain location // don't move windows around the user has dragged to a certain location
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0) tk.makeWindowActive()
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
} else { } else {
w, _ := me.baseGui.Size() w, _ := me.baseGui.Size()
if nextW > w-20 { if nextW > w-20 {
@ -175,12 +174,27 @@ func (win *guiWidget) addWindowFrame(wId int) *tree.Node {
return n return n
} }
func (tk *guiWidget) isWindowActive() bool {
if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
// only allow Window or the Stdout widgets to be made active
return false
}
return tk.window.active
}
// always redraws at the corner of the gocuiSize box
func (tk *guiWidget) makeWindowActive() { func (tk *guiWidget) makeWindowActive() {
if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) { if !(tk.node.WidgetType == widget.Window || tk.node.WidgetType == widget.Stdout) {
// only allow Window or the Stdout widgets to be made active // only allow Window or the Stdout widgets to be made active
return return
} }
if tk.node.WidgetType == widget.Stdout {
me.stdout.outputOnTop = true
} else {
// me.stdout.outputOnTop = false // ?
}
// disable and increment all the windows // disable and increment all the windows
for _, tk := range me.allwin { for _, tk := range me.allwin {
tk.window.order += 1 tk.window.order += 1
@ -193,6 +207,9 @@ func (tk *guiWidget) makeWindowActive() {
tk.window.active = true tk.window.active = true
tk.window.order = 0 tk.window.order = 0
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
/* /*
// print out the window list // print out the window list
for _, tk := range me.allwin { for _, tk := range me.allwin {