From 78b5582e956fec60b529b8cdf8421f742f87dc68 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Tue, 22 Apr 2025 11:24:41 -0700 Subject: [PATCH] dead code elimination, do cleanup pass over cell text rendering story, prep for expr/eval in same cell --- src/draw/draw.c | 10 ++ src/draw/draw.h | 1 + src/raddbg/raddbg_core.c | 293 ++---------------------------------- src/raddbg/raddbg_views.c | 28 ++-- src/raddbg/raddbg_views.h | 3 +- src/raddbg/raddbg_widgets.c | 285 +++++++++++++++++------------------ src/raddbg/raddbg_widgets.h | 7 +- 7 files changed, 183 insertions(+), 444 deletions(-) diff --git a/src/draw/draw.c b/src/draw/draw.c index 24b39995..d77f41af 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -133,6 +133,16 @@ dr_string_from_fstrs(Arena *arena, DR_FStrList *list) return result; } +internal FuzzyMatchRangeList +dr_fuzzy_match_find_from_fstrs(Arena *arena, DR_FStrList *fstrs, String8 needle) +{ + Temp scratch = scratch_begin(&arena, 1); + String8 fstrs_string = dr_string_from_fstrs(scratch.arena, fstrs); + FuzzyMatchRangeList ranges = fuzzy_match_find(arena, needle, fstrs_string); + scratch_end(scratch); + return ranges; +} + internal DR_FRunList dr_fruns_from_fstrs(Arena *arena, F32 tab_size_px, DR_FStrList *strs) { diff --git a/src/draw/draw.h b/src/draw/draw.h index d905818f..d98f1081 100644 --- a/src/draw/draw.h +++ b/src/draw/draw.h @@ -123,6 +123,7 @@ internal void dr_fstrs_push_new_(Arena *arena, DR_FStrList *list, DR_FStrParams internal void dr_fstrs_concat_in_place(DR_FStrList *dst, DR_FStrList *to_push); internal DR_FStrList dr_fstrs_copy(Arena *arena, DR_FStrList *src); internal String8 dr_string_from_fstrs(Arena *arena, DR_FStrList *list); +internal FuzzyMatchRangeList dr_fuzzy_match_find_from_fstrs(Arena *arena, DR_FStrList *fstrs, String8 needle); internal DR_FRunList dr_fruns_from_fstrs(Arena *arena, F32 tab_size_px, DR_FStrList *strs); internal Vec2F32 dr_dim_from_fstrs(DR_FStrList *fstrs); diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 8008764c..c5fefee4 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -3114,7 +3114,11 @@ rd_view_ui(Rng2F32 rect) String8 string = cell->edit_string; if(string.size == 0) { - string = dr_string_from_fstrs(scratch.arena, &cell_info.fstrs); + string = dr_string_from_fstrs(scratch.arena, &cell_info.expr_fstrs); + } + if(string.size == 0) + { + string = dr_string_from_fstrs(scratch.arena, &cell_info.eval_fstrs); } string.size = Min(string.size, sizeof(ewv->dummy_text_edit_state.input_buffer)); RD_WatchPt pt = {row->block->key, row->key, rd_id_from_watch_cell(cell)}; @@ -3363,7 +3367,10 @@ rd_view_ui(Rng2F32 rect) continue; } RD_WatchRowCellInfo cell_info = rd_info_from_watch_row_cell(scratch.arena, row, string_flags, &row_info, cell, ui_top_font(), ui_top_font_size(), row_string_max_size_px); - String8 cell_string = dr_string_from_fstrs(scratch.arena, &cell_info.fstrs); + String8List cell_strings = {0}; + str8_list_push(scratch.arena, &cell_strings, dr_string_from_fstrs(scratch.arena, &cell_info.expr_fstrs)); + str8_list_push(scratch.arena, &cell_strings, dr_string_from_fstrs(scratch.arena, &cell_info.eval_fstrs)); + String8 cell_string = str8_list_join(scratch.arena, &cell_strings, &(StringJoin){.sep = str8_lit(" ")}); cell_string = str8_skip_chop_whitespace(cell_string); U64 comma_pos = str8_find_needle(cell_string, 0, str8_lit(","), 0); if(selection_tbl.min.x != selection_tbl.max.x || selection_tbl.min.y != selection_tbl.max.y) @@ -4330,17 +4337,6 @@ rd_view_ui(Rng2F32 rect) is_button = 0; is_activated_on_single_click = 0; } - String8 searched_string = dr_string_from_fstrs(scratch.arena, &cell_info.fstrs); - String8 search_query = rd_view_query_input(); - FuzzyMatchRangeList fuzzy_matches = fuzzy_match_find(scratch.arena, search_query, searched_string); - if(fuzzy_matches.count == 0) - { - String8 path_needle = str8_skip_last_slash(search_query); - if(0 < path_needle.size && path_needle.size < search_query.size) - { - fuzzy_matches = fuzzy_match_find(scratch.arena, path_needle, searched_string); - } - } // rjf: form cell build parameters RD_CellParams cell_params = {0}; @@ -4354,9 +4350,10 @@ rd_view_ui(Rng2F32 rect) cell_params.edit_buffer_size = sizeof(cell_edit_state->input_buffer); cell_params.edit_string_size_out = &cell_edit_state->input_size; cell_params.expanded_out = &next_row_expanded; - cell_params.pre_edit_value = dr_string_from_fstrs(scratch.arena, &cell_info.fstrs); - cell_params.fstrs = cell_info.fstrs; - cell_params.fuzzy_matches = &fuzzy_matches; + cell_params.pre_edit_value = dr_string_from_fstrs(scratch.arena, &cell_info.expr_fstrs); + cell_params.expr_fstrs = cell_info.expr_fstrs; + cell_params.eval_fstrs = cell_info.eval_fstrs; + cell_params.search_needle = rd_view_query_input(); // rjf: apply description if(row_height_px > ui_top_font_size()*3.5f) @@ -5982,270 +5979,6 @@ rd_window_frame(void) } } - //////////////////////////// - //- rjf: @window_ui_part top-level registers context menu - // -#if 0 - UI_CtxMenu(rd_state->ctx_menu_key) UI_PrefWidth(ui_em(50.f, 1.f)) - { - Temp scratch = scratch_begin(0, 0); - RD_Regs *regs = ws->ctx_menu_regs; - RD_RegSlot slot = ws->ctx_menu_regs_slot; - CTRL_Entity *ctrl_entity = &ctrl_entity_nil; - { - switch(slot) - { - default:{}break; - - ////////////////////// - //- rjf: source code locations - // - case RD_RegSlot_Cursor: - { - // TODO(rjf): with new registers-based commands, all of this can be deduplicated with the - // command-based path, but I am holding off on that until post 0.9.12 - these should be - // able to just all push commands for their corresponding actions - // - TXT_Scope *txt_scope = txt_scope_open(); - HS_Scope *hs_scope = hs_scope_open(); - TxtRng range = txt_rng(regs->cursor, regs->mark); - D_LineList lines = regs->lines; - if(!txt_pt_match(range.min, range.max) && ui_clicked(rd_cmd_spec_button(rd_cmd_kind_info_table[RD_CmdKind_Copy].string))) - { - U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, regs->text_key, regs->lang_kind, &hash); - String8 data = hs_data_from_hash(hs_scope, hash); - String8 copy_data = txt_string_from_info_data_txt_rng(&info, data, range); - os_set_clipboard_text(copy_data); - ui_ctx_menu_close(); - } - if(range.min.line == range.max.line && ui_clicked(rd_icon_buttonf(RD_IconKind_RightArrow, 0, "Set Next Statement"))) - { - CTRL_Entity *thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_regs()->thread); - U64 new_rip_vaddr = regs->vaddr; - if(regs->file_path.size != 0) - { - for(D_LineNode *n = lines.first; n != 0; n = n->next) - { - CTRL_EntityList modules = ctrl_modules_from_dbgi_key(scratch.arena, d_state->ctrl_entity_store, &n->v.dbgi_key); - CTRL_Entity *module = ctrl_module_from_thread_candidates(d_state->ctrl_entity_store, thread, &modules); - if(module != &ctrl_entity_nil) - { - new_rip_vaddr = ctrl_vaddr_from_voff(module, n->v.voff_range.min); - break; - } - } - } - rd_cmd(RD_CmdKind_SetThreadIP, .vaddr = new_rip_vaddr); - ui_ctx_menu_close(); - } - if(range.min.line == range.max.line && ui_clicked(rd_icon_buttonf(RD_IconKind_Play, 0, "Run To Line"))) - { - if(regs->file_path.size != 0) - { - rd_cmd(RD_CmdKind_RunToLine, .file_path = regs->file_path, .cursor = range.min); - } - else - { - rd_cmd(RD_CmdKind_RunToLine, .vaddr = regs->vaddr); - } - ui_ctx_menu_close(); - } - if(range.min.line == range.max.line && ui_clicked(rd_icon_buttonf(RD_IconKind_Null, 0, "Go To Name"))) - { - U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, regs->text_key, regs->lang_kind, &hash); - String8 data = hs_data_from_hash(hs_scope, hash); - Rng1U64 expr_off_range = {0}; - if(range.min.column != range.max.column) - { - expr_off_range = r1u64(txt_off_from_info_pt(&info, range.min), txt_off_from_info_pt(&info, range.max)); - } - else - { - expr_off_range = txt_expr_off_range_from_info_data_pt(&info, data, range.min); - } - String8 expr = str8_substr(data, expr_off_range); - rd_cmd(RD_CmdKind_GoToName, .string = expr); - ui_ctx_menu_close(); - } - if(range.min.line == range.max.line && ui_clicked(rd_icon_buttonf(RD_IconKind_CircleFilled, 0, "Toggle Breakpoint"))) - { - rd_cmd(RD_CmdKind_ToggleBreakpoint, - .file_path = regs->file_path, - .cursor = range.min, - .vaddr = regs->vaddr); - ui_ctx_menu_close(); - } - if(range.min.line == range.max.line && ui_clicked(rd_icon_buttonf(RD_IconKind_Binoculars, 0, "Toggle Watch Expression"))) - { - U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, regs->text_key, regs->lang_kind, &hash); - String8 data = hs_data_from_hash(hs_scope, hash); - Rng1U64 expr_off_range = {0}; - if(range.min.column != range.max.column) - { - expr_off_range = r1u64(txt_off_from_info_pt(&info, range.min), txt_off_from_info_pt(&info, range.max)); - } - else - { - expr_off_range = txt_expr_off_range_from_info_data_pt(&info, data, range.min); - } - String8 expr = str8_substr(data, expr_off_range); - rd_cmd(RD_CmdKind_ToggleWatchExpression, .string = expr); - ui_ctx_menu_close(); - } - if(regs->file_path.size == 0 && range.min.line == range.max.line && ui_clicked(rd_cmd_spec_button(rd_cmd_kind_info_table[RD_CmdKind_GoToSource].string))) - { - rd_cmd(RD_CmdKind_GoToSource, .lines = lines); - ui_ctx_menu_close(); - } - if(regs->file_path.size != 0 && range.min.line == range.max.line && ui_clicked(rd_cmd_spec_button(rd_cmd_kind_info_table[RD_CmdKind_GoToDisassembly].string))) - { - rd_cmd(RD_CmdKind_GoToDisassembly, .lines = lines); - ui_ctx_menu_close(); - } - hs_scope_close(hs_scope); - txt_scope_close(txt_scope); - }break; - - ////////////////////// - //- rjf: tabs - // - case RD_RegSlot_View: - { -#if 0 // TODO(rjf): @cfg (context menus) - RD_Cfg *tab = rd_cfg_from_id(regs->view); - RD_RegsScope(.view = regs->view) - { - String8 expr = rd_view_expr_string(); - RD_ViewRuleInfo *view_rule_info = rd_view_rule_info_from_string(tab->string); - RD_IconKind view_icon = view_rule_info->icon_kind; - DR_FStrList fstrs = rd_title_fstrs_from_view(scratch.arena, view_rule_info->display_name, expr, ui_top_palette()->text, ui_top_palette()->text_weak, ui_top_font_size()); - String8 file_path = rd_file_path_from_eval_string(scratch.arena, expr); - - // rjf: title - UI_Row - { - ui_spacer(ui_em(1.f, 1.f)); - RD_Font(RD_FontSlot_Icons) - UI_FontSize(rd_font_size_from_slot(RD_FontSlot_Icons)) - UI_PrefWidth(ui_em(2.f, 1.f)) - UI_PrefHeight(ui_pct(1, 0)) - UI_TextAlignment(UI_TextAlign_Center) - UI_FlagsAdd(UI_BoxFlag_DrawTextWeak) - ui_label(rd_icon_kind_text_table[view_icon]); - UI_PrefWidth(ui_text_dim(10, 1)) - { - UI_Box *name_box = ui_build_box_from_key(UI_BoxFlag_DrawText, ui_key_zero()); - ui_box_equip_display_fstrs(name_box, &fstrs); - } - } - - RD_Palette(RD_PaletteCode_Floating) ui_divider(ui_em(1.f, 1.f)); - - // rjf: copy name - if(ui_clicked(rd_icon_buttonf(RD_IconKind_Clipboard, 0, "Copy Name"))) - { - os_set_clipboard_text(dr_string_from_fstrs(scratch.arena, &fstrs)); - ui_ctx_menu_close(); - } - - // rjf: copy full path - if(file_path.size != 0) - { - UI_Signal copy_full_path_sig = rd_icon_buttonf(RD_IconKind_Clipboard, 0, "Copy Full Path"); - String8 full_path = path_normalized_from_string(scratch.arena, file_path); - if(ui_clicked(copy_full_path_sig)) - { - os_set_clipboard_text(full_path); - ui_ctx_menu_close(); - } - if(ui_hovering(copy_full_path_sig)) UI_Tooltip - { - ui_label(full_path); - } - } - - // rjf: show in explorer - if(file_path.size != 0) - { - UI_Signal sig = rd_icon_buttonf(RD_IconKind_FolderClosedFilled, 0, "Show In Explorer"); - if(ui_clicked(sig)) - { - String8 full_path = path_normalized_from_string(scratch.arena, file_path); - os_show_in_filesystem_ui(full_path); - ui_ctx_menu_close(); - } - } - - // rjf: filter controls - if(view_rule_info->flags & RD_ViewRuleInfoFlag_CanFilter) - { - if(ui_clicked(rd_cmd_spec_button(rd_cmd_kind_info_table[RD_CmdKind_Filter].string))) - { - rd_cmd(RD_CmdKind_Filter); - ui_ctx_menu_close(); - } - if(ui_clicked(rd_cmd_spec_button(rd_cmd_kind_info_table[RD_CmdKind_ClearFilter].string))) - { - rd_cmd(RD_CmdKind_ClearFilter); - ui_ctx_menu_close(); - } - } - - // rjf: close tab - if(ui_clicked(rd_icon_buttonf(RD_IconKind_X, 0, "Close Tab"))) - { - rd_cmd(RD_CmdKind_CloseTab); - ui_ctx_menu_close(); - } - - // rjf: param tree editing -#if 0 - UI_TextPadding(ui_top_font_size()*1.5f) RD_Font(RD_FontSlot_Code) - { - Temp scratch = scratch_begin(0, 0); - String8 schema_string = view->spec->params_schema; - MD_TokenizeResult schema_tokenize = md_tokenize_from_text(scratch.arena, schema_string); - MD_ParseResult schema_parse = md_parse_from_text_tokens(scratch.arena, str8_zero(), schema_string, schema_tokenize.tokens); - MD_Node *schema_root = schema_parse.root->first; - if(!md_node_is_nil(schema_root)) - { - if(!md_node_is_nil(schema_root->first)) - { - RD_Palette(RD_PaletteCode_Floating) ui_divider(ui_em(1.f, 1.f)); - } - for MD_EachNode(key, schema_root->first) - { - UI_Row - { - MD_Node *params = view->params_roots[view->params_write_gen%ArrayCount(view->params_roots)]; - MD_Node *param_tree = md_child_from_string(params, key->string, 0); - String8 pre_edit_value = md_string_from_children(scratch.arena, param_tree); - UI_PrefWidth(ui_em(10.f, 1.f)) ui_label(key->string); - UI_Signal sig = rd_cellf(RD_CellFlag_Border|RD_CellFlag_CodeContents, 0, 0, &ws->ctx_menu_input_cursor, &ws->ctx_menu_input_mark, ws->ctx_menu_input_buffer, ws->ctx_menu_input_buffer_size, &ws->ctx_menu_input_string_size, 0, pre_edit_value, "%S##view_param", key->string); - if(ui_committed(sig)) - { - String8 new_string = str8(ws->ctx_menu_input_buffer, ws->ctx_menu_input_string_size); - rd_view_store_param(view, key->string, new_string); - } - } - } - } - scratch_end(scratch); - } -#endif - } -#endif - }break; - } - } - - scratch_end(scratch); - } -#endif - //////////////////////////// //- rjf: @window_ui_part drop-completion context menu // diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 72240ccb..e3a5a61a 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -1176,7 +1176,7 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) else if(is_top_level && evalled_cfg != &rd_nil_cfg) { RD_Cfg *cfg = evalled_cfg; - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .edit_string = row->edit_string, .flags = RD_WatchCellFlag_Button|RD_WatchCellFlag_Indented, .pct = 1.f); + rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .edit_string = row->edit_string, .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_Button|RD_WatchCellFlag_Indented, .pct = 1.f); MD_NodePtrList schemas = rd_schemas_from_name(cfg->string); for(MD_NodePtrNode *n = schemas.first; n != 0; n = n->next) { @@ -1248,7 +1248,7 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) CTRL_Entity *entity = evalled_entity; rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .edit_string = row->edit_string, - .flags = RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button, + .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button, .pct = 1.f); if(entity->kind == CTRL_EntityKind_Machine || entity->kind == CTRL_EntityKind_Process || @@ -1291,13 +1291,13 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) { rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .edit_string = row->edit_string, - .flags = RD_WatchCellFlag_Indented, .pct = 1.f); + .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_Indented, .pct = 1.f); } else { rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .edit_string = row->edit_string, - .flags = RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button|RD_WatchCellFlag_ActivateWithSingleClick, + .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button|RD_WatchCellFlag_ActivateWithSingleClick, .pct = 1.f); } } @@ -1523,14 +1523,14 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla //- rjf: cfg evaluation -> button for cfg else if(result.cfg != &rd_nil_cfg) { - result.fstrs = rd_title_fstrs_from_cfg(arena, result.cfg); + result.expr_fstrs = rd_title_fstrs_from_cfg(arena, result.cfg); result.flags |= RD_WatchCellFlag_Button; } //- rjf: entity evaluation -> button for entity else if(result.entity != &ctrl_entity_nil) { - result.fstrs = rd_title_fstrs_from_ctrl_entity(arena, result.entity, 1); + result.expr_fstrs = rd_title_fstrs_from_ctrl_entity(arena, result.entity, 1); result.flags |= RD_WatchCellFlag_Button; } @@ -1549,11 +1549,11 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla .raster_flags = rd_raster_flags_from_slot(RD_FontSlot_Icons), .color = ui_color_from_name(str8_lit("text"))); } - result.fstrs = fstrs; + result.expr_fstrs = fstrs; } else { - result.fstrs = rd_title_fstrs_from_code_name(arena, result.cmd_name); + result.expr_fstrs = rd_title_fstrs_from_code_name(arena, result.cmd_name); } result.flags |= RD_WatchCellFlag_Button; } @@ -1561,7 +1561,7 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla //- rjf: files -> button for file else if(result.file_path.size != 0) { - result.fstrs = rd_title_fstrs_from_file_path(arena, result.file_path); + result.expr_fstrs = rd_title_fstrs_from_file_path(arena, result.file_path); result.flags |= RD_WatchCellFlag_Button; } @@ -1680,12 +1680,12 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla UI_TagF("weak") { DR_FStrParams params = {rd_font_from_slot(RD_FontSlot_Main), rd_raster_flags_from_slot(RD_FontSlot_Main), ui_color_from_name(str8_lit("text")), font_size, 0, 0}; - dr_fstrs_push_new(arena, &result.fstrs, ¶ms, expr_string); + dr_fstrs_push_new(arena, &result.expr_fstrs, ¶ms, expr_string); } } else { - result.fstrs = rd_fstrs_from_code_string(arena, 1, 0, ui_color_from_name(str8_lit("text")), expr_string); + result.expr_fstrs = rd_fstrs_from_code_string(arena, 1, 0, ui_color_from_name(str8_lit("text")), expr_string); } } @@ -1726,12 +1726,12 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla String8 string = rd_value_string_from_eval(arena, rd_view_query_input(), &string_params, font, font_size, max_size_px, cell->eval); if(is_code) { - result.fstrs = rd_fstrs_from_code_string(arena, 1, 0, ui_color_from_name(str8_lit("text")), string); + result.eval_fstrs = rd_fstrs_from_code_string(arena, 1, 0, ui_color_from_name(str8_lit("text")), string); } else UI_TagF("weak") { DR_FStrParams params = {rd_font_from_slot(RD_FontSlot_Main), rd_raster_flags_from_slot(RD_FontSlot_Main), ui_color_from_name(str8_lit("text")), font_size, 0, 0}; - dr_fstrs_push_new(arena, &result.fstrs, ¶ms, string); + dr_fstrs_push_new(arena, &result.eval_fstrs, ¶ms, string); result.flags |= RD_WatchCellFlag_IsNonCode; } } @@ -1757,7 +1757,7 @@ rd_info_from_watch_row_cell(Arena *arena, EV_Row *row, EV_StringFlags string_fla dr_fstrs_push_new(arena, &fstrs, ¶ms, push_str8f(arena, "(PID: %I64u)", pid)); dr_fstrs_push_new(arena, &fstrs, ¶ms, str8_lit(" ")); dr_fstrs_push_new(arena, &fstrs, ¶ms, name); - result.fstrs = fstrs; + result.expr_fstrs = fstrs; }break; } scratch_end(scratch); diff --git a/src/raddbg/raddbg_views.h b/src/raddbg/raddbg_views.h index d3b2b37e..03f8bbb0 100644 --- a/src/raddbg/raddbg_views.h +++ b/src/raddbg/raddbg_views.h @@ -112,7 +112,8 @@ struct RD_WatchRowCellInfo CTRL_Entity *entity; String8 cmd_name; String8 file_path; - DR_FStrList fstrs; + DR_FStrList expr_fstrs; + DR_FStrList eval_fstrs; String8 description; String8 error_tooltip; String8 inheritance_tooltip; diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index c44044c5..e208376d 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -3523,164 +3523,159 @@ rd_cell(RD_CellParams *params, String8 string) F32 cursor_off = 0; UI_Parent(scrollable_box) { + Temp scratch = scratch_begin(0, 0); + + //- rjf: compute fancy strings + DR_FStrList fstrs = {0}; + { + //- rjf: (not editing) + if(!is_focus_active && !is_focus_active_disabled && params->expr_fstrs.total_size != 0) + { + fstrs = params->expr_fstrs; + } + else if(!is_focus_active && !is_focus_active_disabled && params->eval_fstrs.total_size != 0) + { + fstrs = params->eval_fstrs; + } + else if(!is_focus_active && !is_focus_active_disabled && params->flags & RD_CellFlag_CodeContents && params->pre_edit_value.size != 0) + { + String8 display_string = params->pre_edit_value; + fstrs = rd_fstrs_from_code_string(scratch.arena, 1, 0, ui_color_from_name(str8_lit("text")), display_string); + } + else if(!is_focus_active && !is_focus_active_disabled) + { + String8 display_string = params->pre_edit_value; + if(params->pre_edit_value.size == 0) + { + display_string = ui_display_part_from_key_string(string); + } + UI_TagF("weak") + { + DR_FStrParams params = {ui_top_font(), ui_top_text_raster_flags(), ui_color_from_name(str8_lit("text")), ui_top_font_size()}; + dr_fstrs_push_new(scratch.arena, &fstrs, ¶ms, display_string); + } + } + + //- rjf: (editing) + else if((is_focus_active || is_focus_active_disabled) && params->flags & RD_CellFlag_CodeContents) + { + String8 edit_string = str8(params->edit_buffer, params->edit_string_size_out[0]); + DR_FStrList code_fstrs = rd_fstrs_from_code_string(scratch.arena, 1.f, 0, ui_color_from_name(str8_lit("text")), edit_string); + if(autocomplete_hint_string.size != 0) + { + String8 query_word = rd_lister_query_word_from_input_string_off(edit_string, params->cursor->column-1); + String8 autocomplete_append_string = str8_skip(autocomplete_hint_string, query_word.size); + U64 off = 0; + U64 cursor_off = params->cursor->column-1; + DR_FStrNode *prev_n = 0; + for(DR_FStrNode *n = code_fstrs.first; n != 0; n = n->next) + { + if(off <= cursor_off && cursor_off <= off+n->v.string.size) + { + prev_n = n; + break; + } + off += n->v.string.size; + } + { + DR_FStrNode *autocomp_fstr_n = push_array(scratch.arena, DR_FStrNode, 1); + DR_FStr *fstr = &autocomp_fstr_n->v; + fstr->string = autocomplete_append_string; + fstr->params.font = ui_top_font(); + fstr->params.color = ui_color_from_name(str8_lit("text")); + fstr->params.color.w *= 0.5f; + fstr->params.size = ui_top_font_size(); + autocomp_fstr_n->next = prev_n ? prev_n->next : 0; + if(prev_n != 0) + { + prev_n->next = autocomp_fstr_n; + } + if(prev_n == 0) + { + code_fstrs.first = code_fstrs.last = autocomp_fstr_n; + } + if(prev_n != 0 && prev_n->next == 0) + { + code_fstrs.last = autocomp_fstr_n; + } + code_fstrs.node_count += 1; + code_fstrs.total_size += autocomplete_hint_string.size; + if(prev_n != 0 && cursor_off - off < prev_n->v.string.size) + { + String8 full_string = prev_n->v.string; + U64 chop_amt = full_string.size - (cursor_off - off); + prev_n->v.string = str8_chop(full_string, chop_amt); + code_fstrs.total_size -= chop_amt; + if(chop_amt != 0) + { + String8 post_cursor = str8_skip(full_string, cursor_off - off); + DR_FStrNode *post_fstr_n = push_array(scratch.arena, DR_FStrNode, 1); + DR_FStr *post_fstr = &post_fstr_n->v; + MemoryCopyStruct(post_fstr, &prev_n->v); + post_fstr->string = post_cursor; + if(autocomp_fstr_n->next == 0) + { + code_fstrs.last = post_fstr_n; + } + post_fstr_n->next = autocomp_fstr_n->next; + autocomp_fstr_n->next = post_fstr_n; + code_fstrs.node_count += 1; + code_fstrs.total_size += post_cursor.size; + } + } + } + } + fstrs = code_fstrs; + } + else if((is_focus_active || is_focus_active_disabled) && !(params->flags & RD_CellFlag_CodeContents)) + { + String8 edit_string = str8(params->edit_buffer, params->edit_string_size_out[0]); + DR_FStrParams params = {ui_top_font(), ui_top_text_raster_flags(), ui_color_from_name(str8_lit("text")), ui_top_font_size()}; + dr_fstrs_push_new(scratch.arena, &fstrs, ¶ms, edit_string); + } + } + + //- rjf: compute fuzzy match ranges + FuzzyMatchRangeList fuzzy_matches = {0}; + if(params->search_needle.size != 0) + { + fuzzy_matches = dr_fuzzy_match_find_from_fstrs(scratch.arena, &fstrs, params->search_needle); + } + + //- rjf: build textual content if(ui_top_text_alignment() == UI_TextAlign_Left && (params->flags & (RD_CellFlag_Expander|RD_CellFlag_ExpanderSpace|RD_CellFlag_ExpanderPlaceholder)) == 0) { ui_spacer(ui_em(0.5f, 1.f)); } - if(!is_focus_active && !is_focus_active_disabled && params->fstrs.total_size != 0) + if(is_focus_active) { - UI_Box *label = ui_build_box_from_key(UI_BoxFlag_DrawText, ui_key_zero()); - ui_box_equip_display_fstrs(label, ¶ms->fstrs); - if(params->fuzzy_matches != 0) - { - ui_box_equip_fuzzy_match_ranges(label, params->fuzzy_matches); - } + ui_set_next_pref_width(ui_text_dim(1, 1)); + ui_set_next_flags(UI_BoxFlag_DisableTextTrunc); } - else if(!is_focus_active && !is_focus_active_disabled && params->flags & RD_CellFlag_CodeContents) - { - String8 display_string = ui_display_part_from_key_string(string); - if(!(params->flags & RD_CellFlag_PreferDisplayString) && params->pre_edit_value.size != 0) - { - display_string = params->pre_edit_value; - UI_Box *box = rd_code_label(1.f, 1, ui_color_from_name(str8_lit("text")), display_string); - if(params->fuzzy_matches != 0) - { - ui_box_equip_fuzzy_match_ranges(box, params->fuzzy_matches); - } - } - else if(params->flags & RD_CellFlag_DisplayStringIsCode) - { - UI_Box *box = rd_code_label(1.f, 1, ui_color_from_name(str8_lit("text")), display_string); - if(params->fuzzy_matches != 0) - { - ui_box_equip_fuzzy_match_ranges(box, params->fuzzy_matches); - } - } - else UI_TagF("weak") - { - UI_Box *box = ui_label(display_string).box; - if(params->fuzzy_matches != 0) - { - ui_box_equip_fuzzy_match_ranges(box, params->fuzzy_matches); - } - } - } - else if(!is_focus_active && !is_focus_active_disabled && !(params->flags & RD_CellFlag_CodeContents)) - { - String8 display_string = ui_display_part_from_key_string(string); - if(!(params->flags & RD_CellFlag_PreferDisplayString) && params->pre_edit_value.size != 0) - { - display_string = params->pre_edit_value; - } - else - { - ui_set_next_tag(str8_lit("weak")); - } - UI_Box *box = ui_label(display_string).box; - if(params->fuzzy_matches != 0) - { - ui_box_equip_fuzzy_match_ranges(box, params->fuzzy_matches); - } - } - else if((is_focus_active || is_focus_active_disabled) && params->flags & RD_CellFlag_CodeContents) + UI_Box *text_box = ui_build_box_from_stringf(UI_BoxFlag_DrawText, "###text_box"); + ui_box_equip_display_fstrs(text_box, &fstrs); + ui_box_equip_fuzzy_match_ranges(text_box, &fuzzy_matches); + if(is_focus_active || is_focus_active_disabled) { String8 edit_string = str8(params->edit_buffer, params->edit_string_size_out[0]); - Temp scratch = scratch_begin(0, 0); - F32 total_text_width = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), edit_string).x; - F32 total_editstr_width = total_text_width - !!(params->flags & (RD_CellFlag_Expander|RD_CellFlag_ExpanderSpace|RD_CellFlag_ExpanderPlaceholder)) * expander_size_px; - ui_set_next_pref_width(ui_px(total_editstr_width+ui_top_font_size()*2, 0.f)); - UI_Box *editstr_box = ui_build_box_from_stringf(UI_BoxFlag_DrawText|UI_BoxFlag_DisableTextTrunc, "###editstr"); - DR_FStrList code_fstrs = rd_fstrs_from_code_string(scratch.arena, 1.f, 0, ui_color_from_name(str8_lit("text")), edit_string); - if(autocomplete_hint_string.size != 0) - { - String8 query_word = rd_lister_query_word_from_input_string_off(edit_string, params->cursor->column-1); - String8 autocomplete_append_string = str8_skip(autocomplete_hint_string, query_word.size); - U64 off = 0; - U64 cursor_off = params->cursor->column-1; - DR_FStrNode *prev_n = 0; - for(DR_FStrNode *n = code_fstrs.first; n != 0; n = n->next) - { - if(off <= cursor_off && cursor_off <= off+n->v.string.size) - { - prev_n = n; - break; - } - off += n->v.string.size; - } - { - DR_FStrNode *autocomp_fstr_n = push_array(scratch.arena, DR_FStrNode, 1); - DR_FStr *fstr = &autocomp_fstr_n->v; - fstr->string = autocomplete_append_string; - fstr->params.font = ui_top_font(); - fstr->params.color = ui_color_from_name(str8_lit("text")); - fstr->params.color.w *= 0.5f; - fstr->params.size = ui_top_font_size(); - autocomp_fstr_n->next = prev_n ? prev_n->next : 0; - if(prev_n != 0) - { - prev_n->next = autocomp_fstr_n; - } - if(prev_n == 0) - { - code_fstrs.first = code_fstrs.last = autocomp_fstr_n; - } - if(prev_n != 0 && prev_n->next == 0) - { - code_fstrs.last = autocomp_fstr_n; - } - code_fstrs.node_count += 1; - code_fstrs.total_size += autocomplete_hint_string.size; - if(prev_n != 0 && cursor_off - off < prev_n->v.string.size) - { - String8 full_string = prev_n->v.string; - U64 chop_amt = full_string.size - (cursor_off - off); - prev_n->v.string = str8_chop(full_string, chop_amt); - code_fstrs.total_size -= chop_amt; - if(chop_amt != 0) - { - String8 post_cursor = str8_skip(full_string, cursor_off - off); - DR_FStrNode *post_fstr_n = push_array(scratch.arena, DR_FStrNode, 1); - DR_FStr *post_fstr = &post_fstr_n->v; - MemoryCopyStruct(post_fstr, &prev_n->v); - post_fstr->string = post_cursor; - if(autocomp_fstr_n->next == 0) - { - code_fstrs.last = post_fstr_n; - } - post_fstr_n->next = autocomp_fstr_n->next; - autocomp_fstr_n->next = post_fstr_n; - code_fstrs.node_count += 1; - code_fstrs.total_size += post_cursor.size; - } - } - } - } - ui_box_equip_display_fstrs(editstr_box, &code_fstrs); UI_LineEditDrawData *draw_data = push_array(ui_build_arena(), UI_LineEditDrawData, 1); draw_data->edited_string = push_str8_copy(ui_build_arena(), edit_string); draw_data->cursor = params->cursor[0]; draw_data->mark = params->mark[0]; - ui_box_equip_custom_draw(editstr_box, ui_line_edit_draw, draw_data); - mouse_pt = txt_pt(1, 1+ui_box_char_pos_from_xy(editstr_box, ui_mouse())); - cursor_off = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), str8_prefix(edit_string, params->cursor->column-1)).x; - scratch_end(scratch); - } - else if((is_focus_active || is_focus_active_disabled) && !(params->flags & RD_CellFlag_CodeContents)) - { - String8 edit_string = str8(params->edit_buffer, params->edit_string_size_out[0]); - F32 total_text_width = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), edit_string).x; - F32 total_editstr_width = total_text_width - !!(params->flags & (RD_CellFlag_Expander|RD_CellFlag_ExpanderSpace|RD_CellFlag_ExpanderPlaceholder)) * expander_size_px; - ui_set_next_pref_width(ui_px(total_editstr_width+ui_top_font_size()*2, 0.f)); - UI_Box *editstr_box = ui_build_box_from_stringf(UI_BoxFlag_DrawText|UI_BoxFlag_DisableTextTrunc, "###editstr"); - UI_LineEditDrawData *draw_data = push_array(ui_build_arena(), UI_LineEditDrawData, 1); - draw_data->edited_string = push_str8_copy(ui_build_arena(), edit_string); - draw_data->cursor = params->cursor[0]; - draw_data->mark = params->mark[0]; - ui_box_equip_display_string(editstr_box, edit_string); - ui_box_equip_custom_draw(editstr_box, ui_line_edit_draw, draw_data); - mouse_pt = txt_pt(1, 1+ui_box_char_pos_from_xy(editstr_box, ui_mouse())); + ui_box_equip_custom_draw(text_box, ui_line_edit_draw, draw_data); + Vec2F32 text2mouse = sub_2f32(ui_mouse(), ui_box_text_position(text_box)); + FNT_Tag font = ui_top_font(); + F32 font_size = ui_top_font_size(); + if(params->flags & RD_CellFlag_CodeContents) + { + font = rd_font_from_slot(RD_FontSlot_Code); + } + U64 mouse_pt_off = fnt_char_pos_from_tag_size_string_p(font, font_size, 0, ui_top_tab_size(), edit_string, text2mouse.x); + mouse_pt = txt_pt(1, 1+mouse_pt_off); cursor_off = fnt_dim_from_tag_size_string(ui_top_font(), ui_top_font_size(), 0, ui_top_tab_size(), str8_prefix(edit_string, params->cursor->column-1)).x; } + + scratch_end(scratch); } ////////////////////////////// @@ -3722,7 +3717,7 @@ rd_cell(RD_CellParams *params, String8 string) F32 visible_dim_px = dim_2f32(box->rect).x - expander_size_px - ui_top_font_size()*params->depth; if(visible_dim_px > 0) { - Rng1F32 cursor_range_px = r1f32(cursor_off-ui_top_font_size()*2.f, cursor_off+ui_top_font_size()*2.f); + Rng1F32 cursor_range_px = r1f32(cursor_off-ui_top_font_size()*2.f, cursor_off+ui_top_font_size()*1.f); Rng1F32 visible_range_px = r1f32(scrollable_box->view_off_target.x, scrollable_box->view_off_target.x + visible_dim_px); cursor_range_px.min = ClampBot(0, cursor_range_px.min); cursor_range_px.max = ClampBot(0, cursor_range_px.max); diff --git a/src/raddbg/raddbg_widgets.h b/src/raddbg/raddbg_widgets.h index e817b8c4..c657689c 100644 --- a/src/raddbg/raddbg_widgets.h +++ b/src/raddbg/raddbg_widgets.h @@ -33,8 +33,6 @@ enum RD_CellFlag_Border = (1<<9), RD_CellFlag_NoBackground = (1<<10), RD_CellFlag_Button = (1<<11), - RD_CellFlag_PreferDisplayString = (1<<12), - RD_CellFlag_DisplayStringIsCode = (1<<13), }; typedef struct RD_CellParams RD_CellParams; @@ -43,9 +41,10 @@ struct RD_CellParams //- rjf: catchall parameters RD_CellFlags flags; S32 depth; - FuzzyMatchRangeList *fuzzy_matches; String8 pre_edit_value; - DR_FStrList fstrs; + DR_FStrList expr_fstrs; + DR_FStrList eval_fstrs; + String8 search_needle; String8 description; //- rjf: expander r/w info