commit 180940b

delthas  ·  2022-04-20 15:45:37 +0000 UTC
parent 20c2b26
Enable clicking on a horizontal buffer to switch to it

This is inspired by a patch from mooff.

This keeps the same click & drag behavior as for the vertical channel
list.
3 files changed,  +33, -0
M app.go
M app.go
+6, -0
 1@@ -455,6 +455,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
 2 	if ev.Buttons()&tcell.ButtonPrimary != 0 {
 3 		if x < app.win.ChannelWidth() {
 4 			app.win.ClickBuffer(y + app.win.ChannelOffset())
 5+		} else if app.win.ChannelWidth() == 0 && y == h-1 {
 6+			app.win.ClickBuffer(app.win.HorizontalBufferOffset(x))
 7 		} else if x > w-app.win.MemberWidth() {
 8 			app.win.ClickMember(y + app.win.MemberOffset())
 9 		}
10@@ -464,6 +466,10 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
11 			if i := y + app.win.ChannelOffset(); i == app.win.ClickedBuffer() {
12 				app.win.GoToBufferNo(i)
13 			}
14+		} else if app.win.ChannelWidth() == 0 && y == h-1 {
15+			if i := app.win.HorizontalBufferOffset(x); i == app.win.ClickedBuffer() {
16+				app.win.GoToBufferNo(i)
17+			}
18 		} else if x > w-app.win.MemberWidth() {
19 			if i := y + app.win.MemberOffset(); i == app.win.ClickedMember() {
20 				netID, target := app.win.CurrentBuffer()
+23, -0
 1@@ -593,6 +593,29 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
 2 	}
 3 }
 4 
 5+func (bs *BufferList) HorizontalBufferOffset(x int, offset int) int {
 6+	for i, b := range bs.list[offset:] {
 7+		if i > 0 {
 8+			x--
 9+			if x < 0 {
10+				return -1
11+			}
12+		}
13+		if b.title == "" {
14+			x -= stringWidth(b.netName)
15+		} else {
16+			x -= stringWidth(b.title)
17+		}
18+		if 0 < b.highlights {
19+			x -= 2 + len(fmt.Sprintf("%d", b.highlights))
20+		}
21+		if x < 0 {
22+			return offset + i
23+		}
24+	}
25+	return -1
26+}
27+
28 func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int, offset *int) {
29 	x := width
30 	for i := len(bs.list) - 1; i >= 0; i-- {
+4, -0
 1@@ -180,6 +180,10 @@ func (ui *UI) ScrollChannelDownBy(n int) {
 2 	ui.channelOffset += n
 3 }
 4 
 5+func (ui *UI) HorizontalBufferOffset(x int) int {
 6+	return ui.bs.HorizontalBufferOffset(x, ui.channelOffset)
 7+}
 8+
 9 func (ui *UI) ChannelOffset() int {
10 	return ui.channelOffset
11 }