commit 328325b
Tim Culverhouse
·
2023-11-02 00:34:53 +0000 UTC
parent a9be17f
mouse: add mouse shape and events Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
M
app.go
+20,
-2
1@@ -13,6 +13,7 @@ import (
2 "unicode"
3 "unicode/utf8"
4
5+ "git.sr.ht/~rockorager/vaxis"
6 "github.com/gdamore/tcell/v2"
7 "golang.org/x/net/context"
8 "golang.org/x/net/proxy"
9@@ -517,10 +518,20 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
10 }
11 }
12 if ev.Buttons()&tcell.ButtonPrimary != 0 {
13- if x < app.win.ChannelWidth() {
14+ if app.win.ChannelColClicked() {
15+ app.win.ResizeChannelCol(x + 1)
16+ } else if app.win.MemberColClicked() {
17+ app.win.ResizeMemberCol(w - x)
18+ } else if x == app.win.ChannelWidth()-1 {
19+ app.win.ClickChannelCol(true)
20+ app.win.SetMouseShape(vaxis.MouseShapeResizeHorizontal)
21+ } else if x < app.win.ChannelWidth() {
22 app.win.ClickBuffer(y + app.win.ChannelOffset())
23 } else if app.win.ChannelWidth() == 0 && y == h-1 {
24 app.win.ClickBuffer(app.win.HorizontalBufferOffset(x))
25+ } else if x == w-app.win.MemberWidth() {
26+ app.win.ClickMemberCol(true)
27+ app.win.SetMouseShape(vaxis.MouseShapeResizeHorizontal)
28 } else if x > w-app.win.MemberWidth() && y >= 2 {
29 app.win.ClickMember(y - 2 + app.win.MemberOffset())
30 }
31@@ -543,7 +554,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
32 }
33 }
34 if ev.Buttons() == 0 {
35- if x < app.win.ChannelWidth() {
36+ if x < app.win.ChannelWidth()-1 {
37 if i := y + app.win.ChannelOffset(); i == app.win.ClickedBuffer() {
38 app.win.GoToBufferNo(i)
39 }
40@@ -612,6 +623,13 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
41 }
42 app.win.ClickBuffer(-1)
43 app.win.ClickMember(-1)
44+ app.win.ClickChannelCol(false)
45+ app.win.ClickMemberCol(false)
46+ if x == app.win.ChannelWidth()-1 || x == w-app.win.MemberWidth() {
47+ app.win.SetMouseShape(vaxis.MouseShapeResizeHorizontal)
48+ } else {
49+ app.win.SetMouseShape(vaxis.MouseShapeDefault)
50+ }
51 }
52 }
53
M
ui/ui.go
+44,
-0
1@@ -6,6 +6,7 @@ import (
2 "sync/atomic"
3 "time"
4
5+ "git.sr.ht/~rockorager/vaxis"
6 "github.com/gdamore/tcell/v2"
7
8 "git.sr.ht/~delthas/senpai/irc"
9@@ -51,6 +52,9 @@ type UI struct {
10
11 channelWidth int
12 memberWidth int
13+
14+ channelColClicked bool
15+ memberColClicked bool
16 }
17
18 func New(config Config) (ui *UI, err error) {
19@@ -161,6 +165,42 @@ func (ui *UI) ClickBuffer(i int) {
20 }
21 }
22
23+func (ui *UI) ClickChannelCol(v bool) {
24+ ui.channelColClicked = v
25+}
26+
27+func (ui *UI) ChannelColClicked() bool {
28+ return ui.channelColClicked
29+}
30+
31+func (ui *UI) ResizeChannelCol(x int) {
32+ if x < 6 {
33+ x = 6
34+ } else if x > 24 {
35+ x = 24
36+ }
37+ ui.channelWidth = x
38+ ui.Resize()
39+}
40+
41+func (ui *UI) ClickMemberCol(v bool) {
42+ ui.memberColClicked = v
43+}
44+
45+func (ui *UI) MemberColClicked() bool {
46+ return ui.memberColClicked
47+}
48+
49+func (ui *UI) ResizeMemberCol(x int) {
50+ if x < 6 {
51+ x = 6
52+ } else if x > 24 {
53+ x = 24
54+ }
55+ ui.memberWidth = x
56+ ui.Resize()
57+}
58+
59 func (ui *UI) GoToBufferNo(i int) {
60 if ui.bs.To(i) {
61 ui.memberOffset = 0
62@@ -388,6 +428,10 @@ func (ui *UI) SetTitle(title string) {
63 ui.screen.SetTitle(title)
64 }
65
66+func (ui *UI) SetMouseShape(shape vaxis.MouseShape) {
67+ ui.screen.Vaxis().SetMouseShape(shape)
68+}
69+
70 // InputContent result must not be modified.
71 func (ui *UI) InputContent() []rune {
72 return ui.e.Content()