diff options
author | delthas <delthas@dille.cc> | 2022-04-20 17:23:54 +0200 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-04-20 17:23:54 +0200 |
commit | 20c2b265c504ae47b959e60088aa6da41bef3263 (patch) | |
tree | 7451e1397d8b87d98843a5fa5f48326a9a779e07 | |
parent | Show/hide the channel & member list with F7/F8 (diff) |
Scroll horizontal channel list with the mouse wheel
This is inspired by a patch by mooff.
The horizontal channel list can now be scrolled with the mouse wheel.
-rw-r--r-- | app.go | 6 | ||||
-rw-r--r-- | ui/buffers.go | 25 | ||||
-rw-r--r-- | ui/ui.go | 2 |
3 files changed, 26 insertions, 7 deletions
@@ -432,9 +432,9 @@ func (app *App) handleUIEvent(ev interface{}) bool { func (app *App) handleMouseEvent(ev *tcell.EventMouse) { x, y := ev.Position() - w, _ := app.win.Size() + w, h := app.win.Size() if ev.Buttons()&tcell.WheelUp != 0 { - if x < app.win.ChannelWidth() { + if x < app.win.ChannelWidth() || (app.win.ChannelWidth() == 0 && y == h-1) { app.win.ScrollChannelUpBy(4) } else if x > w-app.win.MemberWidth() { app.win.ScrollMemberUpBy(4) @@ -444,7 +444,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) { } } if ev.Buttons()&tcell.WheelDown != 0 { - if x < app.win.ChannelWidth() { + if x < app.win.ChannelWidth() || (app.win.ChannelWidth() == 0 && y == h-1) { app.win.ScrollChannelDownBy(4) } else if x > w-app.win.MemberWidth() { app.win.ScrollMemberDownBy(4) diff --git a/ui/buffers.go b/ui/buffers.go index 69d1aa0..021ddb1 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -593,10 +593,29 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, } } -func (bs *BufferList) DrawHorizontalBufferList(screen tcell.Screen, x0, y0, width int) { - x := x0 +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)) + } + if x <= 10 { + break + } + if *offset > i { + *offset = i + } + } + x = x0 - for i, b := range bs.list { + for i, b := range bs.list[*offset:] { if width <= x-x0 { break } @@ -415,7 +415,7 @@ func (ui *UI) Draw(members []irc.Member) { ui.bs.DrawTimeline(ui.screen, ui.channelWidth, 0, ui.config.NickColWidth) if ui.channelWidth == 0 { - ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth) + ui.bs.DrawHorizontalBufferList(ui.screen, 0, h-1, w-ui.memberWidth, &ui.channelOffset) } else { ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.channelWidth, h, &ui.channelOffset) } |