commit 5c2fb81

delthas  ·  2021-10-30 13:41:48 +0000 UTC
parent 4ee9034
Make vertical channel list scrollable

Seems like I really have too many channels... :)
3 files changed,  +40, -14
M app.go
M app.go
+7, -5
 1@@ -363,7 +363,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 2 	w, _ := app.win.Size()
 3 	if ev.Buttons()&tcell.WheelUp != 0 {
 4 		if x < app.cfg.ChanColWidth {
 5-			// TODO scroll chan list
 6+			app.win.ScrollChannelUpBy(4)
 7 		} else if x > w-app.cfg.MemberColWidth {
 8 			app.win.ScrollMemberUpBy(4)
 9 		} else {
10@@ -373,7 +373,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
11 	}
12 	if ev.Buttons()&tcell.WheelDown != 0 {
13 		if x < app.cfg.ChanColWidth {
14-			// TODO scroll chan list
15+			app.win.ScrollChannelDownBy(4)
16 		} else if x > w-app.cfg.MemberColWidth {
17 			app.win.ScrollMemberDownBy(4)
18 		} else {
19@@ -381,11 +381,13 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
20 		}
21 	}
22 	if ev.Buttons()&tcell.ButtonPrimary != 0 && x < app.cfg.ChanColWidth {
23-		app.win.ClickBuffer(y)
24+		app.win.ClickBuffer(y + app.win.ChannelOffset())
25 	}
26 	if ev.Buttons() == 0 {
27-		if y == app.win.ClickedBuffer() && x < app.cfg.ChanColWidth {
28-			app.win.GoToBufferNo(y)
29+		if x < app.cfg.ChanColWidth {
30+			if i := y + app.win.ChannelOffset(); i == app.win.ClickedBuffer() {
31+				app.win.GoToBufferNo(i)
32+			}
33 		}
34 		app.win.ClickBuffer(-1)
35 	}
+15, -7
 1@@ -419,27 +419,35 @@ func (bs *BufferList) idx(netID, title string) int {
 2 	return -1
 3 }
 4 
 5-func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int) {
 6+func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int, offset *int) {
 7+	if y0+len(bs.list)-*offset < height {
 8+		*offset = y0 + len(bs.list) - height
 9+		if *offset < 0 {
10+			*offset = 0
11+		}
12+	}
13+
14 	width--
15 	drawVerticalLine(screen, x0+width, y0, height)
16 	clearArea(screen, x0, y0, width, height)
17 
18 	indexPadding := 1 + int(math.Ceil(math.Log10(float64(len(bs.list)))))
19-	for i, b := range bs.list {
20+	for i, b := range bs.list[*offset:] {
21+		bi := *offset + i
22 		x := x0
23 		y := y0 + i
24 		st := tcell.StyleDefault
25 		if b.unread {
26 			st = st.Bold(true)
27-		} else if i == bs.current {
28+		} else if bi == bs.current {
29 			st = st.Underline(true)
30 		}
31-		if i == bs.clicked {
32+		if bi == bs.clicked {
33 			st = st.Reverse(true)
34 		}
35 		if bs.showBufferNumbers {
36 			indexSt := st.Foreground(tcell.ColorGray)
37-			indexText := fmt.Sprintf("%d:", i)
38+			indexText := fmt.Sprintf("%d:", bi)
39 			printString(screen, &x, y, Styled(indexText, indexSt))
40 			x = x0 + indexPadding
41 		}
42@@ -448,7 +456,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
43 		if b.title == "" {
44 			title = b.netName
45 		} else {
46-			if i == bs.clicked {
47+			if bi == bs.clicked {
48 				screen.SetContent(x, y, ' ', nil, tcell.StyleDefault.Reverse(true))
49 				screen.SetContent(x+1, y, ' ', nil, tcell.StyleDefault.Reverse(true))
50 			}
51@@ -458,7 +466,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
52 		title = truncate(title, width-(x-x0), "\u2026")
53 		printString(screen, &x, y, Styled(title, st))
54 
55-		if i == bs.clicked {
56+		if bi == bs.clicked {
57 			st := tcell.StyleDefault.Reverse(true)
58 			for ; x < x0+width; x++ {
59 				screen.SetContent(x, y, ' ', nil, st)
+18, -2
 1@@ -28,7 +28,8 @@ type UI struct {
 2 	prompt StyledString
 3 	status string
 4 
 5-	memberOffset int
 6+	channelOffset int
 7+	memberOffset  int
 8 }
 9 
10 func New(config Config) (ui *UI, err error) {
11@@ -140,6 +141,21 @@ func (ui *UI) ScrollDownHighlight() bool {
12 	return ui.bs.ScrollDownHighlight()
13 }
14 
15+func (ui *UI) ScrollChannelUpBy(n int) {
16+	ui.channelOffset -= n
17+	if ui.channelOffset < 0 {
18+		ui.channelOffset = 0
19+	}
20+}
21+
22+func (ui *UI) ScrollChannelDownBy(n int) {
23+	ui.channelOffset += n
24+}
25+
26+func (ui *UI) ChannelOffset() int {
27+	return ui.channelOffset
28+}
29+
30 func (ui *UI) ScrollMemberUpBy(n int) {
31 	ui.memberOffset -= n
32 	if ui.memberOffset < 0 {
33@@ -315,7 +331,7 @@ func (ui *UI) Draw(members []irc.Member) {
34 	if ui.config.ChanColWidth == 0 {
35 		ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth)
36 	} else {
37-		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h)
38+		ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h, &ui.channelOffset)
39 	}
40 	if ui.config.MemberColWidth != 0 {
41 		drawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset)