Skip to content

Commit

Permalink
Add highlighting of hovered views only
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavantix committed Dec 27, 2021
1 parent fbf51e5 commit 266011f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions _examples/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func layout(g *gocui.Gui) error {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Highlight = true
v.SelBgColor = gocui.ColorGreen
v.SelFgColor = gocui.ColorBlack
fmt.Fprintln(v, "Button 1 - line 1")
Expand All @@ -59,11 +58,11 @@ func layout(g *gocui.Gui) error {
if !errors.Is(err, gocui.ErrUnknownView) {
return err
}
v.Highlight = true
v.SelBgColor = gocui.ColorGreen
v.SelFgColor = gocui.ColorBlack
fmt.Fprintln(v, "Button 2 - line 1")
}
updateHighlightedView(g)
return nil
}

Expand Down Expand Up @@ -105,11 +104,23 @@ func showMsg(g *gocui.Gui, v *gocui.View) error {
maxX, maxY := g.Size()
if v, err := g.SetView("msg", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2, 0); err == nil || errors.Is(err, gocui.ErrUnknownView) {
v.Clear()
v.SelBgColor = gocui.ColorCyan
v.SelFgColor = gocui.ColorBlack
fmt.Fprintln(v, l)
}
return nil
}

func updateHighlightedView(g *gocui.Gui) {
mx, my := g.MousePosition()
for _, view := range g.Views() {
view.Highlight = false
}
if v, err := g.ViewByPosition(mx, my); err == nil {
v.Highlight = true
}
}

func moveMsg(g *gocui.Gui) {
mx, my := g.MousePosition()
if !movingMsg && (mx != initialMouseX || my != initialMouseY) {
Expand Down

0 comments on commit 266011f

Please sign in to comment.