commit 20c2b26

delthas  ·  2022-04-20 15:23:54 +0000 UTC
parent db5a4b7
Scroll horizontal channel list with the mouse wheel

This is inspired by a patch by mooff.

The horizontal channel list can now be scrolled with the mouse wheel.
3 files changed,  +26, -7
M app.go
M app.go
+3, -3
 1@@ -432,9 +432,9 @@ func (app *App) handleUIEvent(ev interface{}) bool {
 2 
 3 func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 4 	x, y := ev.Position()
 5-	w, _ := app.win.Size()
 6+	w, h := app.win.Size()
 7 	if ev.Buttons()&tcell.WheelUp != 0 {
 8-		if x < app.win.ChannelWidth() {
 9+		if x < app.win.ChannelWidth() || (app.win.ChannelWidth() == 0 && y == h-1) {
10 			app.win.ScrollChannelUpBy(4)
11 		} else if x > w-app.win.MemberWidth() {
12 			app.win.ScrollMemberUpBy(4)
13@@ -444,7 +444,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
14 		}
15 	}
16 	if ev.Buttons()&tcell.WheelDown != 0 {
17-		if x < app.win.ChannelWidth() {
18+		if x < app.win.ChannelWidth() || (app.win.ChannelWidth() == 0 && y == h-1) {
19 			app.win.ScrollChannelDownBy(4)
20 		} else if x > w-app.win.MemberWidth() {
21 			app.win.ScrollMemberDownBy(4)
+22, -3
 1@@ -593,10 +593,29 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
 2 	}
 3 }
 4 
 5-func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int) {
 6-	x := x0
 7+func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int, offset *int) {
 8+	x := width
 9+	for i := len(bs.list) - 1; i >= 0; i-- {
10+		b := &bs.list[i]
11+		x--
12+		if b.title == "" {
13+			x -= stringWidth(b.netName)
14+		} else {
15+			x -= stringWidth(b.title)
16+		}
17+		if 0 < b.highlights {
18+			x -= 2 + len(fmt.Sprintf("%d", b.highlights))
19+		}
20+		if x <= 10 {
21+			break
22+		}
23+		if *offset > i {
24+			*offset = i
25+		}
26+	}
27+	x = x0
28 
29-	for i, b := range bs.list {
30+	for i, b := range bs.list[*offset:] {
31 		if width <= x-x0 {
32 			break
33 		}
+1, -1
1@@ -415,7 +415,7 @@ func (ui *UI) Draw(members []irc.Member) {
2 
3 	ui.bs.DrawTimeline(ui.screen, ui.channelWidth, 0, ui.config.NickColWidth)
4 	if ui.channelWidth == 0 {
5-		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth)
6+		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth, &ui.channelOffset)
7 	} else {
8 		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.channelWidth, h, &ui.channelOffset)
9 	}