summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.go12
-rw-r--r--ui/buffers.go22
-rw-r--r--ui/ui.go20
3 files changed, 40 insertions, 14 deletions
diff --git a/app.go b/app.go
index 4b9d3e8..bb552e8 100644
--- a/app.go
+++ b/app.go
@@ -363,7 +363,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
w, _ := app.win.Size()
if ev.Buttons()&tcell.WheelUp != 0 {
if x < app.cfg.ChanColWidth {
- // TODO scroll chan list
+ app.win.ScrollChannelUpBy(4)
} else if x > w-app.cfg.MemberColWidth {
app.win.ScrollMemberUpBy(4)
} else {
@@ -373,7 +373,7 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
}
if ev.Buttons()&tcell.WheelDown != 0 {
if x < app.cfg.ChanColWidth {
- // TODO scroll chan list
+ app.win.ScrollChannelDownBy(4)
} else if x > w-app.cfg.MemberColWidth {
app.win.ScrollMemberDownBy(4)
} else {
@@ -381,11 +381,13 @@ func (app *App) handleMouseEvent(ev *tcell.EventMouse) {
}
}
if ev.Buttons()&tcell.ButtonPrimary != 0 && x < app.cfg.ChanColWidth {
- app.win.ClickBuffer(y)
+ app.win.ClickBuffer(y + app.win.ChannelOffset())
}
if ev.Buttons() == 0 {
- if y == app.win.ClickedBuffer() && x < app.cfg.ChanColWidth {
- app.win.GoToBufferNo(y)
+ if x < app.cfg.ChanColWidth {
+ if i := y + app.win.ChannelOffset(); i == app.win.ClickedBuffer() {
+ app.win.GoToBufferNo(i)
+ }
}
app.win.ClickBuffer(-1)
}
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)
diff --git a/ui/ui.go b/ui/ui.go
index 68511ab..cda5a06 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -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)