summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-06 17:29:17 -0600
committerJeff Carr <[email protected]>2025-02-06 17:29:17 -0600
commitf5d465901d2ec48e145c3c7ce04eceb69445a11f (patch)
tree0aa6f6f9edd9c7bb8fb3c4a3b304c3f9a63d6a42
parente134ecb6a4285d576c45c3f86274703f32ab30b0 (diff)
trying to send Close Window() from toolkit plugin
-rw-r--r--eventMouseClick.go53
-rw-r--r--structs.go1
-rw-r--r--treeAdd.go1
-rw-r--r--view.go11
-rw-r--r--window.go8
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