From 58f94fa0a1333dfccfb24f90b22506b29a64397b Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 12 Feb 2024 06:26:23 -0600 Subject: mouse: use vaxis mouse events Replace all tcell.EventMouse events with vaxis mouse events Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/ui/grid.go | 3 +-- lib/ui/stack.go | 5 ++--- lib/ui/tab.go | 15 +++++++-------- lib/ui/textinput.go | 7 +++---- 4 files changed, 13 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/ui/grid.go b/lib/ui/grid.go index 00f759bf..ce3d37d6 100644 --- a/lib/ui/grid.go +++ b/lib/ui/grid.go @@ -5,7 +5,6 @@ import ( "sync" "git.sr.ht/~rockorager/vaxis" - "github.com/gdamore/tcell/v2" ) type Grid struct { @@ -130,7 +129,7 @@ func (grid *Grid) Draw(ctx *Context) { } func (grid *Grid) MouseEvent(localX int, localY int, event vaxis.Event) { - if event, ok := event.(*tcell.EventMouse); ok { + if event, ok := event.(vaxis.Mouse); ok { grid.mutex.RLock() defer grid.mutex.RUnlock() diff --git a/lib/ui/stack.go b/lib/ui/stack.go index a4017007..890ab272 100644 --- a/lib/ui/stack.go +++ b/lib/ui/stack.go @@ -4,8 +4,7 @@ import ( "fmt" "git.sr.ht/~rjarry/aerc/config" - - "github.com/gdamore/tcell/v2" + "git.sr.ht/~rockorager/vaxis" ) type Stack struct { @@ -34,7 +33,7 @@ func (stack *Stack) Draw(ctx *Context) { } } -func (stack *Stack) MouseEvent(localX int, localY int, event tcell.Event) { +func (stack *Stack) MouseEvent(localX int, localY int, event vaxis.Event) { if len(stack.children) > 0 { if element, ok := stack.Peek().(Mouseable); ok { element.MouseEvent(localX, localY, event) diff --git a/lib/ui/tab.go b/lib/ui/tab.go index 704b01db..5d824955 100644 --- a/lib/ui/tab.go +++ b/lib/ui/tab.go @@ -3,7 +3,6 @@ package ui import ( "sync" - "github.com/gdamore/tcell/v2" "github.com/mattn/go-runewidth" "git.sr.ht/~rjarry/aerc/config" @@ -407,7 +406,7 @@ func (strip *TabStrip) Invalidate() { Invalidate() } -func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { +func (strip *TabStrip) MouseEvent(localX int, localY int, event vaxis.Event) { strip.parent.m.Lock() defer strip.parent.m.Unlock() changeFocus := func(focus bool) { @@ -418,9 +417,9 @@ func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { } unfocus := func() { changeFocus(false) } refocus := func() { changeFocus(true) } - if event, ok := event.(*tcell.EventMouse); ok { - switch event.Buttons() { - case tcell.Button1: + if event, ok := event.(vaxis.Mouse); ok { + switch event.Button { + case vaxis.MouseLeftButton: selectedTab, ok := strip.clicked(localX, localY) if !ok || selectedTab == strip.parent.curIndex { return @@ -428,7 +427,7 @@ func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { unfocus() strip.parent.selectPriv(selectedTab) refocus() - case tcell.WheelDown: + case vaxis.MouseWheelDown: unfocus() index := strip.parent.curIndex + 1 if index >= len(strip.parent.tabs) { @@ -436,7 +435,7 @@ func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { } strip.parent.selectPriv(index) refocus() - case tcell.WheelUp: + case vaxis.MouseWheelUp: unfocus() index := strip.parent.curIndex - 1 if index < 0 { @@ -444,7 +443,7 @@ func (strip *TabStrip) MouseEvent(localX int, localY int, event tcell.Event) { } strip.parent.selectPriv(index) refocus() - case tcell.Button3: + case vaxis.MouseMiddleButton: selectedTab, ok := strip.clicked(localX, localY) if !ok { return diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index d52ee07a..a01184f2 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -6,7 +6,6 @@ import ( "sync" "time" - "github.com/gdamore/tcell/v2" "github.com/mattn/go-runewidth" "git.sr.ht/~rjarry/aerc/config" @@ -144,9 +143,9 @@ func (ti *TextInput) drawPopover(ctx *Context) { ctx.Popover(pos, 0, width, height, cmp) } -func (ti *TextInput) MouseEvent(localX int, localY int, event tcell.Event) { - if event, ok := event.(*tcell.EventMouse); ok { - if event.Buttons() == tcell.Button1 { +func (ti *TextInput) MouseEvent(localX int, localY int, event vaxis.Event) { + if event, ok := event.(vaxis.Mouse); ok { + if event.Button == vaxis.MouseLeftButton { if localX >= len(ti.prompt)+1 && localX <= len(ti.text[ti.scroll:])+len(ti.prompt)+1 { ti.index = localX - len(ti.prompt) - 1 ti.ensureScroll() -- cgit