diff options
| author | Jeff Carr <[email protected]> | 2025-02-07 00:35:08 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-07 00:35:08 -0600 |
| commit | 5668e6f081453bdffb7d23f9259f01182d131ace (patch) | |
| tree | 27647a21318f35400b92a049bb1a1479e8e4681d /dropdown.go | |
| parent | e96cb4375c9f4ffc45389a9df8c59116710532a4 (diff) | |
textbox kinda works
Diffstat (limited to 'dropdown.go')
| -rw-r--r-- | dropdown.go | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/dropdown.go b/dropdown.go index 4828736..aed5ead 100644 --- a/dropdown.go +++ b/dropdown.go @@ -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) +} |
