From d44801de76d95d8351006c1c232d1ffc27e8af5d Mon Sep 17 00:00:00 2001 From: Felix Angell Date: Sun, 29 Apr 2018 01:03:45 +0100 Subject: [PATCH] only render visible characters (i.e. horizontal line culling) --- gui/buffer.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gui/buffer.go b/gui/buffer.go index df026fa..96e8b59 100644 --- a/gui/buffer.go +++ b/gui/buffer.go @@ -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 {