summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-27 15:48:59 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-27 15:48:59 -0500
commitc38e418286c5cc2e8af7f68de9483d9cdcf95dce (patch)
tree461a7ce91748ac506fa31e7c918ab5ba6f6d8b14 /buffer.c
parent0fcc0682080da33edc81fa98c450a904165d5b5a (diff)
only render visible lines
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/buffer.c b/buffer.c
index fac72af..7f9d810 100644
--- a/buffer.c
+++ b/buffer.c
@@ -787,10 +787,12 @@ void buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float y2) {
u32 column = 0;
- // @TODO: make this better (we should figure out where to start rendering, etc.)
- text_state.y -= (float)buffer->scroll_y * char_height;
+ u32 start_line = (u32)buffer->scroll_y; // line to start rendering from
+ text_state.y -= (float)(buffer->scroll_y - start_line) * char_height;
- for (u32 line_idx = 0; line_idx < nlines; ++line_idx) {
+ //debug_print("Rendering from " U32_FMT, start_line);
+
+ for (u32 line_idx = start_line; line_idx < nlines; ++line_idx) {
Line *line = &lines[line_idx];
for (char32_t *p = line->str, *end = p + line->len; p != end; ++p) {
char32_t c = *p;
@@ -813,9 +815,16 @@ void buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float y2) {
// next line
text_state.x = render_start_x;
+ if (text_state.y > text_state.max_y) {
+ // made it to the bottom of the buffer view.
+ //debug_println(" to " U32_FMT ".", line_idx);
+ break;
+ }
text_state.y += text_font_char_height(font);
column = 0;
}
+
+
text_chars_end(font);
{ // render cursor