From 180940b653d1f9b46b164292e91a53aedd88d48d Mon Sep 17 00:00:00 2001 From: delthas Date: Wed, 20 Apr 2022 17:45:37 +0200 Subject: 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. --- ui/buffers.go | 23 +++++++++++++++++++++++ ui/ui.go | 4 ++++ 2 files changed, 27 insertions(+) (limited to 'ui') diff --git a/ui/buffers.go b/ui/buffers.go index 021ddb1..fa77414 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -593,6 +593,29 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, } } +func (bs *BufferList) HorizontalBufferOffset(x int, offset int) int { + for i, b := range bs.list[offset:] { + if i > 0 { + x-- + if x < 0 { + return -1 + } + } + if b.title == "" { + x -= stringWidth(b.netName) + } else { + x -= stringWidth(b.title) + } + if 0 < b.highlights { + x -= 2 + len(fmt.Sprintf("%d", b.highlights)) + } + if x < 0 { + return offset + i + } + } + return -1 +} + func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int, offset *int) { x := width for i := len(bs.list) - 1; i >= 0; i-- { diff --git a/ui/ui.go b/ui/ui.go index 6a9979a..f3d232b 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -180,6 +180,10 @@ func (ui *UI) ScrollChannelDownBy(n int) { ui.channelOffset += n } +func (ui *UI) HorizontalBufferOffset(x int) int { + return ui.bs.HorizontalBufferOffset(x, ui.channelOffset) +} + func (ui *UI) ChannelOffset() int { return ui.channelOffset } -- cgit v1.2.3