move fuzzy range match visualization into formal ui rendering path; write dedicated truncated fuzzy match rendering path; fixes some visual bugs & makes all fuzzy range match visualization consistent and not ad-hoc

This commit is contained in:
Ryan Fleury
2024-02-02 15:35:44 -08:00
parent 876d9338fc
commit 708517a668
9 changed files with 102 additions and 58 deletions
+54 -7
View File
@@ -439,16 +439,14 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
{
ProfBeginFunction();
// rjf: grab total advance
F32 run_list_total_advance = list->dim.x;
//- rjf: total advance > max? -> enable trailer
B32 trailer_enabled = (list->dim.x >= max_x && trailer_run.dim.x < max_x);
// rjf: total advance > max? -> enable trailer
B32 trailer_enabled = (run_list_total_advance >= max_x && trailer_run.dim.x < max_x);
// rjf: draw runs
//- rjf: draw runs
F32 advance = 0;
B32 trailer_found = 0;
Vec4F32 last_color = {0};
U64 byte_off = 0;
for(D_FancyRunNode *n = list->first; n != 0; n = n->next)
{
D_FancyRun *fr = &n->v;
@@ -479,6 +477,7 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
if(!r_handle_match(texture, r_handle_zero()))
{
d_img(dst, src, texture, fr->color, 0, 0, 0);
//d_rect(dst, v4f32(1, 0, 0, 1), 0, 1.f, 0.f);
}
advance += piece->advance;
}
@@ -501,7 +500,7 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
}
end_draw:;
// rjf: draw trailer
//- rjf: draw trailer
if(trailer_found)
{
F_Piece *piece_first = trailer_run.pieces.v;
@@ -531,6 +530,54 @@ d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run tra
ProfEnd();
}
internal void
d_truncated_fancy_run_fuzzy_matches(Vec2F32 p, D_FancyRunList *list, F32 max_x, FuzzyMatchRangeList *ranges, Vec4F32 color)
{
for(FuzzyMatchRangeNode *match_n = ranges->first; match_n != 0; match_n = match_n->next)
{
Rng1U64 byte_range = match_n->range;
Rng1F32 pixel_range = {0};
{
pixel_range.min = 100000;
pixel_range.max = 0;
}
F32 last_piece_end_pad = 0;
U64 byte_off = 0;
F32 advance = 0;
F32 ascent = 0;
F32 descent = 0;
for(D_FancyRunNode *fr_n = list->first; fr_n != 0; fr_n = fr_n->next)
{
D_FancyRun *fr = &fr_n->v;
F_Run *run = &fr->run;
ascent = run->ascent;
descent = run->descent;
for(U64 piece_idx = 0; piece_idx < run->pieces.count; piece_idx += 1)
{
F_Piece *piece = &run->pieces.v[piece_idx];
if(contains_1u64(byte_range, byte_off))
{
F32 pre_advance = advance+piece->offset.x;
F32 post_advance = advance+piece->advance;
last_piece_end_pad = ((F32)piece->offset.x+(F32)dim_2s16(piece->subrect).x) - piece->advance;
pixel_range.min = Min(pre_advance, pixel_range.min);
pixel_range.max = Max(post_advance, pixel_range.max);
}
byte_off += piece->decode_size;
advance += piece->advance;
}
}
if(pixel_range.min < pixel_range.max)
{
Rng2F32 rect = r2f32p(p.x + pixel_range.min, p.y - descent - ascent,
p.x + pixel_range.max + last_piece_end_pad/2, p.y - descent - ascent + list->dim.y);
rect.x0 = Min(rect.x0, p.x+max_x);
rect.x1 = Min(rect.x1, p.x+max_x);
d_rect(rect, color, (descent+ascent)/4.f, 0, 1.f);
}
}
}
internal void
d_text_run(Vec2F32 p, Vec4F32 color, F_Run run)
{
+1
View File
@@ -183,6 +183,7 @@ internal void d_sub_bucket(D_Bucket *bucket);
//- rjf: text
internal void d_truncated_fancy_run_list(Vec2F32 p, D_FancyRunList *list, F32 max_x, F_Run trailer_run);
internal void d_truncated_fancy_run_fuzzy_matches(Vec2F32 p, D_FancyRunList *list, F32 max_x, FuzzyMatchRangeList *ranges, Vec4F32 color);
internal void d_text_run(Vec2F32 p, Vec4F32 color, F_Run run);
internal void d_truncated_text_run(Vec2F32 p, Vec4F32 color, F32 max_x, F_Run text_run, F_Run trailer_run);
internal void d_text(F_Tag font, F32 size, Vec2F32 p, Vec4F32 color, String8 string);