crippled, but works

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-02-02 11:47:32 -06:00
parent d6f1a45c77
commit d4c2f8cb1b
5 changed files with 85 additions and 48 deletions

View File

@ -88,19 +88,6 @@ func (tk *guiWidget) showDropdown() {
} }
} }
func dropdownClicked(mouseX, mouseH int) {
tk := me.dropdownV
if tk.Visible() {
log.Log(NOW, "hide DDview() Mouse really down at:", mouseX, mouseH)
hideDDview()
} else {
log.Log(NOW, "show DDview() Mouse really down at:", mouseX, mouseH)
log.Log(NOW, "can you see the dropdown menu right now?")
log.Log(NOW, "if so, something is wrong. I think you can't see it")
showDDview()
}
}
func hideDDview() error { func hideDDview() error {
w, h := me.baseGui.MousePosition() w, h := me.baseGui.MousePosition()
log.Log(NOW, "hide dropdown menu() view msgMouseDown (w,h) =", w, h) log.Log(NOW, "hide dropdown menu() view msgMouseDown (w,h) =", w, h)
@ -127,18 +114,26 @@ func showDDview() error {
return nil return nil
} }
/*
// if there is a drop down view active, treat it like a dialog box and close it // 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) { func (w *guiWidget) dropdownClicked(mouseW, mouseH int) {
log.Log(NOW, "dropdownClicked() (w,h) =", mouseW, mouseH) log.Log(NOW, "dropdownClicked() (w,h) =", mouseW, mouseH)
w.SetVisible(false) w.deleteView()
/*
tk := me.dropdownV
if tk.Visible() {
log.Log(NOW, "hide DDview() Mouse really down at:", mouseX, mouseH)
// hideDDview()
} else {
log.Log(NOW, "show DDview() Mouse really down at:", mouseX, mouseH)
log.Log(NOW, "can you see the dropdown menu right now?")
log.Log(NOW, "if so, something is wrong. I think you can't see it")
showDDview()
}
*/
} }
func dropdownUnclicked(mouseX, mouseH int) { func dropdownUnclicked(mouseX, mouseH int) {
tk := me.dropdownV tk := me.dropdownV
log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH) log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH)

28
main.go
View File

@ -118,9 +118,31 @@ func mainGogui() {
// it runs SetManagerFunc which passes every input // it runs SetManagerFunc which passes every input
// event (keyboard, mouse, etc) to the function "gocuiEvent()" // event (keyboard, mouse, etc) to the function "gocuiEvent()"
func gocuiMain() { func gocuiMain() {
defer func() {
if r := recover(); r != nil {
log.Warn("YAHOOOO Recovered in gocuiMain()", r)
log.Warn("Recovered from panic:", r)
me.baseGui.Close()
panic("BUMMER 2")
// 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()
// attempt to switch to the nocui toolkit
log.Sleep(1)
me.myTree.SendToolkitLoad("nocui")
// panic("BUMMER")
return
}
}()
g, err := gocui.NewGui(gocui.OutputNormal, true) g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil { if err != nil {
panic(err) return
} }
defer g.Close() defer g.Close()
@ -135,10 +157,10 @@ func gocuiMain() {
g.SetManagerFunc(gocuiEvent) g.SetManagerFunc(gocuiEvent)
if err := defaultKeybindings(g); err != nil { if err := defaultKeybindings(g); err != nil {
panic(err) // normally panic here
} }
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) { if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
panic(err) // normally panic here
} }
} }

View File

