commit 0af566c
Hubert Hirtz
·
2020-08-17 19:45:11 +0000 UTC
parent ef46f82
ui: Fix scroll when lines are added When lines were added while "scrollAmt > 0", instead of incrementing scrollAmt, add the height of the line.
2 files changed,
+13,
-11
+11,
-9
1@@ -281,15 +281,17 @@ type bufferList struct {
2 list []buffer
3 current int
4
5- width int
6- height int
7+ width int
8+ height int
9+ nickColWidth int
10 }
11
12-func newBufferList(width, height int) bufferList {
13+func newBufferList(width, height, nickColWidth int) bufferList {
14 return bufferList{
15- list: []buffer{},
16- width: width,
17- height: height,
18+ list: []buffer{},
19+ width: width,
20+ height: height,
21+ nickColWidth: nickColWidth,
22 }
23 }
24
25@@ -356,7 +358,7 @@ func (bs *bufferList) AddLine(title string, line Line) {
26 } else {
27 b.lines = append(b.lines, line)
28 if idx == bs.current && 0 < b.scrollAmt {
29- b.scrollAmt++
30+ b.scrollAmt += len(line.NewLines(bs.width-8-bs.nickColWidth)) + 1
31 }
32 }
33
34@@ -470,8 +472,8 @@ func (bs *bufferList) idx(title string) int {
35 return -1
36 }
37
38-func (bs *bufferList) Draw(screen tcell.Screen, nickColWidth int) {
39- bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3, nickColWidth)
40+func (bs *bufferList) Draw(screen tcell.Screen) {
41+ bs.list[bs.current].DrawLines(screen, bs.width, bs.height-3, bs.nickColWidth)
42 bs.drawStatusBar(screen, bs.height-3)
43 bs.drawTitleList(screen, bs.height-1)
44 }
M
ui/ui.go
+2,
-2
1@@ -51,7 +51,7 @@ func New(config Config) (ui *UI, err error) {
2 ui.exit.Store(false)
3
4 hmIdx := rand.Intn(len(homeMessages))
5- ui.bs = newBufferList(w, h)
6+ ui.bs = newBufferList(w, h, ui.config.NickColWidth)
7 ui.bs.Add(Home)
8 ui.bs.AddLine("", NewLineNow("--", homeMessages[hmIdx]))
9
10@@ -215,6 +215,6 @@ func (ui *UI) Resize() {
11 func (ui *UI) draw() {
12 _, h := ui.screen.Size()
13 ui.e.Draw(ui.screen, h-2)
14- ui.bs.Draw(ui.screen, ui.config.NickColWidth)
15+ ui.bs.Draw(ui.screen)
16 ui.screen.Show()
17 }