comments and code rearrangement
This commit is contained in:
parent
8a4afa760d
commit
c348940ca1
21
dropdown.go
21
dropdown.go
|
@ -155,22 +155,22 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
var dtoggle bool
|
var dtoggle bool // temporarily tracking show & hide
|
||||||
|
var doffset int = 5 // how many spaces over the dropdown menu should be from the mouse
|
||||||
|
|
||||||
func dropdownUnclicked(mouseX, mouseH int) {
|
func dropdownUnclicked(mouseW, mouseH int) {
|
||||||
var d *guiWidget
|
var d *guiWidget
|
||||||
|
|
||||||
// log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseX, mouseH)
|
// log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseW, mouseH)
|
||||||
if me.dropdownV == nil {
|
if me.dropdownV == nil {
|
||||||
log.Log(GOCUI, "mouseUp() dropdownV = nil. you don't have a fake dropdown window to make visible", mouseX, mouseH)
|
log.Log(GOCUI, "mouseUp() dropdownV = nil. you don't have a fake dropdown window to make visible", mouseW, mouseH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked at apparently (w=%d h=%d)", mouseX, mouseH))
|
// log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked at apparently (w=%d h=%d)", mouseW, mouseH))
|
||||||
// log.Log(GOCUI, "dropdownUnclicked() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1)
|
// log.Log(GOCUI, "dropdownUnclicked() find out what the string is here", mouseW, mouseH, tk.gocuiSize.h1)
|
||||||
|
|
||||||
rootW := me.treeRoot.TK.(*guiWidget)
|
|
||||||
// examine everything under X & Y on the screen)
|
// examine everything under X & Y on the screen)
|
||||||
for i, w := range findByXY(rootW, mouseX, mouseH) {
|
for i, w := range findByXY(mouseW, mouseH) {
|
||||||
log.Log(GOCUI, "dropdownUnclicked()", i, w.WidgetType)
|
log.Log(GOCUI, "dropdownUnclicked()", i, w.WidgetType)
|
||||||
if w.WidgetType == widget.Dropdown {
|
if w.WidgetType == widget.Dropdown {
|
||||||
d = w
|
d = w
|
||||||
|
@ -178,7 +178,7 @@ func dropdownUnclicked(mouseX, mouseH int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if d == nil {
|
if d == nil {
|
||||||
log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked() there was no dropdown widget at (w=%d h=%d)", mouseX, mouseH))
|
log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked() there was no dropdown widget at (w=%d h=%d)", mouseW, mouseH))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Log(GOCUI, "dropdownUnclicked()", d.node.Strings(), "end. now try to enable me.dropdownV")
|
log.Log(GOCUI, "dropdownUnclicked()", d.node.Strings(), "end. now try to enable me.dropdownV")
|
||||||
|
@ -191,8 +191,9 @@ func dropdownUnclicked(mouseX, mouseH int) {
|
||||||
tk.SetText("goodbye")
|
tk.SetText("goodbye")
|
||||||
} else {
|
} else {
|
||||||
log.Log(GOCUI, "dropdownUnclicked() set visible=true")
|
log.Log(GOCUI, "dropdownUnclicked() set visible=true")
|
||||||
tk.Show()
|
tk.MoveToOffset(mouseW+doffset, mouseH)
|
||||||
tk.SetText(dtext)
|
tk.SetText(dtext)
|
||||||
|
tk.Show()
|
||||||
dtoggle = true
|
dtoggle = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
find.go
32
find.go
|
@ -5,8 +5,31 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
// returns the widget under the location on the screen
|
/*
|
||||||
func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
|
gocui defines the offset like this:
|
||||||
|
|
||||||
|
width -> increases to the right
|
||||||
|
---------------------------------- hieght
|
||||||
|
| H = 1 | increases
|
||||||
|
| | |
|
||||||
|
| W = 1 W = 18 | |
|
||||||
|
| | v
|
||||||
|
| H = 5 | downwards
|
||||||
|
-------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// change over to this name
|
||||||
|
// returns all the widgets under (X,H) that are visible
|
||||||
|
func findByXY(w int, h int) []*guiWidget {
|
||||||
|
rootW := me.treeRoot.TK.(*guiWidget)
|
||||||
|
|
||||||
|
// this searches the binary tree recursively (function is right below)
|
||||||
|
return findByXYreal(rootW, w, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// this checks a widget to see if it is under (W,H), then checks the widget's children
|
||||||
|
// anything that matches is passed back as an array of widgets
|
||||||
|
func findByXYreal(widget *guiWidget, w int, h int) []*guiWidget {
|
||||||
var widgets []*guiWidget
|
var widgets []*guiWidget
|
||||||
|
|
||||||
if !widget.Visible() {
|
if !widget.Visible() {
|
||||||
|
@ -24,7 +47,7 @@ func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
|
||||||
|
|
||||||
// search through the children widgets in the binary tree
|
// search through the children widgets in the binary tree
|
||||||
for _, child := range widget.children {
|
for _, child := range widget.children {
|
||||||
widgets = append(widgets, findByXY(child, w, h)...)
|
widgets = append(widgets, findByXYreal(child, w, h)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return widgets
|
return widgets
|
||||||
|
@ -33,8 +56,7 @@ func findByXY(widget *guiWidget, w int, h int) []*guiWidget {
|
||||||
func findUnderMouse() *guiWidget {
|
func findUnderMouse() *guiWidget {
|
||||||
w, h := me.baseGui.MousePosition()
|
w, h := me.baseGui.MousePosition()
|
||||||
|
|
||||||
rootW := me.treeRoot.TK.(*guiWidget)
|
widgets := findByXY(w, h)
|
||||||
widgets := findByXY(rootW, w, h)
|
|
||||||
|
|
||||||
// search through all the widgets that were below the mouse click
|
// search through all the widgets that were below the mouse click
|
||||||
var found *guiWidget
|
var found *guiWidget
|
||||||
|
|
46
place.go
46
place.go
|
@ -8,6 +8,29 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
gocui defines the offset like this:
|
||||||
|
|
||||||
|
width -> increases to the right
|
||||||
|
---------------------------------- hieght
|
||||||
|
| H = 1 | increases
|
||||||
|
| | |
|
||||||
|
| W = 1 W = 18 | |
|
||||||
|
| | v
|
||||||
|
| H = 5 | downwards
|
||||||
|
-------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// moves the gocui view to the W and H offset on the screen
|
||||||
|
func (tk *guiWidget) MoveToOffset(W, H int) {
|
||||||
|
tk.gocuiSetWH(W, H)
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns where the corner of widget starts (upper left)
|
||||||
|
func (tk *guiWidget) Position() (int, int) {
|
||||||
|
return tk.gocuiSize.w0, tk.gocuiSize.h0
|
||||||
|
}
|
||||||
|
|
||||||
func (w *guiWidget) placeBox(startW int, startH int) {
|
func (w *guiWidget) placeBox(startW int, startH int) {
|
||||||
if w.WidgetType != widget.Box {
|
if w.WidgetType != widget.Box {
|
||||||
return
|
return
|
||||||
|
@ -215,29 +238,6 @@ func textSize(n *tree.Node) (int, int) {
|
||||||
return width, height
|
return width, height
|
||||||
}
|
}
|
||||||
|
|
||||||
// moves the gocui view the W and H offset on the screen
|
|
||||||
/*
|
|
||||||
gocui defines the offset like this:
|
|
||||||
|
|
||||||
width -> increases to the right
|
|
||||||
---------------------------------- hieght
|
|
||||||
| H = 1 | increases
|
|
||||||
| | |
|
|
||||||
| W = 1 W = 18 | |
|
|
||||||
| | v
|
|
||||||
| H = 5 | downwards
|
|
||||||
-------------------------------------
|
|
||||||
*/
|
|
||||||
// change over to this name
|
|
||||||
func (tk *guiWidget) MoveToOffset(W, H int) {
|
|
||||||
tk.gocuiSetWH(W, H)
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns where the corner of widget starts (upper left)
|
|
||||||
func (tk *guiWidget) Position() (int, int) {
|
|
||||||
return tk.gocuiSize.w0, tk.gocuiSize.h0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tk *guiWidget) gocuiSetWH(sizeW, sizeH int) {
|
func (tk *guiWidget) gocuiSetWH(sizeW, sizeH int) {
|
||||||
w := len(widget.GetString(tk.value))
|
w := len(widget.GetString(tk.value))
|
||||||
lines := strings.Split(widget.GetString(tk.value), "\n")
|
lines := strings.Split(widget.GetString(tk.value), "\n")
|
||||||
|
|
Loading…
Reference in New Issue