dropdown & combobox's pop up

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-01 21:47:31 -06:00
parent 13b0daed7c
commit dddef229dc
5 changed files with 53 additions and 38 deletions

5
add.go
View File

@ -49,6 +49,11 @@ func addWidget(n *tree.Node) {
nw.color = &colorWindow
wRoot := me.treeRoot.TK.(*guiWidget)
wRoot.redoWindows(0, 0)
// TODO: record the first window here?
// do initial setup of helper widgets here:
if me.ddview == nil {
me.ddview = makeDropdownView("addWidget() ddview")
}
return
case widget.Tab:
nw.color = &colorTab

View File

@ -198,9 +198,11 @@ func (w *guiWidget) doWidgetClick() {
log.Log(NOW, "ddItem:", w.String(), i, s)
ddItems += s + "\n"
}
/*
if me.ddview == nil {
me.ddview = makeDropdownView(ddItems)
}
*/
showDropdownItems(ddItems)
me.ddNode = w.node
/*

View File

@ -155,12 +155,13 @@ func showDDview() error {
return nil
}
/*
// if there is a drop down view active, treat it like a dialog box and close it
if (hideDDview() == nil) {
return nil
}
*/
/*
// if there is a drop down view active, treat it like a dialog box and close it
if (hideDDview() == nil) {
return nil
}
*/
func (w *guiWidget) dropdownClicked(mouseW, mouseH int) {
log.Log(NOW, "dropdownClicked() (w,h) =", mouseW, mouseH)
w.SetVisible(false)

View File

@ -12,35 +12,6 @@ import (
"go.wit.com/log"
)
// This initializes the gocui package
// it runs SetManagerFunc which passes every input
// event (keyboard, mouse, etc) to the function "gocuiEvent()"
func gocuiMain() {
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
panic(err)
}
defer g.Close()
me.baseGui = g
g.Cursor = true
g.Mouse = true
// this sets the function that is run on every event. For example:
// When you click the mouse, move the mouse, or press a key on the keyboard
// This is equivalent to xev or similar to cat /dev/input on linux
g.SetManagerFunc(gocuiEvent)
if err := defaultKeybindings(g); err != nil {
panic(err)
}
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
panic(err)
}
}
// Thanks to the gocui developers -- your package kicks ass
// This function is called on every event. It is a callback function from the gocui package
// which has an excellent implementation. While gocui handles things like text highlighting

42
main.go
View File

@ -5,9 +5,11 @@
package main
import (
"errors"
"os"
"runtime/debug"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
)
@ -75,14 +77,19 @@ func mainGogui() {
log.Warn("YAHOOOO Recovered in guiMain application:", r)
log.Warn("Recovered from panic:", r)
me.baseGui.Close()
log.Sleep(3)
// allow gocui to close if possible, then print stack
log.Sleep(1)
os.Stdout = origStdout
os.Stderr = origStderr
me.myTree.SendToolkitPanic()
log.Warn("Stack trace:")
debug.PrintStack()
panic("BUMMER")
// attempt to switch to the nocui toolkit
log.Sleep(1)
me.myTree.SendToolkitLoad("nocui")
// panic("BUMMER")
return
}
}()
@ -106,3 +113,32 @@ func mainGogui() {
os.Stderr = ferr
gocuiMain()
}
// This initializes the gocui package
// it runs SetManagerFunc which passes every input
// event (keyboard, mouse, etc) to the function "gocuiEvent()"
func gocuiMain() {
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
panic(err)
}
defer g.Close()
me.baseGui = g
g.Cursor = true
g.Mouse = true
// this sets the function that is run on every event. For example:
// When you click the mouse, move the mouse, or press a key on the keyboard
// This is equivalent to xev or similar to cat /dev/input on linux
g.SetManagerFunc(gocuiEvent)
if err := defaultKeybindings(g); err != nil {
panic(err)
}
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
panic(err)
}
}