tab rotates through the windows
This commit is contained in:
parent
87141b8d99
commit
c136ca2b4c
|
@ -32,13 +32,12 @@ func registerHandlers(g *gocui.Gui) {
|
||||||
g.SetKeybinding("", keyForced, modForced, handle_ctrl_z) // CTRL-Z :cleverly let's you background gocui (breaks cursor mouse on return)
|
g.SetKeybinding("", keyForced, modForced, handle_ctrl_z) // CTRL-Z :cleverly let's you background gocui (breaks cursor mouse on return)
|
||||||
|
|
||||||
// regular keys
|
// regular keys
|
||||||
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,25 +9,30 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (tk *guiWidget) doWindowClick(w int, h int) {
|
||||||
|
// if there is a current window, hide it
|
||||||
|
if me.currentWindow != nil {
|
||||||
|
me.currentWindow.setColor(&colorWindow)
|
||||||
|
// me.currentWindow.hideWidgets()
|
||||||
|
me.currentWindow.isCurrent = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// now set this window as the current window
|
||||||
|
me.currentWindow = tk
|
||||||
|
me.currentWindow.isCurrent = true
|
||||||
|
tk.active = false
|
||||||
|
|
||||||
|
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
|
// 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
|
// 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
|
// so now it's possible to redo all this and make it better
|
||||||
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:
|
||||||
// if there is a current window, hide it
|
tk.doWindowClick(w, h)
|
||||||
if me.currentWindow != nil {
|
|
||||||
me.currentWindow.setColor(&colorWindow)
|
|
||||||
// me.currentWindow.hideWidgets()
|
|
||||||
me.currentWindow.isCurrent = false
|
|
||||||
}
|
|
||||||
|
|
||||||
// now set this window as the current window
|
|
||||||
me.currentWindow = tk
|
|
||||||
me.currentWindow.isCurrent = true
|
|
||||||
tk.active = false
|
|
||||||
|
|
||||||
tk.redrawWindow(w-2, h-2) // TODO: fix these hard coded things with offsets
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
64
structs.go
64
structs.go
|
@ -37,37 +37,38 @@ type config struct {
|
||||||
helpLabel *gocui.View // ?
|
helpLabel *gocui.View // ?
|
||||||
showHelp bool // toggle boolean for the help menu (deprecate?)
|
showHelp bool // toggle boolean for the help menu (deprecate?)
|
||||||
// dropdownW *guiWidget // grab the dropdown choices from this widget
|
// dropdownW *guiWidget // grab the dropdown choices from this widget
|
||||||
FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
|
FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
|
||||||
FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
|
FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
|
||||||
PadW int `default:"1" dense:"0"` // pad spacing
|
PadW int `default:"1" dense:"0"` // pad spacing
|
||||||
PadH int `default:"1" dense:"0"` // pad spacing
|
PadH int `default:"1" dense:"0"` // pad spacing
|
||||||
WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings
|
WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings
|
||||||
WindowH int `default:"-1"` // how far down to start Window or Tab headings
|
WindowH int `default:"-1"` // how far down to start Window or Tab headings
|
||||||
TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings
|
TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings
|
||||||
TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings
|
TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings
|
||||||
WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets
|
WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets
|
||||||
TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets
|
TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets
|
||||||
GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group
|
GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group
|
||||||
BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box
|
BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box
|
||||||
GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid
|
GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid
|
||||||
RawW int `default:"1"` // the raw beginning of each window (or tab)
|
RawW int `default:"1"` // the raw beginning of each window (or tab)
|
||||||
RawH int `default:"5"` // the raw beginning of each window (or tab)
|
RawH int `default:"5"` // the raw beginning of each window (or tab)
|
||||||
FakeW int `default:"20"` // offset for the hidden widgets
|
FakeW int `default:"20"` // offset for the hidden widgets
|
||||||
padded bool // add space between things like buttons
|
padded bool // add space between things like buttons
|
||||||
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
|
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
|
||||||
canvas bool // if set to true, the windows are a raw canvas
|
canvas bool // if set to true, the windows are a raw canvas
|
||||||
menubar bool // for windows
|
menubar bool // for windows
|
||||||
stretchy bool // expand things like buttons to the maximum size
|
stretchy bool // expand things like buttons to the maximum size
|
||||||
margin bool // add space around the frames of windows
|
margin bool // add space around the frames of windows
|
||||||
writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe)
|
writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe)
|
||||||
ecount int // counts how many mouse and keyboard events have occurred
|
ecount int // counts how many mouse and keyboard events have occurred
|
||||||
supermouse bool // prints out every widget found while you move the mouse around
|
supermouse bool // prints out every widget found while you move the mouse around
|
||||||
depth int // used for listWidgets() debugging
|
depth int // used for listWidgets() debugging
|
||||||
globalMouseDown bool // yep, mouse is pressed
|
globalMouseDown bool // yep, mouse is pressed
|
||||||
newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow()
|
newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow()
|
||||||
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