diff options
author | delthas <delthas@dille.cc> | 2021-10-30 15:41:48 +0200 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-10-31 09:00:10 +0100 |
commit | 5c2fb81b0b172604780362bea76a0df5c746c500 (patch) | |
tree | 6b51d015855055ce826d3563d89bd1c7e05832d7 /ui | |
parent | Rework the /help command (diff) |
Make vertical channel list scrollable
Seems like I really have too many channels... :)
Diffstat (limited to '')
-rw-r--r-- | ui/buffers.go | 22 | ||||
-rw-r--r-- | ui/ui.go | 20 |
2 files changed, 33 insertions, 9 deletions
diff --git a/ui/buffers.go b/ui/buffers.go index c126408..8285fc6 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -419,27 +419,35 @@ func (bs *BufferList) idx(netID, title string) int { return -1 } -func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int) { +func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, height int, offset *int) { + if y0+len(bs.list)-*offset < height { + *offset = y0 + len(bs.list) - height + if *offset < 0 { + *offset = 0 + } + } + width-- drawVerticalLine(screen, x0+width, y0, height) clearArea(screen, x0, y0, width, height) indexPadding := 1 + int(math.Ceil(math.Log10(float64(len(bs.list))))) - for i, b := range bs.list { + for i, b := range bs.list[*offset:] { + bi := *offset + i x := x0 y := y0 + i st := tcell.StyleDefault if b.unread { st = st.Bold(true) - } else if i == bs.current { + } else if bi == bs.current { st = st.Underline(true) } - if i == bs.clicked { + if bi == bs.clicked { st = st.Reverse(true) } if bs.showBufferNumbers { indexSt := st.Foreground(tcell.ColorGray) - indexText := fmt.Sprintf("%d:", i) + indexText := fmt.Sprintf("%d:", bi) printString(screen, &x, y, Styled(indexText, indexSt)) x = x0 + indexPadding } @@ -448,7 +456,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, if b.title == "" { title = b.netName } else { - if i == bs.clicked { + if bi == bs.clicked { screen.SetContent(x, y, ' ', nil, tcell.StyleDefault.Reverse(true)) screen.SetContent(x+1, y, ' ', nil, tcell.StyleDefault.Reverse(true)) } @@ -458,7 +466,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, title = truncate(title, width-(x-x0), "\u2026") printString(screen, &x, y, Styled(title, st)) - if i == bs.clicked { + if bi == bs.clicked { st := tcell.StyleDefault.Reverse(true) for ; x < x0+width; x++ { screen.SetContent(x, y, ' ', nil, st) @@ -28,7 +28,8 @@ type UI struct { prompt StyledString status string - memberOffset int + channelOffset int + memberOffset int } func New(config Config) (ui *UI, err error) { @@ -140,6 +141,21 @@ func (ui *UI) ScrollDownHighlight() bool { return ui.bs.ScrollDownHighlight() } +func (ui *UI) ScrollChannelUpBy(n int) { + ui.channelOffset -= n + if ui.channelOffset < 0 { + ui.channelOffset = 0 + } +} + +func (ui *UI) ScrollChannelDownBy(n int) { + ui.channelOffset += n +} + +func (ui *UI) ChannelOffset() int { + return ui.channelOffset +} + func (ui *UI) ScrollMemberUpBy(n int) { ui.memberOffset -= n if ui.memberOffset < 0 { @@ -315,7 +331,7 @@ func (ui *UI) Draw(members []irc.Member) { if ui.config.ChanColWidth == 0 { ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.config.MemberColWidth) } else { - ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h) + ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h, &ui.channelOffset) } if ui.config.MemberColWidth != 0 { drawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset) |