commit d8c4582

delthas  ·  2021-07-15 15:31:40 +0000 UTC
parent 579c232
Enable scrolling through the vertical member list with the mouse wheel
3 files changed,  +51, -7
M app.go
M app.go
+6, -0
 1@@ -296,9 +296,13 @@ func (app *App) handleUIEvent(ev interface{}) {
 2 
 3 func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 4 	x, y := ev.Position()
 5+	w, _ := app.win.Size()
 6 	if ev.Buttons()&tcell.WheelUp != 0 {
 7 		if x < app.cfg.ChanColWidth {
 8 			// TODO scroll chan list
 9+		} else if x > w-app.cfg.MemberColWidth {
10+			app.win.ScrollMemberUpBy(4)
11+			app.requestHistory()
12 		} else {
13 			app.win.ScrollUpBy(4)
14 			app.requestHistory()
15@@ -307,6 +311,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
16 	if ev.Buttons()&tcell.WheelDown != 0 {
17 		if x < app.cfg.ChanColWidth {
18 			// TODO scroll chan list
19+		} else if x > w-app.cfg.MemberColWidth {
20+			app.win.ScrollMemberDownBy(4)
21 		} else {
22 			app.win.ScrollDownBy(4)
23 		}
+15, -3
 1@@ -207,7 +207,10 @@ func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) {
 2 	bs.tlHeight = tlHeight
 3 }
 4 
 5-func (bs *BufferList) To(i int) {
 6+func (bs *BufferList) To(i int) bool {
 7+	if i == bs.current {
 8+		return false
 9+	}
10 	if 0 <= i {
11 		bs.current = i
12 		if len(bs.list) <= bs.current {
13@@ -215,7 +218,9 @@ func (bs *BufferList) To(i int) {
14 		}
15 		bs.list[bs.current].highlights = 0
16 		bs.list[bs.current].unread = false
17+		return true
18 	}
19+	return false
20 }
21 
22 func (bs *BufferList) Next() {
23@@ -437,9 +442,16 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
24 	}
25 }
26 
27-func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member) {
28+func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member, offset *int) {
29 	st := tcell.StyleDefault
30 
31+	if y0+len(members)-*offset < height {
32+		*offset = y0 + len(members) - height
33+		if *offset < 0 {
34+			*offset = 0
35+		}
36+	}
37+
38 	for y := y0; y < y0+height; y++ {
39 		screen.SetContent(x0, y, 0x2502, nil, st)
40 		for x := x0 + 1; x < x0+width; x++ {
41@@ -447,7 +459,7 @@ func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width,
42 		}
43 	}
44 
45-	for i, m := range members {
46+	for i, m := range members[*offset:] {
47 		st = tcell.StyleDefault
48 		x := x0 + 1
49 		y := y0 + i
+30, -4
  1@@ -28,6 +28,8 @@ type UI struct {
  2 	e      Editor
  3 	prompt StyledString
  4 	status string
  5+
  6+	memberOffset int
  7 }
  8 
  9 func New(config Config) (ui *UI, err error) {
 10@@ -91,10 +93,12 @@ func (ui *UI) CurrentBufferOldestTime() (t *time.Time) {
 11 
 12 func (ui *UI) NextBuffer() {
 13 	ui.bs.Next()
 14+	ui.memberOffset = 0
 15 }
 16 
 17 func (ui *UI) PreviousBuffer() {
 18 	ui.bs.Previous()
 19+	ui.memberOffset = 0
 20 }
 21 
 22 func (ui *UI) ClickedBuffer() int {
 23@@ -108,7 +112,9 @@ func (ui *UI) ClickBuffer(i int) {
 24 }
 25 
 26 func (ui *UI) GoToBufferNo(i int) {
 27-	ui.bs.To(i)
 28+	if ui.bs.To(i) {
 29+		ui.memberOffset = 0
 30+	}
 31 }
 32 
 33 func (ui *UI) ScrollUp() {
 34@@ -127,6 +133,17 @@ func (ui *UI) ScrollDownBy(n int) {
 35 	ui.bs.ScrollDown(n)
 36 }
 37 
 38+func (ui *UI) ScrollMemberUpBy(n int) {
 39+	ui.memberOffset -= n
 40+	if ui.memberOffset < 0 {
 41+		ui.memberOffset = 0
 42+	}
 43+}
 44+
 45+func (ui *UI) ScrollMemberDownBy(n int) {
 46+	ui.memberOffset += n
 47+}
 48+
 49 func (ui *UI) IsAtTop() bool {
 50 	return ui.bs.IsAtTop()
 51 }
 52@@ -137,6 +154,7 @@ func (ui *UI) AddBuffer(title string) int {
 53 
 54 func (ui *UI) RemoveBuffer(title string) {
 55 	_ = ui.bs.Remove(title)
 56+	ui.memberOffset = 0
 57 }
 58 
 59 func (ui *UI) AddLine(buffer string, notify NotifyType, line Line) {
 60@@ -151,7 +169,9 @@ func (ui *UI) JumpBuffer(sub string) bool {
 61 	subLower := strings.ToLower(sub)
 62 	for i, b := range ui.bs.list {
 63 		if strings.Contains(strings.ToLower(b.title), subLower) {
 64-			ui.bs.To(i)
 65+			if ui.bs.To(i) {
 66+				ui.memberOffset = 0
 67+			}
 68 			return true
 69 		}
 70 	}
 71@@ -161,7 +181,9 @@ func (ui *UI) JumpBuffer(sub string) bool {
 72 
 73 func (ui *UI) JumpBufferIndex(i int) bool {
 74 	if i >= 0 && i < len(ui.bs.list) {
 75-		ui.bs.To(i)
 76+		if ui.bs.To(i) {
 77+			ui.memberOffset = 0
 78+		}
 79 		return true
 80 	}
 81 	return false
 82@@ -250,6 +272,10 @@ func (ui *UI) Resize() {
 83 	ui.bs.ResizeTimeline(innerWidth, h-2)
 84 }
 85 
 86+func (ui *UI) Size() (int, int) {
 87+	return ui.screen.Size()
 88+}
 89+
 90 func (ui *UI) Draw(members []irc.Member) {
 91 	w, h := ui.screen.Size()
 92 
 93@@ -257,7 +283,7 @@ func (ui *UI) Draw(members []irc.Member) {
 94 
 95 	ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth)
 96 	ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h)
 97-	ui.bs.DrawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members)
 98+	ui.bs.DrawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset)
 99 	ui.drawStatusBar(ui.config.ChanColWidth, h-2, w-ui.config.ChanColWidth-ui.config.MemberColWidth)
100 
101 	for x := ui.config.ChanColWidth; x < 9+ui.config.ChanColWidth+ui.config.NickColWidth; x++ {