more mouse code cleanups
This commit is contained in:
parent
90a9f84f10
commit
cf073e9aae
|
@ -4,8 +4,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
@ -20,40 +18,6 @@ func (tk *guiWidget) doButtonClick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this whole things was impossible to make but it got me where I am now
|
|
||||||
// the debugging is way way better now with it being visible in the Stdout window
|
|
||||||
// so now it's possible to redo all this and make it better
|
|
||||||
func (tk *guiWidget) doWidgetClick(w int, h int) {
|
|
||||||
tk.dumpWidget(fmt.Sprintf("doWidgetClick(%d,%d)", w, h))
|
|
||||||
switch tk.node.WidgetType {
|
|
||||||
case widget.Checkbox:
|
|
||||||
if tk.node.State.Checked {
|
|
||||||
log.Log(WARN, "checkbox is being set to false")
|
|
||||||
tk.node.State.Checked = false
|
|
||||||
tk.setCheckbox()
|
|
||||||
} else {
|
|
||||||
log.Log(WARN, "checkbox is being set to true")
|
|
||||||
tk.node.State.Checked = true
|
|
||||||
tk.setCheckbox()
|
|
||||||
}
|
|
||||||
me.myTree.SendUserEvent(tk.node)
|
|
||||||
case widget.Button:
|
|
||||||
tk.doButtonClick()
|
|
||||||
case widget.Combobox:
|
|
||||||
tk.showDropdown()
|
|
||||||
case widget.Dropdown:
|
|
||||||
tk.showDropdown()
|
|
||||||
case widget.Textbox:
|
|
||||||
tk.showTextbox()
|
|
||||||
case widget.Flag:
|
|
||||||
tk.dropdownClicked(w, h)
|
|
||||||
case widget.Stdout:
|
|
||||||
tk.dumpWidget("stdout click()")
|
|
||||||
default:
|
|
||||||
tk.dumpWidget("undef click()")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handles a mouse click
|
// handles a mouse click
|
||||||
func doMouseClick(w int, h int) {
|
func doMouseClick(w int, h int) {
|
||||||
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
|
// Flag widgets (dropdown menus, etc) are the highest priority. ALWAYS SEND MOUSE CLICKS THERE FIRST
|
||||||
|
@ -124,29 +88,6 @@ func doMouseClick(w int, h int) {
|
||||||
// tk.dumpWidget("undef click()") // enable this to debug widget clicks
|
// tk.dumpWidget("undef click()") // enable this to debug widget clicks
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName)
|
|
||||||
// win.makeWindowActive()
|
|
||||||
// return
|
|
||||||
|
|
||||||
var found bool
|
|
||||||
|
|
||||||
for _, tk := range findByXY(w, h) {
|
|
||||||
// will show you everything found on a mouse click. great for debugging!
|
|
||||||
// tk.dumpWidget("click()")
|
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
|
||||||
// don't send clicks to the stdout debugging window
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
found = true
|
|
||||||
// tk.doWidgetClick(w, h)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if found {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Log(GOCUI, "click() nothing was at:", w, h)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func doMouseDoubleClick(w int, h int) {
|
func doMouseDoubleClick(w int, h int) {
|
||||||
|
|
|
@ -27,12 +27,14 @@ func mouseMove(g *gocui.Gui) {
|
||||||
|
|
||||||
// this runs while the user moves the mouse. this highlights text
|
// this runs while the user moves the mouse. this highlights text
|
||||||
// toggle off all highlight views except for whatever is under the mouse
|
// toggle off all highlight views except for whatever is under the mouse
|
||||||
|
// START HIGHLIGHTING
|
||||||
for _, view := range g.Views() {
|
for _, view := range g.Views() {
|
||||||
view.Highlight = false
|
view.Highlight = false
|
||||||
}
|
}
|
||||||
w, h := g.MousePosition()
|
w, h := g.MousePosition()
|
||||||
|
// TODO: try to highlight entire grid rows
|
||||||
if v, err := g.ViewByPosition(w, h); err == nil {
|
if v, err := g.ViewByPosition(w, h); err == nil {
|
||||||
// todo: identify and highlight grid rows here
|
// block anything from highlighting while a dialog box is open
|
||||||
if me.dropdown.active || me.textbox.active {
|
if me.dropdown.active || me.textbox.active {
|
||||||
if me.dropdown.tk != nil && me.dropdown.tk.v == v {
|
if me.dropdown.tk != nil && me.dropdown.tk.v == v {
|
||||||
v.Highlight = true
|
v.Highlight = true
|
||||||
|
@ -44,8 +46,9 @@ func mouseMove(g *gocui.Gui) {
|
||||||
v.Highlight = true
|
v.Highlight = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// END HIGHLIGHTING
|
||||||
|
|
||||||
// very useful for debugging in the past. also, just fun
|
// Super Mouse Mode. very useful for debugging in the past. also, just fun
|
||||||
if me.supermouse {
|
if me.supermouse {
|
||||||
w, h := g.MousePosition()
|
w, h := g.MousePosition()
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
|
@ -54,10 +57,13 @@ func mouseMove(g *gocui.Gui) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// how long has the mouse button been pressed down?
|
||||||
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
if time.Since(me.mouse.down) < me.mouse.clicktime {
|
||||||
// log.Info("not yet")
|
// log.Info("not yet")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// okay, the mouse button has been pressed down for a while.
|
||||||
|
// below here is mouse dragging
|
||||||
|
|
||||||
if me.dropdown.active || me.textbox.active {
|
if me.dropdown.active || me.textbox.active {
|
||||||
// can't drag or do anything when dropdown or textbox are visible
|
// can't drag or do anything when dropdown or textbox are visible
|
||||||
|
@ -107,13 +113,15 @@ func (tk *guiWidget) moveNew() {
|
||||||
tk.makeWindowActive()
|
tk.makeWindowActive()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if tk.node.WidgetType == widget.Flag {
|
/*
|
||||||
me.baseGui.SetView(tk.cuiName, w-3, h-3, w+20, h+20, 0)
|
if tk.node.WidgetType == widget.Flag {
|
||||||
// tk.verifyRect()
|
me.baseGui.SetView(tk.cuiName, w-3, h-3, w+20, h+20, 0)
|
||||||
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
|
// tk.verifyRect()
|
||||||
tk.dumpWidget(s)
|
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
|
||||||
return
|
tk.dumpWidget(s)
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
*/
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
if tk.node.WidgetType == widget.Stdout {
|
||||||
if me.mouse.resize {
|
if me.mouse.resize {
|
||||||
newW := w - me.stdout.lastW
|
newW := w - me.stdout.lastW
|
||||||
|
@ -132,7 +140,6 @@ func (tk *guiWidget) moveNew() {
|
||||||
tk.relocateStdout(newW, newH)
|
tk.relocateStdout(newW, newH)
|
||||||
// log.Info("Resize false", w, h, newW, newH)
|
// log.Info("Resize false", w, h, newW, newH)
|
||||||
}
|
}
|
||||||
|
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
||||||
}
|
}
|
||||||
// always place the help menu on top
|
|
||||||
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue