jcs
/textview
/amendments
/20
Grow chunks to accommodate highest chunk on a line
jcs made amendment 20 over 2 years ago
--- textview.c Tue Oct 15 23:29:29 2024
+++ textview.c Wed Oct 16 11:31:16 2024
@@ -818,14 +818,14 @@ bool
TVCalcLines(struct TVRec *tv)
{
struct TVSlab *text_slab;
- struct TVChunk *chunk, *last_chunk, *prev_chunk, *next_chunk;
+ struct TVChunk *chunk, *tchunk, *last_chunk, *prev_chunk, *next_chunk;
struct TVStyle *style, *prev_style;
struct TVLine *line, *next_line;
unsigned long avail, start, linen, last_space, max_right;
long n, back_width, back_n;
short width, space_width, height;
char c, tc, *text_slab_data;
- bool new_line;
+ bool new_line, grow_chunks;
/* find first dirty chunk but search backwards */
last_chunk = TVGetChunk(tv, tv->last_chunk);
@@ -850,12 +850,15 @@ TVCalcLines(struct TVRec *tv)
chunk->start_left = tv->padding.left;
chunk->start_line = 1;
chunk->end_line = 1;
+ prev_chunk = NULL;
+ prev_style = NULL;
} else {
/*
* TODO: compare style heights, use bigger and change
* end of previous chunk(s) on this same line
*/
prev_chunk = TVGetChunk(tv, chunk->prev_chunk);
+ prev_style = &tv->styles[prev_chunk->style];
chunk->top = prev_chunk->top;
chunk->start_left = prev_chunk->end_right;
chunk->start_line = prev_chunk->end_line;
@@ -867,9 +870,6 @@ TVCalcLines(struct TVRec *tv)
text_slab = TVGetTextSlab(tv, chunk->start);
text_slab_data = *(text_slab->data);
- new_line = false;
- last_space = 0;
-
linen = chunk->end_line;
line = TVGetLine(tv, linen);
@@ -879,9 +879,11 @@ TVCalcLines(struct TVRec *tv)
start = chunk->start;
} else
start = line->start;
-
- line->rect.bottom = line->rect.top + style->height;
-
+
+ new_line = false;
+ grow_chunks = false;
+ last_space = 0;
+
for (n = start; n < chunk->end; n++) {
c = text_slab_data[n - text_slab->base];
@@ -944,6 +946,30 @@ TVCalcLines(struct TVRec *tv)
}
chunk->end_right += width;
+
+ if (style->font_info.descent > line->baseline) {
+ if (line->baseline != 0)
+ grow_chunks = true;
+ line->baseline = style->font_info.descent;
+ }
+ if (line->rect.bottom - line->rect.top <
+ style->font_info.ascent + style->font_info.descent) {
+ if (line->rect.bottom != line->rect.top)
+ grow_chunks = true;
+ line->rect.bottom = line->rect.top +
+ style->font_info.ascent + style->font_info.descent;
+ }
+
+ if (grow_chunks) {
+ for (tchunk = TVGetChunk(tv, chunk->prev_chunk);
+ tchunk != NULL;
+ tchunk = TVGetChunk(tv, tchunk->prev_chunk)) {
+ if (tchunk->end < line->start)
+ break;
+ tchunk->bottom = line->rect.bottom;
+ }
+ grow_chunks = false;
+ }
}
chunk->bottom = line->rect.bottom;
@@ -1030,7 +1056,7 @@ TVDrawVisibleChunks(struct TVRec *tv)
tv->scrolled.top + line->rect.bottom >= 0 &&
tv->scrolled.top + line->rect.top <= tv->view_height) {
MoveTo(chunk->start_left,
- tv->scrolled.top + line->rect.top + style->baseline);
+ tv->scrolled.top + line->rect.bottom - line->baseline);
DrawText(start, 0, chars);
}
--- textview.h Tue Oct 15 22:47:05 2024
+++ textview.h Wed Oct 16 10:53:17 2024
@@ -74,6 +74,7 @@ struct TVChunk {
struct TVLine {
unsigned long start;
BigRect rect;
+ unsigned char baseline;
};
struct TVSlab {