window close works

This commit is contained in:
Jeff Carr 2025-02-09 03:21:48 -06:00
parent 8d8fc22745
commit 5bac0308e5
4 changed files with 8 additions and 67 deletions

View File

@ -57,8 +57,8 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
if win != nil {
w, h := g.MousePosition()
s := fmt.Sprintf("mouse(%d,%d) ", w, h)
offW := win.gocuiSize.w1 - w
offH := win.gocuiSize.h1 - h
offW := win.full.w1 - w
offH := win.full.h1 - h
s += fmt.Sprintf("corner(%d,%d)", offW, offH)
if (offW < 3) && (offH < 3) {
log.Info("attempting resize on ", s, win.cuiName)

View File

@ -10,76 +10,12 @@ import (
"go.wit.com/widget"
)
/*
// this didn't work. panic()
func (tk *guiWidget) DeleteNode() {
p := tk.parent
for i, child := range p.children {
log.Log(GOCUI, "parent has child:", i, child.node.WidgetId, child.node.GetProgName())
if tk == child {
log.Log(GOCUI, "Found child ==", i, child.node.WidgetId, child.node.GetProgName())
log.Log(GOCUI, "Found n ==", i, tk.node.WidgetId, tk.node.GetProgName())
p.children = append(p.children[:i], p.children[i+1:]...)
}
}
for i, child := range p.children {
log.Log(TREE, "parent now has child:", i, child.WidgetId, child.GetProgName())
}
}
*/
func (tk *guiWidget) doWindowClick() {
w, h := me.baseGui.MousePosition()
tk.dumpWidget(fmt.Sprintf("doWindowClick(%d,%d)", w, h))
// compare the mouse location to the 'X' indicator to close the window
if tk.gocuiSize.inRect(w, h) {
offset := w - tk.gocuiSize.w1
if (offset < 2) && (offset > -2) {
// close enough // close the window here
tk.dumpWidget(fmt.Sprintf("Close Window(%d,%d) (off=%d)", w, h, offset))
tk.hideWindow()
n := tk.node
tk.deleteNode()
me.myTree.SendWindowCloseEvent(n)
/*
n.DeleteNode()
tk.DeleteNode()
*/
return
}
if tk.window.collapsed {
tk.dumpWidget(fmt.Sprintf("collapse = false"))
tk.window.collapsed = false
} else {
tk.dumpWidget(fmt.Sprintf("collapse = true"))
tk.window.collapsed = true
}
} else {
tk.window.collapsed = false
}
// if there is a current window, hide it
if me.currentWindow != nil {
me.currentWindow.setColor(&colorWindow)
}
// now set this window as the current window
me.currentWindow = tk
tk.redrawWindow(w, h)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
}
// this whole things was impossible to make but it got me where I am now
// the debugging is way way better now with it being visible in the Stdout window
// so now it's possible to redo all this and make it better
func (tk *guiWidget) doWidgetClick(w int, h int) {
tk.dumpWidget(fmt.Sprintf("doWidgetClick(%d,%d)", w, h))
switch tk.node.WidgetType {
case widget.Window:
tk.doWindowClick()
return
case widget.Checkbox:
if tk.node.State.Checked {
log.Log(WARN, "checkbox is being set to false")

View File

@ -39,6 +39,9 @@ func init() {
// init the config struct default values
Set(&me, "default")
// todo: some early output still goes to the /tmp/ file
//time.Sleep(200 * time.Millisecond)
log.CaptureMode(me.stdout)
// initial stdout window settings
me.stdout.w = 180
@ -151,6 +154,7 @@ func mainGogui() {
var err error
// todo: make this a tmp file that goes away
me.outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Info("error opening file:", err)

View File

@ -246,9 +246,10 @@ func (win *guiWidget) checkWindowClose(w int, h int) bool {
s += fmt.Sprintf("offset(%d,%d)", offW, offH)
if (offW < 2) && (offH < 2) {
log.Info("attempting close on ", s, win.cuiName)
me.myTree.SendWindowCloseEvent(win.node)
// store the stdout corner for computing the drag size
return true
}
log.Info("not attempting close on ", s, win.cuiName)
// log.Info("not attempting close on ", s, win.cuiName)
return false
}