From f5d465901d2ec48e145c3c7ce04eceb69445a11f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 6 Feb 2025 17:29:17 -0600 Subject: [PATCH] trying to send Close Window() from toolkit plugin --- eventMouseClick.go | 53 ++++++++++++++++++++++++++++++++++++++++++++-- structs.go | 1 + treeAdd.go | 1 + view.go | 11 ++++++++++ window.go | 8 ++++++- 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/eventMouseClick.go b/eventMouseClick.go index 222cb81..0d09007 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -4,12 +4,60 @@ package main import ( + "fmt" + "github.com/awesome-gocui/gocui" "go.wit.com/log" "go.wit.com/widget" ) -func (tk *guiWidget) doWindowClick(w int, h int) { +/* +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() + // 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 + // tk.dumpWidget(fmt.Sprintf("No (%d,%d)", w, h)) + } // if there is a current window, hide it if me.currentWindow != nil { me.currentWindow.setColor(&colorWindow) @@ -28,7 +76,8 @@ func (tk *guiWidget) doWindowClick(w int, h int) { func (tk *guiWidget) doWidgetClick(w int, h int) { switch tk.node.WidgetType { case widget.Window: - tk.doWindowClick(w, h) + // tk.dumpWidget("doWidgetClick()") + tk.doWindowClick() return case widget.Group: case widget.Checkbox: diff --git a/structs.go b/structs.go index b4d1aef..01a7f49 100644 --- a/structs.go +++ b/structs.go @@ -130,6 +130,7 @@ type window struct { isBG bool // means this is the background widget. There is only one of these order int // what level the window is on resize bool // only set the title once + collapsed bool // only show the window title bar } type guiWidget struct { diff --git a/treeAdd.go b/treeAdd.go index 2e3dbea..a670010 100644 --- a/treeAdd.go +++ b/treeAdd.go @@ -46,6 +46,7 @@ func addWidget(n *tree.Node) { return case widget.Window: tk.frame = false + tk.labelN = tk.GetText() + " X" // tk.color = &colorWindow tk.setColor(&colorWindow) me.newWindowTrigger <- tk diff --git a/view.go b/view.go index c6cd296..b518d59 100644 --- a/view.go +++ b/view.go @@ -28,6 +28,17 @@ func (tk *guiWidget) textResize() { tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH // TODO: fix this size computation } +// deletes every view +func (w *guiWidget) hideWindow() { + if w == nil { + return + } + w.Hide() + for _, child := range w.children { + child.hideWindow() + } +} + func (w *guiWidget) hideWidgets() { if w == nil { return diff --git a/window.go b/window.go index 412096c..7d612e4 100644 --- a/window.go +++ b/window.go @@ -31,7 +31,13 @@ func (tk *guiWidget) redrawWindow(w int, h int) { tk.DrawAt(w, h) tk.setColor(&colorActiveW) // sets the window to Green BG - tk.placeWidgets(w, h) // compute the sizes & places for each widget + + if tk.window.collapsed { + // don't show anything but the title bar + tk.hideWindow() + return + } + tk.placeWidgets(w, h) // compute the sizes & places for each widget // this is a test. this should not be needed tk.full.w0 = tk.force.w0