code cleanups
This commit is contained in:
parent
c2f8cac4a9
commit
e96cb4375c
83
dropdown.go
83
dropdown.go
|
@ -12,50 +12,18 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
// dropdowns don't exist so this is an attempt to pretend they exist
|
// simulates a dropdown menu in gocui
|
||||||
// by having a fake window view in gocui that appears with the dropdown
|
|
||||||
// items. by detecting where the user clicks, we should be
|
|
||||||
// able to set the text of the button to that value (and
|
|
||||||
// rezise it.
|
|
||||||
|
|
||||||
// the thing is this is so damned complicated because it
|
|
||||||
// is very hard to debug this. thanks to the floating on
|
|
||||||
// screen debugging output I might be able to figure it
|
|
||||||
// it out now. maybe. notsure.
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func makeDropdownView(ddItems string) *guiWidget {
|
func addInternalTK(wId int) *guiWidget {
|
||||||
newNode := addDropdown()
|
n := addDropdownNew(wId)
|
||||||
tk := newNode.TK.(*guiWidget)
|
tk := n.TK.(*guiWidget)
|
||||||
tk.labelN = ddItems
|
tk.internal = true
|
||||||
tk.SetText(ddItems)
|
|
||||||
tk.gocuiSize.w0 = 100
|
|
||||||
tk.gocuiSize.w1 = 120
|
|
||||||
tk.gocuiSize.h0 = 15
|
|
||||||
tk.gocuiSize.h1 = 18
|
|
||||||
tk.v, _ = me.baseGui.SetView("ddview",
|
|
||||||
tk.gocuiSize.w0,
|
|
||||||
tk.gocuiSize.h0,
|
|
||||||
tk.gocuiSize.w1,
|
|
||||||
tk.gocuiSize.h1, 0)
|
|
||||||
if tk.v == nil {
|
|
||||||
return tk
|
|
||||||
}
|
|
||||||
tk.v.Wrap = true
|
|
||||||
tk.v.Frame = true
|
|
||||||
tk.v.Clear()
|
|
||||||
fmt.Fprint(tk.v, ddItems)
|
|
||||||
tk.Show()
|
|
||||||
return tk
|
return tk
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func addDropdownTK(wId int) *guiWidget {
|
func addInternalTK(wId int) *guiWidget {
|
||||||
n := addDropdownNew(wId)
|
|
||||||
return n.TK.(*guiWidget)
|
|
||||||
}
|
|
||||||
|
|
||||||
func addDropdownNew(wId int) *tree.Node {
|
|
||||||
n := new(tree.Node)
|
n := new(tree.Node)
|
||||||
n.WidgetType = widget.Flag
|
n.WidgetType = widget.Flag
|
||||||
n.WidgetId = wId
|
n.WidgetId = wId
|
||||||
|
@ -64,14 +32,11 @@ func addDropdownNew(wId int) *tree.Node {
|
||||||
// store the internal toolkit information
|
// store the internal toolkit information
|
||||||
tk := new(guiWidget)
|
tk := new(guiWidget)
|
||||||
tk.frame = true
|
tk.frame = true
|
||||||
tk.labelN = "DropBox text"
|
|
||||||
|
|
||||||
tk.node = n
|
tk.node = n
|
||||||
if tk.node.Parent == nil {
|
if tk.node.Parent == nil {
|
||||||
tk.node.Parent = me.treeRoot
|
tk.node.Parent = me.treeRoot
|
||||||
}
|
}
|
||||||
// copy the data from the action message
|
|
||||||
tk.node.State.Label = "DropBox"
|
|
||||||
|
|
||||||
// set the name used by gocui to the id
|
// set the name used by gocui to the id
|
||||||
tk.cuiName = fmt.Sprintf("%d DR", wId)
|
tk.cuiName = fmt.Sprintf("%d DR", wId)
|
||||||
|
@ -81,39 +46,44 @@ func addDropdownNew(wId int) *tree.Node {
|
||||||
// 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("addDropdown() didn't get treeRoot guiWidget")
|
panic("addInternalNode() 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
|
||||||
return n
|
tk.internal = true
|
||||||
|
return tk
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tk *guiWidget) showDropdown() {
|
func (tk *guiWidget) showDropdown() {
|
||||||
|
if me.dropdown.tk == nil {
|
||||||
|
// should only happen once
|
||||||
|
me.dropdown.tk = addInternalTK(me.dropdown.wId)
|
||||||
|
me.dropdown.tk.dumpWidget("init() dropdown")
|
||||||
|
}
|
||||||
|
if me.dropdown.tk == nil {
|
||||||
|
log.Log(GOCUI, "showDropdown() Is Broken!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// todo: fix this after switching to protobuf
|
// todo: fix this after switching to protobuf
|
||||||
me.dropdown.items = []string{} // zero out whatever was there before
|
me.dropdown.items = []string{} // zero out whatever was there before
|
||||||
for i, s := range tk.node.Strings() {
|
for i, s := range tk.node.Strings() {
|
||||||
log.Log(GOCUI, "showDropdown()", tk.String(), i, s)
|
log.Log(GOCUI, "showDropdown()", tk.String(), i, s)
|
||||||
me.dropdown.items = append(me.dropdown.items, s)
|
me.dropdown.items = append(me.dropdown.items, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Log(GOCUI, "new dropdown items should be set to:", me.dropdown.items)
|
log.Log(GOCUI, "new dropdown items should be set to:", me.dropdown.items)
|
||||||
|
|
||||||
if me.dropdown.tk == nil {
|
|
||||||
me.dropdown.tk = addDropdownTK(me.dropdown.wId)
|
|
||||||
}
|
|
||||||
if me.dropdown.tk == nil {
|
|
||||||
log.Log(GOCUI, "showDropdown() IS BROKEN")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
startW, startH := tk.Position()
|
startW, startH := tk.Position()
|
||||||
log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH)
|
log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH)
|
||||||
|
me.dropdown.tk.Hide()
|
||||||
me.dropdown.tk.MoveToOffset(startW+3, startH+2)
|
me.dropdown.tk.MoveToOffset(startW+3, startH+2)
|
||||||
me.dropdown.tk.labelN = strings.Join(me.dropdown.items, "\n")
|
me.dropdown.tk.labelN = strings.Join(me.dropdown.items, "\n")
|
||||||
me.dropdown.tk.Show()
|
me.dropdown.tk.Show()
|
||||||
me.dropdown.active = true
|
me.dropdown.active = true
|
||||||
me.dropdown.callerTK = tk
|
me.dropdown.callerTK = tk
|
||||||
|
me.dropdown.tk.dumpWidget("showDropdown()")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -163,20 +133,21 @@ func dropdownUnclicked(w, h int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tk *guiWidget) showTextbox() {
|
func (tk *guiWidget) showTextbox() {
|
||||||
// todo: fix this after switching to protobuf
|
|
||||||
|
|
||||||
if me.textbox.tk == nil {
|
if me.textbox.tk == nil {
|
||||||
me.textbox.tk = addDropdownTK(me.textbox.wId)
|
// should only happen once
|
||||||
|
me.textbox.tk = addInternalTK(me.textbox.wId)
|
||||||
|
me.dropdown.tk.dumpWidget("init() textbox")
|
||||||
}
|
}
|
||||||
if me.textbox.tk == nil {
|
if me.textbox.tk == nil {
|
||||||
log.Log(GOCUI, "showDropdown() IS BROKEN")
|
log.Log(GOCUI, "showTextbox() Is Broken")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
startW, startH := tk.Position()
|
startW, startH := tk.Position()
|
||||||
log.Log(GOCUI, "showDropdown() SHOWING AT W,H=", startW, startH)
|
// log.Log(GOCUI, "showTextbox() SHOWING AT W,H=", startW, startH)
|
||||||
me.textbox.tk.MoveToOffset(startW+3, startH+2)
|
me.textbox.tk.MoveToOffset(startW+3, startH+2)
|
||||||
me.textbox.tk.labelN = "holy cow"
|
me.textbox.tk.labelN = "holy cow"
|
||||||
me.textbox.tk.Show()
|
me.textbox.tk.Show()
|
||||||
me.textbox.active = true
|
me.textbox.active = true
|
||||||
me.textbox.callerTK = tk
|
me.textbox.callerTK = tk
|
||||||
|
me.textbox.tk.dumpWidget("showTextbox()")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/toolkits/tree"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// register how the 'gocui' will work as a GO toolkit plugin
|
// register how the 'gocui' will work as a GO toolkit plugin
|
||||||
|
@ -92,9 +91,11 @@ func (tk *guiWidget) makeTK(ddItems []string) {
|
||||||
tk.Show()
|
tk.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func addDropdown() *tree.Node {
|
func addDropdown() *tree.Node {
|
||||||
return addDropdownNew(-222)
|
return addDropdownNew(-222)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
||||||
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
|
37
treeDraw.go
37
treeDraw.go
|
@ -133,47 +133,16 @@ func (w *guiWidget) drawTree(draw bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *guiWidget) Show() {
|
func (w *guiWidget) Show() {
|
||||||
// don't display fake widgets
|
|
||||||
if w.isFake {
|
if w.isFake {
|
||||||
|
// don't display fake widgets
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecate this
|
|
||||||
// if this isn't in the binary tree
|
|
||||||
// it's some internal widget so always display those
|
|
||||||
/*
|
|
||||||
if w.node == nil {
|
|
||||||
w.drawView()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if w.Hidden() {
|
if w.Hidden() {
|
||||||
|
// recursively checks if the parent is hidden
|
||||||
|
// never show hidden widgets
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecate this
|
|
||||||
// always show window titles
|
|
||||||
if w.node.WidgetType == widget.Window {
|
|
||||||
w.drawView()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// if the widget is not in the current displayed windo
|
|
||||||
if !w.IsCurrent() {
|
|
||||||
// log.Log(GOCUI, "Show() w.IsCurrent == false. NOT drawing", w.cuiName, w.String())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// this comes from the application developer
|
|
||||||
// finally, check if the widget State is hidden or not
|
|
||||||
if w.Hidden() {
|
|
||||||
// log.Log(GOCUI, "Show() w.node.Hidden() = false. not drawing", w.cuiName, w.String())
|
|
||||||
// don't display hidden widgets
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// log.Log(GOCUI, "Show() doing w.drawView()", w.cuiName, w.String())
|
|
||||||
w.drawView()
|
w.drawView()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue