tab rotates through the windows
This commit is contained in:
parent
87141b8d99
commit
c136ca2b4c
|
@ -35,10 +35,9 @@ func registerHandlers(g *gocui.Gui) {
|
||||||
g.SetKeybinding("", 'H', gocui.ModNone, theHelp) // '?' toggles on and off the help menu
|
g.SetKeybinding("", 'H', gocui.ModNone, theHelp) // '?' toggles on and off the help menu
|
||||||
g.SetKeybinding("", 'O', gocui.ModNone, theStdout) // 'o' toggle the STDOUT window
|
g.SetKeybinding("", 'O', gocui.ModNone, theStdout) // 'o' toggle the STDOUT window
|
||||||
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
|
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
|
||||||
|
g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, tabCycleWindows) // '2' use this to test new ideas
|
||||||
|
|
||||||
// debugging
|
// debugging
|
||||||
g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, theNotsure) // '2' use this to test new ideas
|
|
||||||
g.SetKeybinding("", gocui.KeyTab, gocui.ModShift, theNotsure) // '2' use this to test new ideas
|
|
||||||
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' use this to test new ideas
|
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' use this to test new ideas
|
||||||
g.SetKeybinding("", 'S', gocui.ModNone, theSuperMouse) // 'S' Super Mouse mode!
|
g.SetKeybinding("", 'S', gocui.ModNone, theSuperMouse) // 'S' Super Mouse mode!
|
||||||
g.SetKeybinding("", 'M', gocui.ModNone, printWidgetPlacements) // 'M' list all widgets with positions
|
g.SetKeybinding("", 'M', gocui.ModNone, printWidgetPlacements) // 'M' list all widgets with positions
|
||||||
|
@ -93,12 +92,60 @@ func addDropdown() *tree.Node {
|
||||||
return addDropdownNew(-222)
|
return addDropdownNew(-222)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findNextWindow() *guiWidget {
|
||||||
|
var found bool
|
||||||
|
if len(me.allwin) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, win := range me.allwin {
|
||||||
|
if win.activeWindow {
|
||||||
|
found = true
|
||||||
|
win.activeWindow = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if found {
|
||||||
|
win.activeWindow = true
|
||||||
|
return win
|
||||||
|
}
|
||||||
|
}
|
||||||
|
me.allwin[0].activeWindow = true
|
||||||
|
// at the end, loop to the beginning
|
||||||
|
return me.allwin[0]
|
||||||
|
}
|
||||||
|
|
||||||
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
||||||
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||||
log.Info("got keypress 2. now what?")
|
log.Info("got keypress 2. now what?")
|
||||||
log.Info("try to switch windows here")
|
log.Info("try to switch windows here")
|
||||||
// w, h := g.MousePosition()
|
if len(me.allwin) != len(findWindows()) {
|
||||||
// me.newWindowTrigger <- true
|
me.allwin = findWindows()
|
||||||
|
}
|
||||||
|
newwin := findNextWindow()
|
||||||
|
for i, win := range me.allwin {
|
||||||
|
log.Info("Window", i, "named", win.labelN, win.activeWindow)
|
||||||
|
}
|
||||||
|
if newwin == nil {
|
||||||
|
log.Info("findNextWindow() err. returned nil")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
newwin.doWidgetClick(newwin.gocuiSize.w0, newwin.gocuiSize.h0)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
log.Info("try to switch windows here")
|
||||||
|
if len(me.allwin) != len(findWindows()) {
|
||||||
|
me.allwin = findWindows()
|
||||||
|
}
|
||||||
|
newwin := findNextWindow()
|
||||||
|
for i, win := range me.allwin {
|
||||||
|
log.Info("Window", i, "named", win.labelN, win.activeWindow)
|
||||||
|
}
|
||||||
|
if newwin == nil {
|
||||||
|
log.Info("findNextWindow() err. returned nil")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
newwin.doWidgetClick(newwin.gocuiSize.w0, newwin.gocuiSize.h0)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
|
@ -74,6 +73,11 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
tk.doWidgetClick(w, h)
|
tk.doWidgetClick(w, h)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if tk.node.WidgetType == widget.Textbox {
|
||||||
|
log.Info("SENDING CLICK TO Textbox")
|
||||||
|
tk.doWidgetClick(w, h)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,37 +113,13 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
log.Log(GOCUI, fmt.Sprintf("mouseDown() found nothing at (%d,%d)", mx, my))
|
log.Log(GOCUI, fmt.Sprintf("mouseDown() found nothing at (%d,%d)", mx, my))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sort this junk out
|
||||||
vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
|
vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
||||||
return msgDown(g, v)
|
return msgDown(g, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maxX, _ := g.Size()
|
|
||||||
|
|
||||||
// why was this here?
|
|
||||||
// findUnderMouse()
|
|
||||||
|
|
||||||
// TODO: USE THIS TO MAKE TEMPORARY HELP / INSTRUCTION DIALOGS
|
|
||||||
|
|
||||||
// this message will pop up when you click on the magic thing
|
|
||||||
// figure out how this works and make it generically useful.
|
|
||||||
msg := fmt.Sprintf("This is -222 widget demo. %d,%d", mx, my)
|
|
||||||
// dropdownClicked(mx, my)
|
|
||||||
x := mx - len(msg)/2
|
|
||||||
if x < 0 {
|
|
||||||
x = 0
|
|
||||||
} else if x+len(msg)+1 > maxX-1 {
|
|
||||||
x = maxX - 1 - len(msg) - 1
|
|
||||||
}
|
|
||||||
log.Log(GOCUI, "mouseDown() about to write out message to 'globalDown' view. msg =", msg)
|
|
||||||
if v, err := g.SetView("globalDown", x, my-1, x+len(msg)+1, my+1, 0); err != nil {
|
|
||||||
if !errors.Is(err, gocui.ErrUnknownView) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.WriteString(msg)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,7 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
// this whole things was impossible to make but it got me where I am now
|
func (tk *guiWidget) doWindowClick(w int, h int) {
|
||||||
// the debugging is way way better now with it being visible in the Stdout window
|
|
||||||
// so now it's possible to redo all this and make it better
|
|
||||||
func (tk *guiWidget) doWidgetClick(w int, h int) {
|
|
||||||
switch tk.node.WidgetType {
|
|
||||||
case widget.Window:
|
|
||||||
// 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)
|
||||||
|
@ -27,7 +22,17 @@ func (tk *guiWidget) doWidgetClick(w int, h int) {
|
||||||
me.currentWindow.isCurrent = true
|
me.currentWindow.isCurrent = true
|
||||||
tk.active = false
|
tk.active = false
|
||||||
|
|
||||||
tk.redrawWindow(w-2, h-2) // TODO: fix these hard coded things with offsets
|
tk.redrawWindow(w, h)
|
||||||
|
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
||||||
|
}
|
||||||
|
|
||||||
|
// this whole things was impossible to make but it got me where I am now
|
||||||
|
// the debugging is way way better now with it being visible in the Stdout window
|
||||||
|
// so now it's possible to redo all this and make it better
|
||||||
|
func (tk *guiWidget) doWidgetClick(w int, h int) {
|
||||||
|
switch tk.node.WidgetType {
|
||||||
|
case widget.Window:
|
||||||
|
tk.doWindowClick(w, h)
|
||||||
return
|
return
|
||||||
case widget.Group:
|
case widget.Group:
|
||||||
/*
|
/*
|
||||||
|
|
12
find.go
12
find.go
|
@ -108,6 +108,18 @@ func (tk *guiWidget) findBG() *guiWidget {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findWindowUnderMouse() *guiWidget {
|
||||||
|
w, h := me.baseGui.MousePosition()
|
||||||
|
|
||||||
|
// if the stdout window is on top, check it first
|
||||||
|
if me.stdout.outputOnTop {
|
||||||
|
if me.stdout.tk.full.inRect(w, h) {
|
||||||
|
return me.stdout.tk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// returns the "highest priority widget under the mouse
|
// returns the "highest priority widget under the mouse
|
||||||
func findUnderMouse() *guiWidget {
|
func findUnderMouse() *guiWidget {
|
||||||
w, h := me.baseGui.MousePosition()
|
w, h := me.baseGui.MousePosition()
|
||||||
|
|
1
help.go
1
help.go
|
@ -30,6 +30,7 @@ var helpText []string = []string{"Help Menu",
|
||||||
"S: super mouse",
|
"S: super mouse",
|
||||||
"M: list all widgets positions",
|
"M: list all widgets positions",
|
||||||
"L: list all widgets in tree",
|
"L: list all widgets in tree",
|
||||||
|
"Tab: toggle through windows",
|
||||||
"q: quit()",
|
"q: quit()",
|
||||||
"",
|
"",
|
||||||
}
|
}
|
||||||
|
|
2
init.go
2
init.go
|
@ -77,7 +77,7 @@ func standardExit() {
|
||||||
log.Log(NOW, "standardExit() send back Quit()")
|
log.Log(NOW, "standardExit() send back Quit()")
|
||||||
// go sendBackQuit() // don't stall here in case the
|
// go sendBackQuit() // don't stall here in case the
|
||||||
// induces a delay in case the callback channel is broken
|
// induces a delay in case the callback channel is broken
|
||||||
log.Sleep(1)
|
time.Sleep(200 * time.Millisecond)
|
||||||
log.Log(NOW, "standardExit() exit()")
|
log.Log(NOW, "standardExit() exit()")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ type config struct {
|
||||||
stdout stdout // information for the STDOUT window
|
stdout stdout // information for the STDOUT window
|
||||||
showDebug bool // todo: move this into config struct
|
showDebug bool // todo: move this into config struct
|
||||||
dropdown dropdown // the dropdown menu
|
dropdown dropdown // the dropdown menu
|
||||||
|
allwin []*guiWidget // for tracking which window is next
|
||||||
}
|
}
|
||||||
|
|
||||||
// settings for the stdout window
|
// settings for the stdout window
|
||||||
|
@ -145,6 +146,7 @@ type guiWidget struct {
|
||||||
color *colorT // what color to use
|
color *colorT // what color to use
|
||||||
resize bool // the window is currently being resized
|
resize bool // the window is currently being resized
|
||||||
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
|
||||||
|
activeWindow bool // means this window is the active one
|
||||||
}
|
}
|
||||||
|
|
||||||
// from the gocui devs:
|
// from the gocui devs:
|
||||||
|
|
|
@ -71,6 +71,11 @@ func addWidget(n *tree.Node) {
|
||||||
case widget.Dropdown:
|
case widget.Dropdown:
|
||||||
nw.color = &colorDropdown
|
nw.color = &colorDropdown
|
||||||
return
|
return
|
||||||
|
case widget.Textbox:
|
||||||
|
n.State.Label = "TEXTBOX"
|
||||||
|
nw.labelN = " " + n.State.Label
|
||||||
|
nw.color = &colorDropdown
|
||||||
|
return
|
||||||
case widget.Combobox:
|
case widget.Combobox:
|
||||||
nw.color = &colorCombobox
|
nw.color = &colorCombobox
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue