diff options
-rw-r--r-- | app.go | 6 | ||||
-rw-r--r-- | ui/buffers.go | 18 | ||||
-rw-r--r-- | ui/ui.go | 34 |
3 files changed, 51 insertions, 7 deletions
@@ -296,9 +296,13 @@ func (app *App) handleUIEvent(ev interface{}) { func (app *App) handleMouseEvent(ev *tcell.EventMouse) { x, y := ev.Position() + w, _ := app.win.Size() if ev.Buttons()&tcell.WheelUp != 0 { if x < app.cfg.ChanColWidth { // TODO scroll chan list + } else if x > w-app.cfg.MemberColWidth { + app.win.ScrollMemberUpBy(4) + app.requestHistory() } else { app.win.ScrollUpBy(4) app.requestHistory() @@ -307,6 +311,8 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) { if ev.Buttons()&tcell.WheelDown != 0 { if x < app.cfg.ChanColWidth { // TODO scroll chan list + } else if x > w-app.cfg.MemberColWidth { + app.win.ScrollMemberDownBy(4) } else { app.win.ScrollDownBy(4) } diff --git a/ui/buffers.go b/ui/buffers.go index 3f2ae4a..91d46cd 100644 --- a/ui/buffers.go +++ b/ui/buffers.go @@ -207,7 +207,10 @@ func (bs *BufferList) ResizeTimeline(tlInnerWidth, tlHeight int) { bs.tlHeight = tlHeight } -func (bs *BufferList) To(i int) { +func (bs *BufferList) To(i int) bool { + if i == bs.current { + return false + } if 0 <= i { bs.current = i if len(bs.list) <= bs.current { @@ -215,7 +218,9 @@ func (bs *BufferList) To(i int) { } bs.list[bs.current].highlights = 0 bs.list[bs.current].unread = false + return true } + return false } func (bs *BufferList) Next() { @@ -437,9 +442,16 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width, } } -func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member) { +func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, height int, members []irc.Member, offset *int) { st := tcell.StyleDefault + if y0+len(members)-*offset < height { + *offset = y0 + len(members) - height + if *offset < 0 { + *offset = 0 + } + } + for y := y0; y < y0+height; y++ { screen.SetContent(x0, y, 0x2502, nil, st) for x := x0 + 1; x < x0+width; x++ { @@ -447,7 +459,7 @@ func (bs *BufferList) DrawVerticalMemberList(screen tcell.Screen, x0, y0, width, } } - for i, m := range members { + for i, m := range members[*offset:] { st = tcell.StyleDefault x := x0 + 1 y := y0 + i @@ -28,6 +28,8 @@ type UI struct { e Editor prompt StyledString status string + + memberOffset int } func New(config Config) (ui *UI, err error) { @@ -91,10 +93,12 @@ func (ui *UI) CurrentBufferOldestTime() (t *time.Time) { func (ui *UI) NextBuffer() { ui.bs.Next() + ui.memberOffset = 0 } func (ui *UI) PreviousBuffer() { ui.bs.Previous() + ui.memberOffset = 0 } func (ui *UI) ClickedBuffer() int { @@ -108,7 +112,9 @@ func (ui *UI) ClickBuffer(i int) { } func (ui *UI) GoToBufferNo(i int) { - ui.bs.To(i) + if ui.bs.To(i) { + ui.memberOffset = 0 + } } func (ui *UI) ScrollUp() { @@ -127,6 +133,17 @@ func (ui *UI) ScrollDownBy(n int) { ui.bs.ScrollDown(n) } +func (ui *UI) ScrollMemberUpBy(n int) { + ui.memberOffset -= n + if ui.memberOffset < 0 { + ui.memberOffset = 0 + } +} + +func (ui *UI) ScrollMemberDownBy(n int) { + ui.memberOffset += n +} + func (ui *UI) IsAtTop() bool { return ui.bs.IsAtTop() } @@ -137,6 +154,7 @@ func (ui *UI) AddBuffer(title string) int { func (ui *UI) RemoveBuffer(title string) { _ = ui.bs.Remove(title) + ui.memberOffset = 0 } func (ui *UI) AddLine(buffer string, notify NotifyType, line Line) { @@ -151,7 +169,9 @@ func (ui *UI) JumpBuffer(sub string) bool { subLower := strings.ToLower(sub) for i, b := range ui.bs.list { if strings.Contains(strings.ToLower(b.title), subLower) { - ui.bs.To(i) + if ui.bs.To(i) { + ui.memberOffset = 0 + } return true } } @@ -161,7 +181,9 @@ func (ui *UI) JumpBuffer(sub string) bool { func (ui *UI) JumpBufferIndex(i int) bool { if i >= 0 && i < len(ui.bs.list) { - ui.bs.To(i) + if ui.bs.To(i) { + ui.memberOffset = 0 + } return true } return false @@ -250,6 +272,10 @@ func (ui *UI) Resize() { ui.bs.ResizeTimeline(innerWidth, h-2) } +func (ui *UI) Size() (int, int) { + return ui.screen.Size() +} + func (ui *UI) Draw(members []irc.Member) { w, h := ui.screen.Size() @@ -257,7 +283,7 @@ func (ui *UI) Draw(members []irc.Member) { ui.bs.DrawTimeline(ui.screen, ui.config.ChanColWidth, 0, ui.config.NickColWidth) ui.bs.DrawVerticalBufferList(ui.screen, 0, 0, ui.config.ChanColWidth, h) - ui.bs.DrawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members) + ui.bs.DrawVerticalMemberList(ui.screen, w-ui.config.MemberColWidth, 0, ui.config.MemberColWidth, h, members, &ui.memberOffset) ui.drawStatusBar(ui.config.ChanColWidth, h-2, w-ui.config.ChanColWidth-ui.config.MemberColWidth) for x := ui.config.ChanColWidth; x < 9+ui.config.ChanColWidth+ui.config.NickColWidth; x++ { |