extend mouse events to include view frame edges

This commit is contained in:
Jesse Duffield 2019-06-29 10:35:26 +10:00
parent e030e03fac
commit d99ac1a5a2
2 changed files with 6 additions and 2 deletions

6
gui.go
View File

@ -233,7 +233,11 @@ func (g *Gui) ViewByPosition(x, y int) (*View, error) {
// traverse views in reverse order checking top views first
for i := len(g.views); i > 0; i-- {
v := g.views[i-1]
if x > v.x0 && x < v.x1 && y > v.y0 && y < v.y1 {
frameOffset := 0
if v.Frame {
frameOffset = 1
}
if x > v.x0-frameOffset && x < v.x1+frameOffset && y > v.y0-frameOffset && y < v.y1+frameOffset {
return v, nil
}
}

View File

@ -196,7 +196,7 @@ func (v *View) setRune(x, y int, ch rune, fgColor, bgColor Attribute) error {
func (v *View) SetCursor(x, y int) error {
maxX, maxY := v.Size()
if x < 0 || x >= maxX || y < 0 || y >= maxY {
return errors.New("invalid point")
return nil
}
v.cx = x
v.cy = y