trying to send Close Window() from toolkit plugin
This commit is contained in:
parent
e134ecb6a4
commit
f5d465901d
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
11
view.go
11
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue