mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-30 17:43:20 -08:00
expand cell capabilities to have meta data (expr name/description/etc.), as well as value editor, as well as fancy value editing widgets, all in one cell
This commit is contained in:
1 parent
78b5582e95
commit
d9d102cb56
11 files changed
+313
-204
No files matched your search
+195
-158
@@ -3148,6 +3148,7 @@ internal UI_Signal
|
||||
rd_cell(RD_CellParams *params, String8 string)
|
||||
{
|
||||
ProfBeginFunction();
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: unpack visual metrics
|
||||
@@ -3171,6 +3172,140 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
B32 is_focus_hot_disabled = (!is_focus_hot && ui_top_focus_hot() == UI_FocusKind_On);
|
||||
B32 is_focus_active_disabled = (!is_focus_active && ui_top_focus_active() == UI_FocusKind_On);
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: determine which sub-cell components we'll build
|
||||
//
|
||||
// (the base line edit textual label / editor is always built, but this can be enriched
|
||||
// with extra widgets & metadata)
|
||||
//
|
||||
B32 build_toggle_switch = !!(params->flags & RD_CellFlag_ToggleSwitch && !is_focus_active);
|
||||
B32 build_slider = !!(params->flags & RD_CellFlag_Slider && !is_focus_active);
|
||||
B32 build_lhs_name_desc = (params->meta_fstrs.node_count != 0 || params->description.size != 0);
|
||||
DR_FStrList lhs_name_fstrs = params->meta_fstrs;
|
||||
DR_FStrList value_name_fstrs = params->value_fstrs;
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: determine autocompletion string
|
||||
//
|
||||
String8 autocomplete_hint_string = {0};
|
||||
{
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(evt->kind == UI_EventKind_AutocompleteHint)
|
||||
{
|
||||
autocomplete_hint_string = evt->string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: compute editable fancy strings
|
||||
//
|
||||
DR_FStrList fstrs = {0};
|
||||
{
|
||||
//- rjf: (not editing)
|
||||
if(!is_focus_active && !is_focus_active_disabled && value_name_fstrs.total_size != 0)
|
||||
{
|
||||
fstrs = value_name_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: build top-level box
|
||||
//
|
||||
@@ -3235,29 +3370,78 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
//- rjf: build left-hand-side container box
|
||||
//
|
||||
UI_Box *lhs_box = &ui_nil_box;
|
||||
UI_Parent(box) UI_WidthFill UI_ChildLayoutAxis(Axis2_Y)
|
||||
if(build_lhs_name_desc)
|
||||
{
|
||||
lhs_box = ui_build_box_from_stringf(0, "lhs_box");
|
||||
UI_Parent(lhs_box)
|
||||
UI_Parent(box) UI_WidthFill UI_ChildLayoutAxis(Axis2_Y)
|
||||
{
|
||||
ui_spacer(ui_em(3.f, 0.f));
|
||||
lhs_box = ui_build_box_from_stringf(0, "lhs_box");
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build line edit container box
|
||||
//
|
||||
UI_Box *edit_box = &ui_nil_box;
|
||||
UI_Parent(box) if(fstrs.node_count != 0 || (!is_focus_active && !is_focus_active_disabled))
|
||||
{
|
||||
UI_Size edit_box_size = ui_pct(1, 0);
|
||||
if(build_lhs_name_desc)
|
||||
{
|
||||
edit_box_size = ui_px(dr_dim_from_fstrs(&fstrs).x + 10, 1.f);
|
||||
ui_set_next_text_alignment(UI_TextAlign_Center);
|
||||
}
|
||||
UI_PrefWidth(edit_box_size)
|
||||
edit_box = ui_build_box_from_stringf(0, "edit_box");
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build scrollable container box
|
||||
//
|
||||
UI_Box *scrollable_box = &ui_nil_box;
|
||||
UI_Parent(lhs_box) UI_WidthFill UI_HeightFill
|
||||
if(edit_box != &ui_nil_box)
|
||||
{
|
||||
scrollable_box = ui_build_box_from_stringf(is_focus_active*(UI_BoxFlag_AllowOverflowX), "scroll_box_%p", params->edit_buffer);
|
||||
UI_Parent(edit_box) UI_WidthFill UI_HeightFill
|
||||
{
|
||||
scrollable_box = ui_build_box_from_stringf(is_focus_active*(UI_BoxFlag_AllowOverflowX), "scroll_box_%p", params->edit_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build left-hand-side name/desc box
|
||||
//
|
||||
if(build_lhs_name_desc) UI_Parent(lhs_box) UI_Padding(ui_em(3.f, 0.f)) UI_WidthFill UI_HeightFill
|
||||
{
|
||||
FuzzyMatchRangeList fuzzy_matches = {0};
|
||||
if(params->search_needle.size != 0)
|
||||
{
|
||||
fuzzy_matches = dr_fuzzy_match_find_from_fstrs(scratch.arena, &lhs_name_fstrs, params->search_needle);
|
||||
}
|
||||
UI_Row
|
||||
{
|
||||
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));
|
||||
}
|
||||
UI_Box *name_box = ui_build_box_from_key(UI_BoxFlag_DrawText, ui_key_zero());
|
||||
ui_box_equip_display_fstrs(name_box, &lhs_name_fstrs);
|
||||
ui_box_equip_fuzzy_match_ranges(name_box, &fuzzy_matches);
|
||||
}
|
||||
if(params->description.size != 0) RD_Font(RD_FontSlot_Main) UI_FontSize(ui_top_font_size()*0.85f)
|
||||
{
|
||||
UI_Row
|
||||
{
|
||||
ui_spacer(ui_em(0.5f, 1.f));
|
||||
UI_Box *desc_box = ui_label(params->description).box;
|
||||
FuzzyMatchRangeList desc_fuzzy_matches = fuzzy_match_find(scratch.arena, params->search_needle, params->description);
|
||||
ui_box_equip_fuzzy_match_ranges(desc_box, &desc_fuzzy_matches);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build toggle-switch
|
||||
//
|
||||
if(params->flags & RD_CellFlag_ToggleSwitch && !is_focus_active)
|
||||
UI_Parent(box)
|
||||
if(build_toggle_switch) UI_Parent(box)
|
||||
{
|
||||
B32 is_toggled = !!params->toggled_out[0];
|
||||
F32 toggle_t = ui_anim(ui_key_from_stringf(key, "toggled"), (F32)is_toggled, .initial = (F32)is_toggled);
|
||||
@@ -3307,8 +3491,7 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
//////////////////////////////
|
||||
//- rjf: build slider
|
||||
//
|
||||
if(params->flags & RD_CellFlag_Slider && !is_focus_active)
|
||||
UI_Parent(box)
|
||||
if(build_slider) UI_Parent(box)
|
||||
{
|
||||
F32 height_px = ceil_f32(ui_top_font_size() * 1.75f);
|
||||
F32 padding_px = ceil_f32((ui_top_px_height() - height_px) / 2.f);
|
||||
@@ -3438,20 +3621,6 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
sig.f |= UI_SignalFlag_Commit;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: determine autocompletion string
|
||||
//
|
||||
String8 autocomplete_hint_string = {0};
|
||||
{
|
||||
for(UI_Event *evt = 0; ui_next_event(&evt);)
|
||||
{
|
||||
if(evt->kind == UI_EventKind_AutocompleteHint)
|
||||
{
|
||||
autocomplete_hint_string = evt->string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: take navigation actions for editing
|
||||
//
|
||||
@@ -3521,128 +3690,13 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
//
|
||||
TxtPt mouse_pt = {0};
|
||||
F32 cursor_off = 0;
|
||||
UI_Parent(scrollable_box)
|
||||
if(scrollable_box != &ui_nil_box) 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));
|
||||
@@ -3674,24 +3728,6 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
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);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: build description
|
||||
//
|
||||
if(params->description.size != 0) UI_Parent(lhs_box) UI_HeightFill RD_Font(RD_FontSlot_Main) UI_FontSize(ui_top_font_size()*0.85f)
|
||||
{
|
||||
UI_Row
|
||||
{
|
||||
ui_spacer(ui_em(0.5f, 1.f));
|
||||
ui_label(params->description);
|
||||
}
|
||||
}
|
||||
UI_Parent(lhs_box)
|
||||
{
|
||||
ui_spacer(ui_em(3.f, 0.f));
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
@@ -3741,6 +3777,7 @@ rd_cell(RD_CellParams *params, String8 string)
|
||||
if(is_auto_focus_active) { ui_pop_focus_active(); }
|
||||
|
||||
ProfEnd();
|
||||
scratch_end(scratch);
|
||||
return sig;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user