commit 770c472
aoife cassidy
·
2024-12-16 19:53:04 +0000 UTC
parent 6f33f5d
Allow scrolling topic left and right Co-authored-by: delthas <delthas@dille.cc>
3 files changed,
+54,
-3
M
app.go
+4,
-0
1@@ -604,6 +604,8 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
2 app.win.ScrollChannelUpBy(4)
3 } else if x > w-app.win.MemberWidth() && y < h-memberItems*2 {
4 app.win.ScrollMemberUpBy(4)
5+ } else if y == 0 {
6+ app.win.ScrollTopicLeftBy(12)
7 } else {
8 app.win.ScrollUpBy(4)
9 }
10@@ -613,6 +615,8 @@ func (app *App) handleMouseEvent(ev vaxis.Mouse) {
11 app.win.ScrollChannelDownBy(4)
12 } else if x > w-app.win.MemberWidth() && y < h-memberItems*2 {
13 app.win.ScrollMemberDownBy(4)
14+ } else if y == 0 {
15+ app.win.ScrollTopicRightBy(12)
16 } else {
17 app.win.ScrollDownBy(4)
18 }
+42,
-3
1@@ -222,8 +222,9 @@ type buffer struct {
2 lines []Line
3 topic StyledString
4
5- scrollAmt int // offset in lines from the bottom
6- isAtTop bool
7+ scrollAmt int // offset in lines from the bottom
8+ topicOffset int // offset in clusters that are skipped when rendering topic text
9+ isAtTop bool
10 }
11
12 type BufferList struct {
13@@ -747,6 +748,20 @@ func (bs *BufferList) ScrollDownHighlight() bool {
14 return b.scrollAmt != 0
15 }
16
17+func (bs *BufferList) ScrollTopicLeft(n int) {
18+ b := bs.cur()
19+ b.topicOffset -= n
20+
21+ if b.topicOffset < 0 {
22+ b.topicOffset = 0
23+ }
24+}
25+
26+func (bs *BufferList) ScrollTopicRight(n int) {
27+ b := bs.cur()
28+ b.topicOffset += n
29+}
30+
31 // LinesAboveOffset returns a rough approximate of the number of lines
32 // above the offset (that is, starting from the bottom of the screen,
33 // up to the first line).
34@@ -1069,6 +1084,24 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
35 }
36 }
37
38+ for b.topicOffset > 0 {
39+ sr := []rune(b.topic.string)
40+ ri := 0
41+ for i := 0; i < b.topicOffset; i++ {
42+ s, _ := firstCluster(bs.ui.vx, sr[ri:])
43+ ri += len([]rune(s))
44+ }
45+ w := stringWidth(bs.ui.vx, string(sr[ri:]))
46+ if w <= bs.tlInnerWidth+nickColWidth+9-16 {
47+ b.topicOffset -= 12
48+ if b.topicOffset < 0 {
49+ b.topicOffset = 0
50+ }
51+ } else {
52+ break
53+ }
54+ }
55+
56 xTopic := x0
57 {
58 // TODO: factorize this (same code for drawing timeline)
59@@ -1076,8 +1109,14 @@ func (bs *BufferList) DrawTimeline(ui *UI, x0, y0, nickColWidth int) {
60 var st vaxis.Style
61 nextStyles := b.topic.styles
62
63- i := 0
64 sr := []rune(b.topic.string)
65+ ri := 0
66+ for i := 0; i < b.topicOffset; i++ {
67+ s, _ := firstCluster(bs.ui.vx, sr[ri:])
68+ ri += len([]rune(s))
69+ }
70+ i := len(string(sr[:ri]))
71+ sr = sr[ri:]
72 for len(sr) > 0 {
73 if 0 < len(nextStyles) && nextStyles[0].Start == i {
74 st = nextStyles[0].Style
M
ui/ui.go
+8,
-0
1@@ -350,6 +350,14 @@ func (ui *UI) ScrollMemberDownBy(n int) {
2 ui.memberOffset += n
3 }
4
5+func (ui *UI) ScrollTopicLeftBy(n int) {
6+ ui.bs.ScrollTopicLeft(n)
7+}
8+
9+func (ui *UI) ScrollTopicRightBy(n int) {
10+ ui.bs.ScrollTopicRight(n)
11+}
12+
13 func (ui *UI) LinesAboveOffset() int {
14 return ui.bs.LinesAboveOffset()
15 }