only render visible characters (i.e. horizontal line culling)

This commit is contained in:
Felix Angell 2018-04-29 01:03:45 +01:00
parent e6fa391b06
commit d44801de76

View File

@ -763,6 +763,13 @@ var (
CAPS_LOCK = false
)
func min(a, b int) int {
if a < b {
return a
}
return b
}
// TODO(Felix) this is really stupid
func (b *Buffer) makeTab() string {
blah := []rune{}
@ -929,7 +936,7 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
ctx.Rect(highlightLinePosX, highlightLinePosY, b.w-ex, last_h, strife.Fill)
}
var visibleLines int = 50
var visibleLines, visibleChars int = 50, -1
// HACK
// force a render off screen
@ -949,6 +956,12 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
visibleLines = (int(b.h) / int(last_h)) + 3
}
// calculate how many chars we can fit
// on the screen.
if int(last_w) > 0 && int(b.w) != 0 {
visibleChars = (int(b.w-ex) / int(last_w)) - 3
}
start := b.cam.y
upper := b.cam.y + visibleLines
if start > len(b.contents) {
@ -969,6 +982,9 @@ func (b *Buffer) renderAt(ctx *strife.Renderer, rx int, ry int) {
for lineNum, rope := range b.contents[start:upper] {
currLine := []rune(rope.String())
// slice the visible characters only.
currLine = currLine[:min(visibleChars, len(currLine))]
// char index => colour
var matches map[int]syntaxRuneInfo
if b.languageInfo != nil && len(currLine) > 0 {