diff options
| author | Albert Cervin <albert@acervin.com> | 2022-12-13 09:01:00 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-12-13 09:01:00 +0100 |
| commit | a73225c9b45e110d315a3fc587a82040ce8c9a13 (patch) | |
| tree | f6b00156d203181ecbfd2f02cf7b1589dfd88e91 /src/text.c | |
| parent | 31e6fb2ba5fe9fd04722971a13a72ec71e846e46 (diff) | |
| download | dged-a73225c9b45e110d315a3fc587a82040ce8c9a13.tar.gz dged-a73225c9b45e110d315a3fc587a82040ce8c9a13.tar.xz dged-a73225c9b45e110d315a3fc587a82040ce8c9a13.zip | |
Implement scrolling
Buffer now scrolls correcly when reaching top or bottom and puts dot at
the middle of the screen.
Diffstat (limited to 'src/text.c')
| -rw-r--r-- | src/text.c | 31 |
1 files changed, 5 insertions, 26 deletions
@@ -282,31 +282,6 @@ void text_delete(struct text *text, uint32_t line, uint32_t col, } } -uint32_t text_render(struct text *text, uint32_t line, uint32_t nlines, - struct render_cmd *cmds, uint32_t max_ncmds) { - uint32_t nlines_max = nlines > text->capacity ? text->capacity : nlines; - - uint32_t ncmds = 0; - for (uint32_t lineidx = line; lineidx < nlines_max; ++lineidx) { - struct line *lp = &text->lines[lineidx]; - if (lp->flags & LineChanged) { - - cmds[ncmds] = (struct render_cmd){ - .row = lineidx, - .col = 0, // TODO: do not redraw full line - .data = lp->data, - .len = lp->nbytes, - }; - - lp->flags &= ~(LineChanged); - - ++ncmds; - } - } - - return ncmds; -} - void text_for_each_chunk(struct text *text, chunk_cb callback, void *userdata) { // if representation of text is changed, this can be changed as well text_for_each_line(text, 0, text->nlines, callback, userdata); @@ -314,12 +289,15 @@ void text_for_each_chunk(struct text *text, chunk_cb callback, void *userdata) { void text_for_each_line(struct text *text, uint32_t line, uint32_t nlines, chunk_cb callback, void *userdata) { - for (uint32_t li = line; li < (line + nlines); ++li) { + uint32_t nlines_max = + (line + nlines) > text->nlines ? text->nlines : (line + nlines); + for (uint32_t li = line; li < nlines_max; ++li) { struct line *src_line = &text->lines[li]; struct text_chunk line = (struct text_chunk){ .text = src_line->data, .nbytes = src_line->nbytes, .nchars = src_line->nchars, + .line = li, }; callback(&line, userdata); } @@ -331,6 +309,7 @@ struct text_chunk text_get_line(struct text *text, uint32_t line) { .text = src_line->data, .nbytes = src_line->nbytes, .nchars = src_line->nchars, + .line = line, }; } |