@ -66,7 +66,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
maxX, _ := g.Size() maxX, _ := g.Size()
findUnderMouse() findUnderMouse()
msg := fmt.Sprintf("mouseDown() Mouse really down at: %d,%d", mx, my) msg := fmt.Sprintf("mouseDown() Mouse really down at: %d,%d", mx, my)
dropdownClicked(mx, my) // dropdownClicked(mx, my)
x := mx - len(msg)/2 x := mx - len(msg)/2
if x < 0 { if x < 0 {
x = 0 x = 0

33
view.go
View File

@ -62,32 +62,35 @@ func (w *guiWidget) showView() {
} }
log.Log(INFO, "showView() labelN =", w.labelN) log.Log(INFO, "showView() labelN =", w.labelN)
/*
if w.hidden { if w.hidden {
w.SetVisible(false) w.SetVisible(false)
return return
} }
*/
// if the gocui element doesn't exist, create it if w.v != nil {
if w.v == nil { return
w.recreateView()
} }
w.recreateView()
w.textResize()
w.v.Clear()
fmt.Fprint(w.v, w.labelN)
/*
x0, y0, x1, y1, _ := me.baseGui.ViewPosition(w.cuiName) x0, y0, x1, y1, _ := me.baseGui.ViewPosition(w.cuiName)
// x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName) // x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName)
// log.Log(INFO, "showView() w.v already defined for widget", w.String(), x0, y0, x1, y1, err) // log.Log(INFO, "showView() w.v already defined for widget", w.String(), x0, y0, x1, y1, err)
// n.smartGocuiSize() // n.smartGocuiSize()
changed := w.textResize() // changed := w.textResize()
if !changed { log.Log(INFO, "showView() Clear() and Fprint() here wId =", w.cuiName)
log.Log(INFO, "showView() Clear() and Fprint() here wId =", w.cuiName) w.v.Clear()
w.v.Clear() fmt.Fprint(w.v, w.labelN)
fmt.Fprint(w.v, w.labelN)
w.SetVisible(false)
w.SetVisible(true)
return
}
log.Log(INFO, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) log.Log(INFO, "showView() textResize() changed. Should recreateView here wId =", w.cuiName)
*/
/*
// if the gocui element has changed where it is supposed to be on the screen // if the gocui element has changed where it is supposed to be on the screen
// recreate it // recreate it
if x0 != w.gocuiSize.w0 { if x0 != w.gocuiSize.w0 {
@ -109,8 +112,9 @@ func (w *guiWidget) showView() {
w.recreateView() w.recreateView()
return return
} }
*/
w.SetVisible(true) // w.SetVisible(true)
} }
// create or recreate the gocui widget visible // create or recreate the gocui widget visible
@ -127,6 +131,7 @@ func (w *guiWidget) recreateView() {
me.baseGui.DeleteView(w.cuiName) me.baseGui.DeleteView(w.cuiName)
w.v = nil w.v = nil
w.textResize()
a := w.gocuiSize.w0 a := w.gocuiSize.w0
b := w.gocuiSize.h0 b := w.gocuiSize.h0
c := w.gocuiSize.w1 c := w.gocuiSize.w1

View File

@ -70,11 +70,14 @@ func setupCtrlDownWidget() {
} }
func (w *guiWidget) deleteView() { func (w *guiWidget) deleteView() {
if w.v != nil { /*
w.v.Visible = false if w.v != nil {
return w.v.Visible = false
} return
}
*/
// make sure the view isn't really there // make sure the view isn't really there
log.Log(NOW, "deleteView()", w.cuiName, w.WidgetType, w.node.WidgetId)
me.baseGui.DeleteView(w.cuiName) me.baseGui.DeleteView(w.cuiName)
w.v = nil w.v = nil
} }
@ -103,12 +106,24 @@ func (tk *guiWidget) Visible() bool {
if tk.v == nil { if tk.v == nil {
return false return false
} }
return tk.v.Visible // return tk.v.Visible
tk.v.Visible = true
return true
} }
func (w *guiWidget) SetVisible(b bool) { func (tk *guiWidget) Show() {
if w.v == nil { tk.showView()
return }
}
w.v.Visible = b func (tk *guiWidget) Hide() {
tk.deleteView()
}
func (tk *guiWidget) SetVisible(b bool) {
if b {
tk.Show()
} else {
tk.Hide()
}
// w.v.Visible = b
} }