diff options
-rw-r--r-- | app.go | 2 | ||||
-rw-r--r-- | ui/buffers.go | 48 | ||||
-rw-r--r-- | ui/ui.go | 16 |
3 files changed, 50 insertions, 16 deletions
@@ -514,8 +514,10 @@ func (app *App) handleKeyEvent(ev *tcell.EventKey) { app.win.ScrollDown() case tcell.KeyCtrlN: app.win.NextBuffer() + app.win.HorizontalBufferScrollTo() case tcell.KeyCtrlP: app.win.PreviousBuffer() + app.win.HorizontalBufferScrollTo() case tcell.KeyRight: if ev.Modifiers() == tcell.ModAlt { app.win.NextBuffer() diff --git a/ui/buffers.go b/ui/buffers.go index 4bf4d20..f1f71b3 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -607,14 +607,7 @@ func (bs *BufferList) HorizontalBufferOffset(x int, offset int) int { 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)) - } + x -= bufferWidth(&b) if x < 0 { return offset + i } @@ -622,19 +615,42 @@ func (bs *BufferList) HorizontalBufferOffset(x int, offset int) int { return -1 } +func (bs *BufferList) GetLeftMost(screenWidth int) int { + width := 0 + var leftMost int + + for leftMost = bs.current; leftMost >= 0; leftMost-- { + if leftMost < bs.current { + width++ + } + width += bufferWidth(&bs.list[leftMost]) + if width > screenWidth { + return leftMost + 1 // Went offscreen, need to go one step back + } + } + + return 0 +} + +func bufferWidth(b *buffer) int { + width := 0 + if b.title == "" { + width += stringWidth(b.netName) + } else { + width += stringWidth(b.title) + } + if 0 < b.highlights { + width += 2 + len(fmt.Sprintf("%d", b.highlights)) + } + return width +} + func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int, offset *int) { x := width for i := len(bs.list) - 1; i >= 0; i-- { b := &bs.list[i] x-- - if b.title == "" { - x -= stringWidth(b.netName) - } else { - x -= stringWidth(b.title) - } - if 0 < b.highlights { - x -= 2 + len(fmt.Sprintf("%d", b.highlights)) - } + x -= bufferWidth(b) if x <= 10 { break } @@ -452,6 +452,22 @@ func (ui *UI) Draw(members []irc.Member) { ui.screen.Show() } +func (ui *UI) HorizontalBufferScrollTo() { + w, _ := ui.screen.Size() + screenWidth := w - ui.memberWidth + if ui.bs.current < ui.channelOffset { + ui.channelOffset = ui.bs.current + return + } + + leftMost := ui.bs.GetLeftMost(screenWidth) + + if ui.channelOffset >= leftMost { + return + } + ui.channelOffset = leftMost +} + func (ui *UI) drawStatusBar(x0, y, width int) { clearArea(ui.screen, x0, y, width, 1) |