textbox kinda works
This commit is contained in:
parent
e96cb4375c
commit
5668e6f081
38
dropdown.go
38
dropdown.go
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
// simulates a dropdown menu in gocui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -12,18 +14,8 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
// simulates a dropdown menu in gocui
|
// create a new widget in the binary tree
|
||||||
|
func makeNewFlagWidget(wId int) *guiWidget {
|
||||||
/*
|
|
||||||
func addInternalTK(wId int) *guiWidget {
|
|
||||||
n := addDropdownNew(wId)
|
|
||||||
tk := n.TK.(*guiWidget)
|
|
||||||
tk.internal = true
|
|
||||||
return tk
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func addInternalTK(wId int) *guiWidget {
|
|
||||||
n := new(tree.Node)
|
n := new(tree.Node)
|
||||||
n.WidgetType = widget.Flag
|
n.WidgetType = widget.Flag
|
||||||
n.WidgetId = wId
|
n.WidgetId = wId
|
||||||
|
@ -46,20 +38,19 @@ func addInternalTK(wId int) *guiWidget {
|
||||||
// add this new widget on the binary tree
|
// add this new widget on the binary tree
|
||||||
tk.parent = me.treeRoot.TK.(*guiWidget)
|
tk.parent = me.treeRoot.TK.(*guiWidget)
|
||||||
if tk.parent == nil {
|
if tk.parent == nil {
|
||||||
panic("addInternalNode() didn't get treeRoot guiWidget")
|
panic("makeNewFlagWidget() didn't get treeRoot guiWidget")
|
||||||
} else {
|
} else {
|
||||||
tk.parent.children = append(tk.parent.children, tk)
|
tk.parent.children = append(tk.parent.children, tk)
|
||||||
}
|
}
|
||||||
|
|
||||||
n.TK = tk
|
n.TK = tk
|
||||||
tk.internal = true
|
|
||||||
return tk
|
return tk
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tk *guiWidget) showDropdown() {
|
func (tk *guiWidget) showDropdown() {
|
||||||
if me.dropdown.tk == nil {
|
if me.dropdown.tk == nil {
|
||||||
// should only happen once
|
// should only happen once
|
||||||
me.dropdown.tk = addInternalTK(me.dropdown.wId)
|
me.dropdown.tk = makeNewFlagWidget(me.dropdown.wId)
|
||||||
me.dropdown.tk.dumpWidget("init() dropdown")
|
me.dropdown.tk.dumpWidget("init() dropdown")
|
||||||
}
|
}
|
||||||
if me.dropdown.tk == nil {
|
if me.dropdown.tk == nil {
|
||||||
|
@ -135,7 +126,7 @@ func dropdownUnclicked(w, h int) {
|
||||||
func (tk *guiWidget) showTextbox() {
|
func (tk *guiWidget) showTextbox() {
|
||||||
if me.textbox.tk == nil {
|
if me.textbox.tk == nil {
|
||||||
// should only happen once
|
// should only happen once
|
||||||
me.textbox.tk = addInternalTK(me.textbox.wId)
|
me.textbox.tk = makeNewFlagWidget(me.textbox.wId)
|
||||||
me.dropdown.tk.dumpWidget("init() textbox")
|
me.dropdown.tk.dumpWidget("init() textbox")
|
||||||
}
|
}
|
||||||
if me.textbox.tk == nil {
|
if me.textbox.tk == nil {
|
||||||
|
@ -151,3 +142,18 @@ func (tk *guiWidget) showTextbox() {
|
||||||
me.textbox.callerTK = tk
|
me.textbox.callerTK = tk
|
||||||
me.textbox.tk.dumpWidget("showTextbox()")
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -50,7 +50,20 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Info("never found dropdown at", w, h)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ func mouseMove(g *gocui.Gui) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if me.globalMouseDown && me.dropdown.active {
|
if me.globalMouseDown && (me.dropdown.active || me.textbox.active) {
|
||||||
log.Info("can't drag while dropdown is active", w, h)
|
log.Info("can't drag while dropdown or textbox are active", w, h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,7 @@ func (w *guiWidget) simpleDrawAt(offsetW, offsetH int) {
|
||||||
w.dumpWidget("simpleDrawAt()")
|
w.dumpWidget("simpleDrawAt()")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
var toggle bool = true
|
var toggle bool = true
|
||||||
|
|
||||||
func (w *guiWidget) toggleTree() {
|
func (w *guiWidget) toggleTree() {
|
||||||
|
@ -113,6 +114,7 @@ func (w *guiWidget) toggleTree() {
|
||||||
toggle = true
|
toggle = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// display the widgets in the binary tree
|
// display the widgets in the binary tree
|
||||||
func (w *guiWidget) drawTree(draw bool) {
|
func (w *guiWidget) drawTree(draw bool) {
|
||||||
|
|
Loading…
Reference in New Issue