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
+10 -36
View File
@@ -6472,6 +6472,12 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D
ellipses_run = f_push_run_from_string(scratch.arena, box->font, box->font_size, 0, str8_lit("..."));
}
d_truncated_fancy_run_list(text_position, &box->display_string_runs, max_x, ellipses_run);
if(box->flags & UI_BoxFlag_HasFuzzyMatchRanges)
{
Vec4F32 match_color = df_rgba_from_theme_color(DF_ThemeColor_Cursor);
match_color.w *= 0.25f;
d_truncated_fancy_run_fuzzy_matches(text_position, &box->display_string_runs, max_x, &box->fuzzy_match_ranges, match_color);
}
}
// rjf: draw focus viz
@@ -8390,38 +8396,6 @@ df_cfg_strings_from_gfx(Arena *arena, String8 root_path, DF_CfgSrc source)
return strs;
}
////////////////////////////////
//~ rjf: UI Helpers
internal void
df_box_equip_fuzzy_match_range_list_vis(UI_Box *box, FuzzyMatchRangeList range_list)
{
UI_Parent(box)
{
String8 display_string = ui_box_display_string(box);
F_Metrics metrics = f_metrics_from_tag_size(box->font, box->font_size);
F32 line_height = f_line_height_from_metrics(&metrics);
for(FuzzyMatchRangeNode *match_n = range_list.first; match_n != 0; match_n = match_n->next)
{
Rng1F32 match_pixel_range =
{
f_dim_from_tag_size_string(box->font, box->font_size, str8_prefix(display_string, match_n->range.min)).x,
f_dim_from_tag_size_string(box->font, box->font_size, str8_prefix(display_string, match_n->range.max)).x,
};
ui_set_next_fixed_x(match_pixel_range.min + box->text_padding + 4.f);
ui_set_next_fixed_y(box->font_size/8.f);
ui_set_next_fixed_width(match_pixel_range.max-match_pixel_range.min);
ui_set_next_pref_height(ui_pct(1, 0));
ui_set_next_corner_radius_00(box->font_size/3.f);
ui_set_next_corner_radius_01(box->font_size/3.f);
ui_set_next_corner_radius_10(box->font_size/3.f);
ui_set_next_corner_radius_11(box->font_size/3.f);
ui_set_next_background_color(df_rgba_from_theme_color(DF_ThemeColor_PlainOverlay));
ui_build_box_from_key(UI_BoxFlag_FloatingX|UI_BoxFlag_FloatingY|UI_BoxFlag_DrawBackground, ui_key_zero());
}
}
}
////////////////////////////////
//~ rjf: UI Widgets: Fancy Buttons
@@ -10935,7 +10909,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx
UI_Box *box = df_code_label(1.f, 1, ui_top_text_color(), display_string);
if(matches != 0)
{
df_box_equip_fuzzy_match_range_list_vis(box, *matches);
ui_box_equip_fuzzy_match_ranges(box, matches);
}
}
else if(flags & DF_LineEditFlag_DisplayStringIsCode)
@@ -10943,7 +10917,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx
UI_Box *box = df_code_label(1.f, 1, ui_top_text_color(), display_string);
if(matches != 0)
{
df_box_equip_fuzzy_match_range_list_vis(box, *matches);
ui_box_equip_fuzzy_match_ranges(box, matches);
}
}
else
@@ -10952,7 +10926,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx
UI_Box *box = ui_label(display_string).box;
if(matches != 0)
{
df_box_equip_fuzzy_match_range_list_vis(box, *matches);
ui_box_equip_fuzzy_match_ranges(box, matches);
}
}
}
@@ -10970,7 +10944,7 @@ df_line_edit(DF_LineEditFlags flags, S32 depth, FuzzyMatchRangeList *matches, Tx
UI_Box *box = ui_label(display_string).box;
if(matches != 0)
{
df_box_equip_fuzzy_match_range_list_vis(box, *matches);
ui_box_equip_fuzzy_match_ranges(box, matches);
}
}
else if(is_focus_active && flags & DF_LineEditFlag_CodeContents)
-5
View File
@@ -1018,11 +1018,6 @@ internal F32 df_font_size_from_slot(DF_Window *ws, DF_FontSlot slot);
//- rjf: config serialization
internal String8List df_cfg_strings_from_gfx(Arena *arena, String8 root_path, DF_CfgSrc source);
////////////////////////////////
//~ rjf: UI Helpers
internal void df_box_equip_fuzzy_match_range_list_vis(UI_Box *box, FuzzyMatchRangeList range_list);
////////////////////////////////
//~ rjf: UI Widgets: Fancy Buttons
+8 -8
View File
@@ -1965,8 +1965,8 @@ DF_VIEW_UI_FUNCTION_DEF(Commands)
{
desc_box = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "%S##desc_%p", cmd_desc, item->cmd_spec);
}
df_box_equip_fuzzy_match_range_list_vis(name_box, item->name_match_ranges);
df_box_equip_fuzzy_match_range_list_vis(desc_box, item->desc_match_ranges);
ui_box_equip_fuzzy_match_ranges(name_box, &item->name_match_ranges);
ui_box_equip_fuzzy_match_ranges(desc_box, &item->desc_match_ranges);
}
//- rjf: binding
@@ -2405,7 +2405,7 @@ DF_VIEW_UI_FUNCTION_DEF(FileSystem)
UI_PrefWidth(ui_pct(1, 0))
{
UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "%S##%p", file->filename, view);
df_box_equip_fuzzy_match_range_list_vis(box, file->match_ranges);
ui_box_equip_fuzzy_match_ranges(box, &file->match_ranges);
}
}
@@ -2579,14 +2579,14 @@ DF_VIEW_UI_FUNCTION_DEF(SystemProcesses)
if(is_attached) UI_TextColor(df_rgba_from_theme_color(DF_ThemeColor_Highlight1)) UI_PrefWidth(ui_text_dim(10, 1))
{
UI_Box *attached_label = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "[attached]##attached_label_%i", (int)info->info.pid);
df_box_equip_fuzzy_match_range_list_vis(attached_label, info->attached_match_ranges);
ui_box_equip_fuzzy_match_ranges(attached_label, &info->attached_match_ranges);
}
// rjf: process name
UI_PrefWidth(ui_text_dim(10, 1))
{
UI_Box *name_label = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "%S##name_label_%i", info->info.name, (int)info->info.pid);
df_box_equip_fuzzy_match_range_list_vis(name_label, info->name_match_ranges);
ui_box_equip_fuzzy_match_ranges(name_label, &info->name_match_ranges);
}
// rjf: process number
@@ -2594,7 +2594,7 @@ DF_VIEW_UI_FUNCTION_DEF(SystemProcesses)
{
ui_labelf("[PID: ");
UI_Box *pid_label = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "%i##pid_label", info->info.pid);
df_box_equip_fuzzy_match_range_list_vis(pid_label, info->pid_match_ranges);
ui_box_equip_fuzzy_match_ranges(pid_label, &info->pid_match_ranges);
ui_labelf("]");
}
}
@@ -2748,7 +2748,7 @@ DF_VIEW_UI_FUNCTION_DEF(EntityLister)
ui_set_next_text_color(color);
}
UI_Box *name_label = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "%S##label_%p", display_string, ent);
df_box_equip_fuzzy_match_range_list_vis(name_label, item.name_match_ranges);
ui_box_equip_fuzzy_match_ranges(name_label, &item.name_match_ranges);
}
if(ui_signal_from_box(box).clicked)
{
@@ -2880,7 +2880,7 @@ DF_VIEW_UI_FUNCTION_DEF(SymbolLister)
UI_Parent(box) UI_PrefWidth(ui_text_dim(10, 1))
{
UI_Box *box = df_code_label(1.f, 0, df_rgba_from_theme_color(DF_ThemeColor_CodeFunction), name);
df_box_equip_fuzzy_match_range_list_vis(box, item->match_ranges);
ui_box_equip_fuzzy_match_ranges(box, &item->match_ranges);
if(!tg_key_match(tg_key_zero(), type_key))
{
String8 type_string = tg_string_from_key(scratch.arena, graph, rdbg, type_key);