about summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2020-06-09 19:49:23 +0100
committerReto Brunner <reto@labrat.space>2020-06-09 20:50:28 +0200
commitc6f4d7badd4cb36067f0e76198630a3d0f9e7ce9 (patch)
treeb429620f599eee7b5efc04b528ff9e3acfca0278 /widgets
parent543510f5c146aa6e4d3344ec7d109ad7945fa106 (diff)
downloadaerc-c6f4d7badd4cb36067f0e76198630a3d0f9e7ce9.tar.gz
Add dirlist scrollbar
This mimics the scrollbar implementation from the completion popover.
Only showing it when necessary and adapting the dirlist strings
appropriately.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/dirlist.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 418d2ea..f12631b 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -3,6 +3,7 @@ package widgets
 import (
 	"fmt"
 	"log"
+	"math"
 	"regexp"
 	"sort"
 
@@ -210,6 +211,20 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
 
 	dirlist.ensureScroll(ctx.Height())
 
+	needScrollbar := true
+	percentVisible := float64(ctx.Height()) / float64(len(dirlist.dirs))
+	if percentVisible >= 1.0 {
+		needScrollbar = false
+	}
+
+	textWidth := ctx.Width()
+	if needScrollbar {
+		textWidth -= 1
+	}
+	if textWidth < 0 {
+		textWidth = 0
+	}
+
 	for i, name := range dirlist.dirs {
 		if i < dirlist.scroll {
 			continue
@@ -226,14 +241,33 @@ func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
 			style = style.Reverse(true)
 			style = style.Foreground(tcell.ColorGray)
 		}
-		ctx.Fill(0, row, ctx.Width(), 1, ' ', style)
+		ctx.Fill(0, row, textWidth, 1, ' ', style)
 
-		dirString := dirlist.getDirString(name, ctx.Width(), func() string {
+		dirString := dirlist.getDirString(name, textWidth, func() string {
 			return dirlist.getRUEString(name)
 		})
 
 		ctx.Printf(0, row, style, dirString)
 	}
+
+	if needScrollbar {
+		scrollBarCtx := ctx.Subcontext(ctx.Width()-1, 0, 1, ctx.Height())
+		dirlist.drawScrollbar(scrollBarCtx, percentVisible)
+	}
+}
+
+func (dirlist *DirectoryList) drawScrollbar(ctx *ui.Context, percentVisible float64) {
+	gutterStyle := tcell.StyleDefault
+	pillStyle := tcell.StyleDefault.Reverse(true)
+
+	// gutter
+	ctx.Fill(0, 0, 1, ctx.Height(), ' ', gutterStyle)
+
+	// pill
+	pillSize := int(math.Ceil(float64(ctx.Height()) * percentVisible))
+	percentScrolled := float64(dirlist.scroll) / float64(len(dirlist.dirs))
+	pillOffset := int(math.Floor(float64(ctx.Height()) * percentScrolled))
+	ctx.Fill(0, pillOffset, 1, pillSize, ' ', pillStyle)
 }
 
 func (dirlist *DirectoryList) ensureScroll(h int) {
amp;id=b0a216f59a7770f5ce35f4a56b5055c51ceec284'>b0a216f5 ^
2c5ea01d ^
b0a216f5 ^



3a1e1f28 ^
b0a216f5 ^
e7758eba ^
b0a216f5 ^

5fca2a0b ^
b0b3af33 ^


b0a216f5 ^
b0b3af33 ^

2c5ea01d ^
5fca2a0b ^
b0b3af33 ^
2c5ea01d ^
582f3519 ^
b06433bc ^
582f3519 ^

94c5d83e ^
dee6cfa6 ^
e9e4b4ff ^
b0a216f5 ^
a082b66a ^

b0a216f5 ^
e9e4b4ff ^





ad75190c ^
e9e4b4ff ^
5fca2a0b ^


9cf43c17 ^
5fca2a0b ^

c7720fff ^



8d21b83c ^


e9e4b4ff ^
25a4162d ^
e9e4b4ff ^
0c2c782d ^
636d9393 ^
b0a216f5 ^
c6afc196 ^

c0d63e78 ^


c6afc196 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84