disable and enable doesn't crash

This commit is contained in:
Jeff Carr 2025-02-11 13:22:23 -06:00
parent 535646335a
commit 733c595c54
3 changed files with 93 additions and 49 deletions

View File

@ -68,12 +68,13 @@ func (tk *guiWidget) updateColor() {
if tk.v == nil { if tk.v == nil {
return return
} }
if tk.color != nil {
tk.colorLast.frame = tk.color.frame tk.colorLast.frame = tk.color.frame
tk.colorLast.fg = tk.color.fg tk.colorLast.fg = tk.color.fg
tk.colorLast.bg = tk.color.bg tk.colorLast.bg = tk.color.bg
tk.colorLast.selFg = tk.color.selFg tk.colorLast.selFg = tk.color.selFg
tk.colorLast.selBg = tk.color.selBg tk.colorLast.selBg = tk.color.selBg
}
tk.activateColor() tk.activateColor()
} }

View File

@ -7,6 +7,7 @@ import (
// if you include more than just this import // if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27) // then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"github.com/awesome-gocui/gocui"
"go.wit.com/log" "go.wit.com/log"
"go.wit.com/toolkits/tree" "go.wit.com/toolkits/tree"
"go.wit.com/widget" "go.wit.com/widget"
@ -224,6 +225,35 @@ func (tk *guiWidget) Disable() {
log.Log(NOW, "widget is nil") log.Log(NOW, "widget is nil")
return return
} }
initTextbox()
tk.prepTextbox()
r := new(rectType)
r.w0 = 2
r.h0 = 1
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
log.Info("textbox should be shown")
// showTextbox("Running...")
me.textbox.tk.dumpWidget("shown?")
me.textbox.tk.setColorModal()
me.textbox.tk.v.Clear()
me.textbox.tk.v.WriteString("Running...")
me.textbox.tk.v.Editable = true
me.textbox.tk.v.Wrap = true
me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
me.baseGui.SetCurrentView(me.textbox.tk.v.Name())
// bind the enter key to a function so we can close the textbox
me.baseGui.SetKeybinding(me.textbox.tk.v.Name(), gocui.KeyEnter, gocui.ModNone, theCloseTheTextbox)
me.textbox.active = true
/*
tk.enable = false tk.enable = false
tk.node.State.Enable = false tk.node.State.Enable = false
// log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName()) // log.Info("disable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
@ -245,6 +275,7 @@ func (tk *guiWidget) Disable() {
default: default:
tk.dumpWidget("fixme: disable") tk.dumpWidget("fixme: disable")
} }
*/
} }
func (tk *guiWidget) Enable() { func (tk *guiWidget) Enable() {
@ -252,6 +283,13 @@ func (tk *guiWidget) Enable() {
log.Log(NOW, "widget is nil") log.Log(NOW, "widget is nil")
return return
} }
initTextbox()
tk.prepTextbox()
me.textbox.tk.Hide()
/*
initTextbox()
tk.enable = true tk.enable = true
tk.node.State.Enable = true tk.node.State.Enable = true
// log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName()) // log.Info("enable widget in gocui", tk.node.WidgetType, tk.node.ProgName())
@ -268,4 +306,5 @@ func (tk *guiWidget) Enable() {
default: default:
tk.dumpWidget("fixme: enable") tk.dumpWidget("fixme: enable")
} }
*/
} }

View File

@ -29,14 +29,18 @@ func (tk *guiWidget) forceSizes(r *rectType) {
tk.force.h1 = r.h1 tk.force.h1 = r.h1
} }
func (callertk *guiWidget) prepTextbox() { func initTextbox() {
if me.textbox.tk == nil { if me.textbox.tk == nil {
// should only happen once // should only happen once
me.textbox.tk = makeNewFlagWidget(me.textbox.wId) me.textbox.tk = makeNewFlagWidget(me.textbox.wId)
// me.textbox.tk.dumpWidget("init() textbox") // me.textbox.tk.dumpWidget("init() textbox")
} }
}
func (callertk *guiWidget) prepTextbox() {
initTextbox()
if me.textbox.tk == nil { if me.textbox.tk == nil {
log.Log(GOCUI, "showTextbox() Is Broken") log.Log(GOCUI, "prepTextbox() Is Broken")
return return
} }
@ -51,14 +55,14 @@ func (callertk *guiWidget) prepTextbox() {
me.textbox.callerTK = callertk me.textbox.callerTK = callertk
showTextbox(callertk.String()) // showTextbox(callertk.String())
} }
func showTextbox(callertk string) { func showTextbox(callers string) {
// tk := me.textbox.tk // tk := me.textbox.tk
// me.textbox.tk.dumpWidget("after sizes") // me.textbox.tk.dumpWidget("after sizes")
me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this // me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
if me.textbox.tk.v == nil { if me.textbox.tk.v == nil {
log.Info("wtf went wrong") log.Info("wtf went wrong")
@ -67,7 +71,7 @@ func showTextbox(callertk string) {
me.textbox.tk.setColorModal() me.textbox.tk.setColorModal()
me.textbox.tk.v.Clear() me.textbox.tk.v.Clear()
cur := strings.TrimSpace(callertk) cur := strings.TrimSpace(callers)
// log.Info("setting textbox string to:", cur) // log.Info("setting textbox string to:", cur)
me.textbox.tk.v.WriteString(cur) me.textbox.tk.v.WriteString(cur)