finally can drag something else

This commit is contained in:
Jeff Carr 2025-02-02 23:36:33 -06:00
parent 517d844b3c
commit a5b3a934d2
4 changed files with 123 additions and 34 deletions

View File

@ -39,8 +39,13 @@ func (w *guiWidget) dumpWidget(s string) {
if w.Visible() {
s1 += fmt.Sprintf("gocui=(%3d,%3d,%3d,%3d)",
w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
// vx0, vy0, vx1, vy1, _ := me.baseGui.ViewPosition("msg")
vx0, vy0, vx1, vy1, _ := me.baseGui.ViewPosition(w.cuiName)
s1 += fmt.Sprintf(" real=(%3d,%3d,%3d,%3d)",
vx0, vy0, vx1, vy1)
} else {
s1 += fmt.Sprintf(" %3s %3s %3s %3s ", "", "", "", "")
s1 += fmt.Sprintf(" %3s %3s %3s %3s ", "", "", "", "")
}
if w.node.Parent != nil {
if w.node.Parent.WidgetType == widget.Grid {

View File

@ -48,10 +48,15 @@ func makeDropdownView(ddItems string) *guiWidget {
return tk
}
func addDropdown() *tree.Node {
func addDropdownTK(wId int) *guiWidget {
n := addDropdownNew(wId)
return n.TK.(*guiWidget)
}
func addDropdownNew(wId int) *tree.Node {
n := new(tree.Node)
n.WidgetType = widget.Flag
n.WidgetId = -222
n.WidgetId = wId
n.ParentId = 0
// store the internal toolkit information
@ -64,7 +69,7 @@ func addDropdown() *tree.Node {
tk.node.State.Label = "DropBox"
// set the name used by gocui to the id
tk.cuiName = "-1 DR"
tk.cuiName = fmt.Sprintf("%d DR", wId)
tk.color = &colorFlag

View File

@ -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
}

View File

@ -19,6 +19,8 @@ import (
"go.wit.com/widget"
)
var currentDrag *guiWidget
// this function uses the mouse position to highlight & unhighlight things
// this is run every time the user moves the mouse over the terminal window
func mouseMove(g *gocui.Gui) {
@ -38,13 +40,26 @@ func mouseMove(g *gocui.Gui) {
// plugin will segfault if you don't keep this inside a check for msgMouseDown
// don't move this code out of here
var found bool = false
if currentDrag != nil {
currentDrag.moveNew(g)
return
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Flag {
currentDrag = tk
// tk.moveNew(g)
return
}
}
for _, tk := range findByXY(w, h) {
if tk.node.WidgetType == widget.Stdout {
tk.moveNew(g)
// currentDrag = tk
// tk.moveNew(g)
return
}
if tk.node.WidgetType == widget.Label {
tk.moveNew(g)
currentDrag = tk
// tk.moveNew(g)
return
}
found = true
@ -72,15 +87,20 @@ func mouseMove(g *gocui.Gui) {
// this is how the window gets dragged around
func (tk *guiWidget) moveNew(g *gocui.Gui) {
w, h := g.MousePosition()
if tk.node.WidgetType == widget.Label {
if tk.node.WidgetType == widget.Flag {
log.Info("MOVE FLAG")
log.Info("MOVE FLAG")
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
tk.dumpWidget(s)
outputW, outputH := tk.Size()
g.SetView(tk.cuiName, w-xOffset, h-yOffset, w-xOffset+outputW, h-yOffset+outputH+me.FramePadH, 0)
g.SetView(tk.cuiName, w-xOffset, h-yOffset, w-xOffset+outputW+20, h-yOffset+outputH+me.FramePadH+20, 0)
me.startOutputW = w - xOffset
me.startOutputH = h - yOffset
// g.SetViewOnBottom(tk.cuiName)
return
} else {
log.Info("NOT MOVE FLAG", tk.node.WidgetType)
log.Info("NOT MOVE FLAG", tk.node.WidgetType)
}
tk.dumpWidget("moveNew() on " + tk.cuiName)
outputW := 140