summaryrefslogtreecommitdiff
path: root/eventBindings.go
diff options
context:
space:
mode:
Diffstat (limited to 'eventBindings.go')
-rw-r--r--eventBindings.go113
1 files changed, 86 insertions, 27 deletions
diff --git a/eventBindings.go b/eventBindings.go
index e923f2d..fe7b214 100644
--- a/eventBindings.go
+++ b/eventBindings.go
@@ -4,21 +4,21 @@
package main
import (
+ "fmt"
+ "strings"
"syscall"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
+ "go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
-// THIS IS A STANDARD.
-
// register how the 'gocui' will work as a GO toolkit plugin
// all applications will use these keys. they are universal.
// tells 'gocui' where to send events
func registerHandlers(g *gocui.Gui) {
- keyForced, modForced := gocui.MustParse("ctrl+z") // setup ctrl+z
// mouse handlers
g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, mouseDown) // normal left mouse down
@@ -29,6 +29,7 @@ func registerHandlers(g *gocui.Gui) {
g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, doExit) // CTRL-C : exits the application
g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, doPanic) // CTRL-V : force a panic()
g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, openDebuggger) // CTRL-D : open the (D)ebugger
+ keyForced, modForced := gocui.MustParse("ctrl+z") // setup ctrl+z
g.SetKeybinding("", keyForced, modForced, handle_ctrl_z) // CTRL-Z :cleverly let's you background gocui (breaks cursor mouse on return)
// regular keys
@@ -63,41 +64,97 @@ func setSuperMouse(g *gocui.Gui, v *gocui.View) error {
var wtf bool
+func (tk *guiWidget) verifyRect() bool {
+ if !tk.Visible() {
+ return false
+ }
+ vw0, vh0, vw1, vh1, err := me.baseGui.ViewPosition(tk.cuiName)
+ if err != nil {
+ log.Printf("verifyRect() gocui err=%v cuiName=%s v.Name=%s", err, tk.cuiName, tk.v.Name())
+ return false
+ }
+ var ok bool = true
+ if vw0 != tk.gocuiSize.w0 {
+ tk.dumpWidget("verifyRect() err w0")
+ ok = false
+ }
+ if vw1 != tk.gocuiSize.w1 {
+ tk.dumpWidget("verifyRect() err w1")
+ ok = false
+ }
+ if vh0 != tk.gocuiSize.h0 {
+ tk.dumpWidget("verifyRect() err h0")
+ ok = false
+ }
+ if vh1 != tk.gocuiSize.h1 {
+ tk.dumpWidget("verifyRect() err h1")
+ ok = false
+ }
+ if !ok {
+ log.Info("verifyRect() NEED TO FIX RECT HERE", tk.cuiName)
+ tk.dumpWidget("verifyRect() FIXME")
+ }
+ log.Printf("verifyRect() OK cuiName=%s v.Name=%s", tk.cuiName, tk.v.Name())
+ return true
+}
+
+func (tk *guiWidget) makeTK(ddItems []string) {
+ items := strings.Join(ddItems, "\n")
+ var err error
+ tk.labelN = items
+ tk.SetText(items)
+ tk.gocuiSize.w0 = 100
+ tk.gocuiSize.w1 = 120
+ tk.gocuiSize.h0 = 15
+ tk.gocuiSize.h1 = 18
+ tk.v, err = me.baseGui.SetView(tk.cuiName,
+ tk.gocuiSize.w0,
+ tk.gocuiSize.h0,
+ tk.gocuiSize.w1,
+ tk.gocuiSize.h1, 0)
+ if err != nil {
+ log.Info("makeTK() err", err)
+ return
+ }
+ if tk.v == nil {
+ return
+ }
+ tk.v.Wrap = true
+ tk.v.Frame = true
+ tk.v.Clear()
+ fmt.Fprint(tk.v, items)
+ tk.Show()
+}
+
+func addDropdown() *tree.Node {
+ return addDropdownNew(-222)
+}
+
+var notsure *guiWidget
+
// use this to test code ideas
func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got keypress 2. now what?")
// closes anything under your mouse
w, h := g.MousePosition()
- for _, tk := range findByXY(w, h) {
- if tk.node.WidgetType == widget.Stdout {
- tk.dumpWidget("theNotsure() DrawAt STDOUT")
- tk.DrawAt(10, 10)
- if wtf {
- log.Log(GOCUI, "set visible false")
- tk.deleteView()
- // tk.SetVisible(false)
- wtf = false
- } else {
- log.Log(GOCUI, "set visible true")
- tk.drawView()
- // tk.SetVisible(true)
- wtf = true
- }
- continue
- }
+ if notsure == nil {
+ // notsure = makeDropdownView("addWidget() notsure")
+ notsure = addDropdownTK(-118)
+ notsure.makeTK([]string{"apple", "pear"})
}
+ notsure.MoveToOffset(w+10, h+10)
+ // notsure.SetText("theNotsure")
+ notsure.drawView()
+ notsure.Show()
- /* closes anything under your mouse
- w, h := g.MousePosition()
for _, tk := range findByXY(w, h) {
+ // vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
+ log.Log(GOCUI, "verify rect:", tk.v.Name())
+ tk.verifyRect()
+
if tk.node.WidgetType == widget.Stdout {
- tk.dumpWidget("theNotsure() SKIP STDOUT")
- continue
}
- tk.dumpWidget("theNotsure() HIDDING")
- tk.Hide()
}
- */
return nil
}
@@ -159,7 +216,9 @@ func openDebuggger(g *gocui.Gui, v *gocui.View) error {
func theFind(g *gocui.Gui, v *gocui.View) error {
w, h := g.MousePosition()
for _, tk := range findByXY(w, h) {
+ // tk.v.BgColor = gocui.ColorGreen
tk.dumpWidget("theFind()")
+ tk.verifyRect()
}
return nil
}