diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-27 15:48:59 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-27 15:48:59 -0500 |
commit | c38e418286c5cc2e8af7f68de9483d9cdcf95dce (patch) | |
tree | 461a7ce91748ac506fa31e7c918ab5ba6f6d8b14 /buffer.c | |
parent | 0fcc0682080da33edc81fa98c450a904165d5b5a (diff) |
only render visible lines
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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 |