mouse dragging works correctly again
This commit is contained in:
parent
b730ee9459
commit
1923f8df96
|
@ -117,9 +117,6 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
tk.makeWindowActive()
|
tk.makeWindowActive()
|
||||||
// w, h := g.MousePosition()
|
|
||||||
// me.downW = tk.gocuiSize.w0
|
|
||||||
// me.downH = tk.gocuiSize.h0
|
|
||||||
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
|
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
|
||||||
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -124,48 +124,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
|
||||||
// tk.dumpWidget("stdout fixme drag()" + tk.labelN)
|
|
||||||
me.mouse.currentDrag = tk
|
me.mouse.currentDrag = tk
|
||||||
tk.dragW = w - tk.gocuiSize.w0
|
|
||||||
tk.dragH = h - tk.gocuiSize.h0
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// tk.dumpWidget("mouse drag()" + tk.labelN)
|
|
||||||
me.mouse.currentDrag = tk
|
|
||||||
tk.dragW = w - tk.gocuiSize.w0
|
|
||||||
tk.dragH = h - tk.gocuiSize.h0
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// this needs to go
|
|
||||||
// event triggers when you push down on a mouse button
|
|
||||||
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
w, h := g.MousePosition()
|
|
||||||
|
|
||||||
for _, tk := range findByXY(w, h) {
|
|
||||||
tk.dumpWidget("msgDown()")
|
|
||||||
}
|
|
||||||
|
|
||||||
vx, vy, _, _, err := g.ViewPosition("msg")
|
|
||||||
if err == nil {
|
|
||||||
me.stdout.mouseOffsetW = w - vx
|
|
||||||
me.stdout.mouseOffsetH = h - vy
|
|
||||||
}
|
|
||||||
|
|
||||||
// did the user click in the corner of the stdout window? If so, resize the window.
|
|
||||||
cornerW := w - vx
|
|
||||||
cornerH := h - vy
|
|
||||||
if (me.stdout.w-cornerW < 4) && (me.stdout.h-cornerH < 4) {
|
|
||||||
log.Info("Resize msg", cornerW, cornerH)
|
|
||||||
me.stdout.resize = true
|
|
||||||
} else {
|
|
||||||
log.Info("not Resize msg", cornerW, cornerH)
|
|
||||||
me.stdout.resize = false
|
|
||||||
}
|
|
||||||
log.Info("setting mousedown to true for msg")
|
|
||||||
// msgMouseDown = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
@ -85,13 +85,13 @@ func mouseMove(g *gocui.Gui) {
|
||||||
}
|
}
|
||||||
// new function that is smarter
|
// new function that is smarter
|
||||||
if tk := findWindowUnderMouse(); tk != nil {
|
if tk := findWindowUnderMouse(); tk != nil {
|
||||||
me.mouse.currentDrag = tk
|
tk.setAsDragging()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// first look for windows
|
// first look for windows
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Window {
|
if tk.node.WidgetType == widget.Window {
|
||||||
me.mouse.currentDrag = tk
|
tk.setAsDragging()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,14 +99,13 @@ func mouseMove(g *gocui.Gui) {
|
||||||
// now look for the STDOUT window
|
// now look for the STDOUT window
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Flag {
|
if tk.node.WidgetType == widget.Flag {
|
||||||
me.mouse.currentDrag = tk
|
tk.setAsDragging()
|
||||||
// tk.moveNew()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, tk := range findByXY(w, h) {
|
for _, tk := range findByXY(w, h) {
|
||||||
if tk.node.WidgetType == widget.Stdout {
|
if tk.node.WidgetType == widget.Stdout {
|
||||||
me.mouse.currentDrag = tk
|
tk.setAsDragging()
|
||||||
// tk.moveNew()
|
// tk.moveNew()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -124,12 +123,24 @@ func mouseMove(g *gocui.Gui) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tk *guiWidget) setAsDragging() {
|
||||||
|
me.mouse.currentDrag = tk
|
||||||
|
tk.lastW = tk.gocuiSize.w0
|
||||||
|
tk.lastH = tk.gocuiSize.h0
|
||||||
|
}
|
||||||
|
|
||||||
// this is how the window gets dragged around
|
// this is how the window gets dragged around
|
||||||
func (tk *guiWidget) moveNew() {
|
func (tk *guiWidget) moveNew() {
|
||||||
w, h := me.baseGui.MousePosition()
|
w, h := me.baseGui.MousePosition()
|
||||||
if tk.node.WidgetType == widget.Window {
|
if tk.node.WidgetType == widget.Window {
|
||||||
tk.window.wasDragged = true
|
tk.window.wasDragged = true
|
||||||
tk.redrawWindow(w-tk.dragW, h-tk.dragH) // TODO: fix these hard coded things with offsets
|
|
||||||
|
// compute the new location based off how far the mouse has moved
|
||||||
|
// since the mouse button was pressed down
|
||||||
|
newW := tk.lastW + w - me.mouse.downW
|
||||||
|
newH := tk.lastH + h - me.mouse.downH
|
||||||
|
tk.redrawWindow(newW, newH)
|
||||||
|
|
||||||
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -151,12 +162,11 @@ func (tk *guiWidget) moveNew() {
|
||||||
// me.stdout.lastH = h - me.stdout.mouseOffsetH
|
// me.stdout.lastH = h - me.stdout.mouseOffsetH
|
||||||
tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||||||
} else {
|
} else {
|
||||||
// tk.dumpWidget(fmt.Sprintf("move(%dx%d) %s", w, h, tk.cuiName))
|
// compute the new location based off how far the mouse has moved
|
||||||
// log.Info("Resize false", w, h)
|
// since the mouse button was pressed down
|
||||||
// me.stdout.lastW = w - me.stdout.mouseOffsetW
|
newW := tk.lastW + w - me.mouse.downW
|
||||||
// me.stdout.lastH = h - me.stdout.mouseOffsetH
|
newH := tk.lastH + h - me.mouse.downH
|
||||||
// tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
tk.relocateStdout(newW, newH)
|
||||||
tk.relocateStdout(w-tk.dragW, h-tk.dragH)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// always place the help menu on top
|
// always place the help menu on top
|
||||||
|
|
|
@ -135,8 +135,6 @@ func (r *rectType) Height() int {
|
||||||
type window struct {
|
type window struct {
|
||||||
windowFrame *guiWidget // this is the frame for a window widget
|
windowFrame *guiWidget // this is the frame for a window widget
|
||||||
wasDragged bool // indicates the window was dragged. This keeps it from being rearranged
|
wasDragged bool // indicates the window was dragged. This keeps it from being rearranged
|
||||||
dragW int // when dragging a window, this is the offset to the mouse position
|
|
||||||
dragH int // when dragging a window, this is the offset to the mouse position
|
|
||||||
hasTabs bool // does the window have tabs?
|
hasTabs bool // does the window have tabs?
|
||||||
currentTab bool // the visible tab
|
currentTab bool // the visible tab
|
||||||
selectedTab *tree.Node // for a window, this is currently selected tab
|
selectedTab *tree.Node // for a window, this is currently selected tab
|
||||||
|
@ -165,8 +163,6 @@ type guiWidget struct {
|
||||||
node *tree.Node // the pointer back to the tree
|
node *tree.Node // the pointer back to the tree
|
||||||
windowFrame *guiWidget // this is the frame for a window widget
|
windowFrame *guiWidget // this is the frame for a window widget
|
||||||
internal bool // indicates the widget is internal to gocui and should be treated differently
|
internal bool // indicates the widget is internal to gocui and should be treated differently
|
||||||
dragW int // when dragging a window, this is the offset to the mouse position
|
|
||||||
dragH int // when dragging a window, this is the offset to the mouse position
|
|
||||||
hasTabs bool // does the window have tabs?
|
hasTabs bool // does the window have tabs?
|
||||||
currentTab bool // the visible tab
|
currentTab bool // the visible tab
|
||||||
window window // holds information specific only to Window widgets
|
window window // holds information specific only to Window widgets
|
||||||
|
@ -180,6 +176,8 @@ type guiWidget struct {
|
||||||
force rectType // force widget within these boundries (using this to debug window dragging)
|
force rectType // force widget within these boundries (using this to debug window dragging)
|
||||||
startW int // ?
|
startW int // ?
|
||||||
startH int // ?
|
startH int // ?
|
||||||
|
lastW int // used during mouse dragging
|
||||||
|
lastH int // used during mouse dragging
|
||||||
isFake bool // widget types like 'box' are 'false'
|
isFake bool // widget types like 'box' are 'false'
|
||||||
widths map[int]int // how tall each row in the grid is
|
widths map[int]int // how tall each row in the grid is
|
||||||
heights map[int]int // how wide each column in the grid is
|
heights map[int]int // how wide each column in the grid is
|
||||||
|
@ -189,7 +187,6 @@ type guiWidget struct {
|
||||||
color *colorT // what color to use
|
color *colorT // what color to use
|
||||||
defaultColor *colorT // the default colors // TODO: make a function for this instead
|
defaultColor *colorT // the default colors // TODO: make a function for this instead
|
||||||
isBG bool // means this is the background widget. There is only one of these
|
isBG bool // means this is the background widget. There is only one of these
|
||||||
// resize bool // the window is currently being resized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// THIS IS GO COMPILER MAGIC
|
// THIS IS GO COMPILER MAGIC
|
||||||
|
|
Loading…
Reference in New Issue