trying to send Close Window() from toolkit plugin
This commit is contained in:
parent
e134ecb6a4
commit
f5d465901d
|
@ -4,12 +4,60 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/widget"
|
"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 there is a current window, hide it
|
||||||
if me.currentWindow != nil {
|
if me.currentWindow != nil {
|
||||||
me.currentWindow.setColor(&colorWindow)
|
me.currentWindow.setColor(&colorWindow)
|
||||||
|
@ -28,7 +76,8 @@ func (tk *guiWidget) doWindowClick(w int, h int) {
|
||||||
func (tk *guiWidget) doWidgetClick(w int, h int) {
|
func (tk *guiWidget) doWidgetClick(w int, h int) {
|
||||||
switch tk.node.WidgetType {
|
switch tk.node.WidgetType {
|
||||||
case widget.Window:
|
case widget.Window:
|
||||||
tk.doWindowClick(w, h)
|
// tk.dumpWidget("doWidgetClick()")
|
||||||
|
tk.doWindowClick()
|
||||||
return
|
return
|
||||||
case widget.Group:
|
case widget.Group:
|
||||||
case widget.Checkbox:
|
case widget.Checkbox:
|
||||||
|
|
|
@ -130,6 +130,7 @@ type window struct {
|
||||||
isBG bool // means this is the background widget. There is only one of these
|
isBG bool // means this is the background widget. There is only one of these
|
||||||
order int // what level the window is on
|
order int // what level the window is on
|
||||||
resize bool // only set the title once
|
resize bool // only set the title once
|
||||||
|
collapsed bool // only show the window title bar
|
||||||
}
|
}
|
||||||
|
|
||||||
type guiWidget struct {
|
type guiWidget struct {
|
||||||
|
|
|
@ -46,6 +46,7 @@ func addWidget(n *tree.Node) {
|
||||||
return
|
return
|
||||||
case widget.Window:
|
case widget.Window:
|
||||||
tk.frame = false
|
tk.frame = false
|
||||||
|
tk.labelN = tk.GetText() + " X"
|
||||||
// tk.color = &colorWindow
|
// tk.color = &colorWindow
|
||||||
tk.setColor(&colorWindow)
|
tk.setColor(&colorWindow)
|
||||||
me.newWindowTrigger <- tk
|
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
|
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() {
|
func (w *guiWidget) hideWidgets() {
|
||||||
if w == nil {
|
if w == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -31,7 +31,13 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
|
||||||
|
|
||||||
tk.DrawAt(w, h)
|
tk.DrawAt(w, h)
|
||||||
tk.setColor(&colorActiveW) // sets the window to Green BG
|
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
|
// this is a test. this should not be needed
|
||||||
tk.full.w0 = tk.force.w0
|
tk.full.w0 = tk.force.w0
|
||||||
|
|
Loading…
Reference in New Issue