textbox kinda works

This commit is contained in:
Jeff Carr 2025-02-07 00:35:08 -06:00
parent e96cb4375c
commit 5668e6f081
4 changed files with 40 additions and 19 deletions

View File

@ -3,6 +3,8 @@
package main
// simulates a dropdown menu in gocui
import (
"fmt"
"strings"
@ -12,18 +14,8 @@ import (
"go.wit.com/widget"
)
// simulates a dropdown menu in gocui
/*
func addInternalTK(wId int) *guiWidget {
n := addDropdownNew(wId)
tk := n.TK.(*guiWidget)
tk.internal = true
return tk
}
*/
func addInternalTK(wId int) *guiWidget {
// create a new widget in the binary tree
func makeNewFlagWidget(wId int) *guiWidget {
n := new(tree.Node)
n.WidgetType = widget.Flag
n.WidgetId = wId
@ -46,20 +38,19 @@ func addInternalTK(wId int) *guiWidget {
// add this new widget on the binary tree
tk.parent = me.treeRoot.TK.(*guiWidget)
if tk.parent == nil {
panic("addInternalNode() didn't get treeRoot guiWidget")
panic("makeNewFlagWidget() didn't get treeRoot guiWidget")
} else {
tk.parent.children = append(tk.parent.children, tk)
}
n.TK = tk
tk.internal = true
return tk
}
func (tk *guiWidget) showDropdown() {
if me.dropdown.tk == nil {
// should only happen once
me.dropdown.tk = addInternalTK(me.dropdown.wId)
me.dropdown.tk = makeNewFlagWidget(me.dropdown.wId)
me.dropdown.tk.dumpWidget("init() dropdown")
}
if me.dropdown.tk == nil {
@ -135,7 +126,7 @@ func dropdownUnclicked(w, h int) {
func (tk *guiWidget) showTextbox() {
if me.textbox.tk == nil {
// should only happen once
me.textbox.tk = addInternalTK(me.textbox.wId)
me.textbox.tk = makeNewFlagWidget(me.textbox.wId)
me.dropdown.tk.dumpWidget("init() textbox")
}
if me.textbox.tk == nil {
@ -151,3 +142,18 @@ func (tk *guiWidget) showTextbox() {
me.textbox.callerTK = tk
me.textbox.tk.dumpWidget("showTextbox()")
}
// updates the text and sends an event back to the application
func (tk *guiWidget) textboxClosed() {
tk.Hide()
// get the text the user entered
newname := tk.GetText()
// change the text of the caller widget
me.textbox.callerTK.SetText(newname)
me.textbox.callerTK.node.SetCurrentS(newname)
// send an event from the plugin with the new string
me.myTree.SendUserEvent(me.textbox.callerTK.node)
}

View File

@ -50,7 +50,20 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
}
}
log.Info("never found dropdown at", w, h)
// me.dropdown.active = false
return nil
}
// if the textbox is active, never do anything else
if me.textbox.active {
log.Info("mouseDown() stopping here. textbox widget is open")
for _, tk := range findByXY(w, h) {
if (tk.node.WidgetType == widget.Flag) && (tk == me.textbox.tk) {
me.textbox.active = false
tk.textboxClosed()
return nil
}
}
log.Info("never found textbox at", w, h)
return nil
}

View File

@ -47,8 +47,8 @@ func mouseMove(g *gocui.Gui) {
return
}
if me.globalMouseDown && me.dropdown.active {
log.Info("can't drag while dropdown is active", w, h)
if me.globalMouseDown && (me.dropdown.active || me.textbox.active) {
log.Info("can't drag while dropdown or textbox are active", w, h)
return
}

View File

@ -102,6 +102,7 @@ func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) {
w.dumpWidget("simpleDrawAt()")
}
/*
var toggle bool = true
func (w *guiWidget) toggleTree() {
@ -113,6 +114,7 @@ func (w *guiWidget) toggleTree() {
toggle = true
}
}
*/
// display the widgets in the binary tree
func (w *guiWidget) drawTree(draw bool) {