checkpoint in first pass at new unified code view impl.; start setting up unified top-level code ctx menu

This commit is contained in:
Ryan Fleury
2024-06-25 12:00:50 -07:00
parent d12c5ec2e8
commit 010d5609c6
9 changed files with 275 additions and 81 deletions
+4 -3
View File
@@ -6643,6 +6643,7 @@ df_core_init(CmdLine *cmdln, DF_StateDeltaHistory *hist)
df_state = push_array(arena, DF_State, 1);
df_state->arena = arena;
df_state->root_cmd_arena = arena_alloc();
df_state->output_log_key = hs_hash_from_data(str8_lit("df_output_log_key"));
df_state->entities_arena = arena_alloc__sized(GB(64), KB(64));
df_state->entities_root = &df_g_nil_entity;
df_state->entities_base = push_array(df_state->entities_arena, DF_Entity, 0);
@@ -7129,9 +7130,9 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt)
case CTRL_EventKind_DebugString:
{
//MTX_Op op = {r1u64(max_U64, max_U64), event->string};
//mtx_push_op(u128_zero(), op);
#if 1
MTX_Op op = {r1u64(max_U64, max_U64), event->string};
mtx_push_op(df_state->output_log_key, op);
#if 0
String8 string = event->string;
DF_Entity *root = df_entity_root();
DF_Entity *thread = df_entity_from_ctrl_handle(event->machine_id, event->entity);
+3
View File
@@ -1171,6 +1171,9 @@ struct DF_State
Arena *root_cmd_arena;
DF_CmdList root_cmds;
// rjf: output log key
U128 output_log_key;
// rjf: history cache
DF_StateDeltaHistory *hist;
+23 -9
View File
@@ -1026,6 +1026,7 @@ df_window_open(Vec2F32 size, OS_Handle preferred_monitor, DF_CfgSrc cfg_src)
window->r = r_window_equip(window->os);
window->ui = ui_state_alloc();
window->view_state_hist = df_state_delta_history_alloc();
window->code_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_code_ctx_menu_"));
window->entity_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_entity_ctx_menu_"));
window->tab_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_tab_ctx_menu_"));
window->hover_eval_arena = arena_alloc();
@@ -3688,6 +3689,16 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
}
}
//- rjf: code ctx menu
UI_CtxMenu(ws->code_ctx_menu_key)
UI_PrefWidth(ui_em(30.f, 1.f))
DF_Palette(DF_PaletteCode_ImplicitButton)
{
ui_buttonf("Foo");
ui_buttonf("Bar");
ui_buttonf("Baz");
}
//- rjf: entity menu
UI_CtxMenu(ws->entity_ctx_menu_key)
UI_PrefWidth(ui_em(30.f, 1.f))
@@ -7468,16 +7479,19 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds)
DF_View *list_first = list_firsts[idx];
for(DF_View *view = list_first; !df_view_is_nil(view); view = view->next)
{
if(abs_f32(view->loading_t_target - view->loading_t) > 0.01f ||
abs_f32(view->scroll_pos.x.off) > 0.01f ||
abs_f32(view->scroll_pos.y.off) > 0.01f ||
abs_f32(view->is_filtering_t - (F32)!!view->is_filtering))
if(window_is_focused)
{
df_gfx_request_frame();
}
if(view->loading_t_target != 0 && view == df_selected_tab_from_panel(panel))
{
df_gfx_request_frame();
if(abs_f32(view->loading_t_target - view->loading_t) > 0.01f ||
abs_f32(view->scroll_pos.x.off) > 0.01f ||
abs_f32(view->scroll_pos.y.off) > 0.01f ||
abs_f32(view->is_filtering_t - (F32)!!view->is_filtering))
{
df_gfx_request_frame();
}
if(view->loading_t_target != 0 && view == df_selected_tab_from_panel(panel))
{
df_gfx_request_frame();
}
}
view->loading_t += (view->loading_t_target - view->loading_t) * rate;
view->is_filtering_t += ((F32)!!view->is_filtering - view->is_filtering_t) * fast_rate;
+6
View File
@@ -569,6 +569,12 @@ struct DF_Window
B32 menu_bar_key_held;
B32 menu_bar_focus_press_started;
// rjf: code context menu state
UI_Key code_ctx_menu_key;
DF_Handle code_ctx_menu_entity;
U128 code_ctx_menu_text_key;
TxtRng code_ctx_menu_range;
// rjf: entity context menu state
UI_Key entity_ctx_menu_key;
DF_Handle entity_ctx_menu_entity;
+222 -66
View File
@@ -387,7 +387,7 @@ df_code_view_init(DF_CodeViewState *cv, DF_View *view)
}
internal void
df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, U128 key, TXT_LangKind lang_kind)
df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info)
{
for(DF_CmdNode *n = cmds->first; n != 0; n = n->next)
{
@@ -433,22 +433,17 @@ df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewStat
TXT_Scope *txt_scope = txt_scope_open();
HS_Scope *hs_scope = hs_scope_open();
{
// rjf: unpack entity info
U128 hash = {0};
TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
String8 data = hs_data_from_hash(hs_scope, hash);
// rjf: determine expression range
Rng1U64 expr_range = {0};
{
TxtRng selection_range = txt_rng(cv->cursor, cv->mark);
if(txt_pt_match(selection_range.min, selection_range.max))
{
expr_range = txt_expr_off_range_from_info_data_pt(&text_info, data, cv->cursor);
expr_range = txt_expr_off_range_from_info_data_pt(info, data, cv->cursor);
}
else
{
expr_range = r1u64(txt_off_from_info_pt(&text_info, selection_range.min), txt_off_from_info_pt(&text_info, selection_range.max));
expr_range = r1u64(txt_off_from_info_pt(info, selection_range.min), txt_off_from_info_pt(info, selection_range.max));
}
}
@@ -471,22 +466,17 @@ df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewStat
TXT_Scope *txt_scope = txt_scope_open();
HS_Scope *hs_scope = hs_scope_open();
{
// rjf: unpack entity info
U128 hash = {0};
TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
String8 data = hs_data_from_hash(hs_scope, hash);
// rjf: determine expression range
Rng1U64 expr_range = {0};
{
TxtRng selection_range = txt_rng(cv->cursor, cv->mark);
if(txt_pt_match(selection_range.min, selection_range.max))
{
expr_range = txt_expr_off_range_from_info_data_pt(&text_info, data, cv->cursor);
expr_range = txt_expr_off_range_from_info_data_pt(info, data, cv->cursor);
}
else
{
expr_range = r1u64(txt_off_from_info_pt(&text_info, selection_range.min), txt_off_from_info_pt(&text_info, selection_range.max));
expr_range = r1u64(txt_off_from_info_pt(info, selection_range.min), txt_off_from_info_pt(info, selection_range.max));
}
}
@@ -509,7 +499,7 @@ df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewStat
}
internal void
df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, U128 key, TXT_LangKind lang_kind)
df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info)
{
ProfBeginFunction();
Temp scratch = scratch_begin(0, 0);
@@ -528,9 +518,8 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
F32 code_line_height = ceil_f32(f_line_height_from_metrics(&code_font_metrics) * 1.5f);
F32 big_glyph_advance = f_dim_from_tag_size_string(code_font, code_font_size, 0, 0, str8_lit("H")).x;
Vec2F32 panel_box_dim = dim_2f32(rect);
Vec2F32 bottom_bar_dim = {panel_box_dim.x, ui_em(1.8f, 0).value};
F32 scroll_bar_dim = floor_f32(ui_top_font_size()*1.5f);
Vec2F32 code_area_dim = v2f32(panel_box_dim.x - scroll_bar_dim, panel_box_dim.y - scroll_bar_dim - bottom_bar_dim.y);
Vec2F32 code_area_dim = v2f32(panel_box_dim.x - scroll_bar_dim, panel_box_dim.y - scroll_bar_dim);
S64 num_possible_visible_lines = (S64)(code_area_dim.y/code_line_height)+1;
//////////////////////////////
@@ -542,22 +531,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
EVAL_ParseCtx parse_ctx = df_eval_parse_ctx_from_process_vaddr(di_scope, process, rip_vaddr);
//////////////////////////////
//- rjf: unpack text info
//
U128 hash = {0};
TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
String8 data = hs_data_from_hash(hs_scope, hash);
B32 text_info_is_ready = (text_info.lines_count != 0);
//////////////////////////////
//- rjf: buffer is pending -> equip view with loading information
//
if(!text_info_is_ready)
{
df_view_equip_loading_info(view, 1, text_info.bytes_processed, text_info.bytes_to_process);
}
//////////////////////////////
//- rjf: determine visible line range / count
//
@@ -567,12 +540,12 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
view->scroll_pos.y.idx + 1 + num_possible_visible_lines);
U64 visible_line_count = 0;
{
visible_line_num_range.min = Clamp(1, visible_line_num_range.min, (S64)text_info.lines_count);
visible_line_num_range.max = Clamp(1, visible_line_num_range.max, (S64)text_info.lines_count);
visible_line_num_range.min = Clamp(1, visible_line_num_range.min, (S64)info->lines_count);
visible_line_num_range.max = Clamp(1, visible_line_num_range.max, (S64)info->lines_count);
visible_line_num_range.min = Max(1, visible_line_num_range.min);
visible_line_num_range.max = Max(1, visible_line_num_range.max);
target_visible_line_num_range.min = Clamp(1, target_visible_line_num_range.min, (S64)text_info.lines_count);
target_visible_line_num_range.max = Clamp(1, target_visible_line_num_range.max, (S64)text_info.lines_count);
target_visible_line_num_range.min = Clamp(1, target_visible_line_num_range.min, (S64)info->lines_count);
target_visible_line_num_range.max = Clamp(1, target_visible_line_num_range.max, (S64)info->lines_count);
target_visible_line_num_range.min = Max(1, target_visible_line_num_range.min);
target_visible_line_num_range.max = Max(1, target_visible_line_num_range.max);
visible_line_count = (U64)dim_1s64(visible_line_num_range)+1;
@@ -584,11 +557,11 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
S64 line_size_x = 0;
Rng1S64 scroll_idx_rng[Axis2_COUNT] = {0};
{
line_size_x = (text_info.lines_max_size*big_glyph_advance*3)/2;
line_size_x = (info->lines_max_size*big_glyph_advance*3)/2;
line_size_x = ClampBot(line_size_x, (S64)big_glyph_advance*120);
line_size_x = ClampBot(line_size_x, (S64)code_area_dim.x);
scroll_idx_rng[Axis2_X] = r1s64(0, line_size_x-(S64)code_area_dim.x);
scroll_idx_rng[Axis2_Y] = r1s64(0, (S64)text_info.lines_count-1);
scroll_idx_rng[Axis2_Y] = r1s64(0, (S64)info->lines_count-1);
}
//////////////////////////////
@@ -597,7 +570,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
F32 priority_margin_width_px = big_glyph_advance*3.5f;
F32 catchall_margin_width_px = big_glyph_advance*3.5f;
F32 line_num_width_px = big_glyph_advance * (log10(visible_line_num_range.max) + 3);
TXT_LineTokensSlice slice = txt_line_tokens_slice_from_info_data_line_range(scratch.arena, &text_info, data, visible_line_num_range);
TXT_LineTokensSlice slice = txt_line_tokens_slice_from_info_data_line_range(scratch.arena, info, data, visible_line_num_range);
//////////////////////////////
//- rjf: get active search query
@@ -620,7 +593,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//- rjf: prepare code slice info bundle, for the viewable region of text
//
DF_CodeSliceParams code_slice_params = {0};
if(text_info_is_ready)
{
// rjf: fill basics
code_slice_params.flags = DF_CodeSliceFlag_PriorityMargin|DF_CodeSliceFlag_CatchallMargin|DF_CodeSliceFlag_LineNums|DF_CodeSliceFlag_Clickable;
@@ -650,8 +622,8 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
U64 line_idx = visible_line_num_range.min-1;
for(U64 visible_line_idx = 0; visible_line_idx < visible_line_count; visible_line_idx += 1, line_idx += 1, line_num += 1)
{
code_slice_params.line_text[visible_line_idx] = str8_substr(data, text_info.lines_ranges[line_idx]);
code_slice_params.line_ranges[visible_line_idx] = text_info.lines_ranges[line_idx];
code_slice_params.line_text[visible_line_idx] = str8_substr(data, info->lines_ranges[line_idx]);
code_slice_params.line_ranges[visible_line_idx] = info->lines_ranges[line_idx];
code_slice_params.line_tokens[visible_line_idx] = slice.line_tokens[visible_line_idx];
}
}
@@ -661,7 +633,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//- rjf: build container
//
UI_Box *container_box = &ui_g_nil_box;
if(text_info_is_ready)
{
ui_set_next_pref_width(ui_px(code_area_dim.x, 1));
ui_set_next_pref_height(ui_px(code_area_dim.y, 1));
@@ -685,7 +656,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: do searching operations
//
if(text_info_is_ready)
{
//- rjf: find text (forward)
if(cv->find_text_fwd.size != 0)
@@ -694,14 +664,14 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
B32 found = 0;
B32 first = 1;
S64 line_num_start = cv->cursor.line;
S64 line_num_last = (S64)text_info.lines_count;
S64 line_num_last = (S64)info->lines_count;
for(S64 line_num = line_num_start;; first = 0)
{
// rjf: pop scratch
temp_end(scratch);
// rjf: gather line info
String8 line_string = str8_substr(data, text_info.lines_ranges[line_num-1]);
String8 line_string = str8_substr(data, info->lines_ranges[line_num-1]);
U64 search_start = 0;
if(cv->cursor.line == line_num && first)
{
@@ -750,14 +720,14 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
B32 found = 0;
B32 first = 1;
S64 line_num_start = cv->cursor.line;
S64 line_num_last = (S64)text_info.lines_count;
S64 line_num_last = (S64)info->lines_count;
for(S64 line_num = line_num_start;; first = 0)
{
// rjf: pop scratch
temp_end(scratch);
// rjf: gather line info
String8 line_string = str8_substr(data, text_info.lines_ranges[line_num-1]);
String8 line_string = str8_substr(data, info->lines_ranges[line_num-1]);
if(cv->cursor.line == line_num && first)
{
line_string = str8_prefix(line_string, cv->cursor.column-1);
@@ -815,11 +785,11 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: do goto line
//
if(text_info_is_ready) if(cv->goto_line_num != 0)
if(cv->goto_line_num != 0)
{
S64 line_num = cv->goto_line_num;
cv->goto_line_num = 0;
line_num = Clamp(1, line_num, text_info.lines_count);
line_num = Clamp(1, line_num, info->lines_count);
cv->cursor = cv->mark = txt_pt(line_num, 1);
cv->center_cursor = !cv->contain_cursor || (line_num < target_visible_line_num_range.min+4 || target_visible_line_num_range.max-4 < line_num);
}
@@ -830,16 +800,16 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
B32 snap[Axis2_COUNT] = {0};
UI_Focus(UI_FocusKind_On)
{
if(ui_is_focus_active() && text_info_is_ready && visible_line_num_range.max >= visible_line_num_range.min)
if(ui_is_focus_active() && visible_line_num_range.max >= visible_line_num_range.min)
{
snap[Axis2_X] = snap[Axis2_Y] = df_do_txt_controls(&text_info, data, ClampBot(num_possible_visible_lines, 10) - 10, &cv->cursor, &cv->mark, &cv->preferred_column);
snap[Axis2_X] = snap[Axis2_Y] = df_do_txt_controls(info, data, ClampBot(num_possible_visible_lines, 10) - 10, &cv->cursor, &cv->mark, &cv->preferred_column);
}
}
//////////////////////////////
//- rjf: build container contents
//
if(text_info_is_ready) UI_Parent(container_box)
UI_Parent(container_box)
{
//- rjf: build fractional space
container_box->view_off.x = container_box->view_off_target.x = view->scroll_pos.x.idx + view->scroll_pos.x.off;
@@ -877,7 +847,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
{
ui_kill_action();
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.string = txt_string_from_info_data_txt_rng(&text_info, data, sig.mouse_expr_rng);
params.string = txt_string_from_info_data_txt_rng(info, data, sig.mouse_expr_rng);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_String);
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_GoToName));
}
@@ -885,14 +855,14 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//- rjf: copy text
if(!txt_pt_match(sig.copy_range.min, sig.copy_range.max))
{
String8 text = txt_string_from_info_data_txt_rng(&text_info, data, sig.copy_range);
String8 text = txt_string_from_info_data_txt_rng(info, data, sig.copy_range);
os_set_clipboard_text(text);
}
//- rjf: selected text on single line, no query? -> set search text
if(!txt_pt_match(cv->cursor, cv->mark) && cv->cursor.line == cv->mark.line && search_query.size == 0)
{
String8 text = txt_string_from_info_data_txt_rng(&text_info, data, txt_rng(cv->cursor, cv->mark));
String8 text = txt_string_from_info_data_txt_rng(info, data, txt_rng(cv->cursor, cv->mark));
df_set_search_string(text);
}
@@ -946,7 +916,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: apply post-build view snapping rules
//
if(text_info_is_ready)
{
// rjf: contain => snap
if(cv->contain_cursor)
@@ -960,7 +929,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
if(cv->center_cursor)
{
cv->center_cursor = 0;
String8 cursor_line = str8_substr(data, text_info.lines_ranges[cv->cursor.line-1]);
String8 cursor_line = str8_substr(data, info->lines_ranges[cv->cursor.line-1]);
F32 cursor_advance = f_dim_from_tag_size_string(code_font, code_font_size, 0, code_tab_size, str8_prefix(cursor_line, cv->cursor.column-1)).x;
// rjf: scroll x
@@ -983,7 +952,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
// rjf: snap in X
if(snap[Axis2_X])
{
String8 cursor_line = str8_substr(data, text_info.lines_ranges[cv->cursor.line-1]);
String8 cursor_line = str8_substr(data, info->lines_ranges[cv->cursor.line-1]);
S64 cursor_off = (S64)(f_dim_from_tag_size_string(code_font, code_font_size, 0, code_tab_size, str8_prefix(cursor_line, cv->cursor.column-1)).x + priority_margin_width_px + catchall_margin_width_px + line_num_width_px);
Rng1S64 visible_pixel_range =
{
@@ -1011,7 +980,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
S64 min_delta = Min(0, cursor_visibility_range.min-(target_visible_line_num_range.min));
S64 max_delta = Max(0, cursor_visibility_range.max-(target_visible_line_num_range.min+num_possible_visible_lines));
S64 new_idx = view->scroll_pos.y.idx+min_delta+max_delta;
new_idx = Clamp(0, new_idx, (S64)text_info.lines_count-1);
new_idx = Clamp(0, new_idx, (S64)info->lines_count-1);
ui_scroll_pt_target_idx(&view->scroll_pos.y, new_idx);
}
}
@@ -1019,7 +988,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: build horizontal scroll bar
//
if(text_info_is_ready)
{
ui_set_next_fixed_x(0);
ui_set_next_fixed_y(code_area_dim.y);
@@ -1037,12 +1005,11 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: build vertical scroll bar
//
if(text_info_is_ready)
{
ui_set_next_fixed_x(code_area_dim.x);
ui_set_next_fixed_y(0);
ui_set_next_fixed_width(scroll_bar_dim);
ui_set_next_fixed_height(panel_box_dim.y - bottom_bar_dim.y - scroll_bar_dim);
ui_set_next_fixed_height(panel_box_dim.y - scroll_bar_dim);
{
view->scroll_pos.y = ui_scroll_bar(Axis2_Y,
ui_px(scroll_bar_dim, 1.f),
@@ -1055,7 +1022,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta
//////////////////////////////
//- rjf: top-level container interaction (scrolling)
//
if(text_info_is_ready)
{
UI_Signal sig = ui_signal_from_box(container_box);
if(sig.scroll.x != 0)
@@ -6225,6 +6191,195 @@ DF_VIEW_UI_FUNCTION_DEF(PendingEntity)
////////////////////////////////
//~ rjf: Code @view_hook_impl
#if 0
DF_VIEW_SETUP_FUNCTION_DEF(Code)
{
// rjf: set up state
DF_CodeViewState *cv = df_view_user_state(view, DF_CodeViewState);
df_code_view_init(cv, view);
// rjf: deserialize cursor
DF_CfgNode *cursor_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("cursor"), StringMatchFlag_CaseInsensitive);
if(cursor_cfg != &df_g_nil_cfg_node)
{
TxtPt cursor = txt_pt(1, 1);
cursor.line = s64_from_str8(cursor_cfg->first->string, 10);
cursor.column = s64_from_str8(cursor_cfg->first->first->string, 10);
if(cursor.line == 0) { cursor.line = 1; }
if(cursor.column == 0) { cursor.column = 1; }
cv->cursor = cv->mark = cursor;
cv->center_cursor = 1;
}
// rjf: default to loading
df_view_equip_loading_info(view, 1, 0, 0);
view->loading_t = view->loading_t_target = 1.f;
}
DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(Code)
{
DF_CodeViewState *tvs = df_view_user_state(view, DF_CodeViewState);
String8 string = push_str8f(arena, " cursor:%I64d:%I64d", tvs->cursor.line, tvs->cursor.column);
return string;
}
DF_VIEW_CMD_FUNCTION_DEF(Code)
{
DF_CodeViewState *cv = df_view_user_state(view, DF_CodeViewState);
Temp scratch = scratch_begin(0, 0);
HS_Scope *hs_scope = hs_scope_open();
TXT_Scope *txt_scope = txt_scope_open();
String8 path = df_full_path_from_entity(scratch.arena, df_entity_from_handle(view->entity));
TXT_LangKind lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path));
U128 key = fs_key_from_path(path);
U128 hash = {0};
TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
String8 data = hs_data_from_hash(hs_scope, hash);
df_code_view_cmds(ws, panel, view, cv, cmds, data, &info);
txt_scope_close(txt_scope);
hs_scope_close(hs_scope);
scratch_end(scratch);
}
DF_VIEW_UI_FUNCTION_DEF(Code)
{
DF_CodeViewState *cv = df_view_user_state(view, DF_CodeViewState);
Temp scratch = scratch_begin(0, 0);
HS_Scope *hs_scope = hs_scope_open();
TXT_Scope *txt_scope = txt_scope_open();
//////////////////////////////
//- rjf: set up invariants
//
F32 bottom_bar_height = ui_top_font_size()*2.f;
Rng2F32 code_area_rect = r2f32p(rect.x0, rect.y0, rect.x1, rect.y1 - bottom_bar_height);
Rng2F32 bottom_bar_rect = r2f32p(rect.x0, rect.y1 - bottom_bar_height, rect.x1, rect.y1);
//////////////////////////////
//- rjf: unpack entity info
//
DF_Entity *entity = df_entity_from_handle(view->entity);
String8 path = df_full_path_from_entity(scratch.arena, entity);
TXT_LangKind lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path));
U128 key = fs_key_from_path(path);
U128 hash = {0};
TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
String8 data = hs_data_from_hash(hs_scope, hash);
B32 entity_is_missing = !!(entity->flags & DF_EntityFlag_IsMissing);
B32 key_has_data = !u128_match(hash, u128_zero()) && info.lines_count;
B32 file_is_out_of_date = 0;
String8 out_of_date_dbgi_name = {0};
//////////////////////////////
//- rjf: build missing file interface
//
if(entity_is_missing && !key_has_data)
{
UI_WidthFill UI_HeightFill UI_Column UI_Padding(ui_pct(1, 0))
{
Temp scratch = scratch_begin(0, 0);
String8 full_path = df_full_path_from_entity(scratch.arena, entity);
UI_PrefWidth(ui_children_sum(1)) UI_PrefHeight(ui_em(3, 1))
UI_Row UI_Padding(ui_pct(1, 0))
UI_PrefWidth(ui_text_dim(10, 1))
UI_Palette(ui_build_palette(ui_top_palette(), .text = df_rgba_from_theme_color(DF_ThemeColor_TextNegative)))
{
UI_Font(df_font_from_slot(DF_FontSlot_Icons))
UI_RunFlags(F_RunFlag_Smooth)
ui_label(df_g_icon_kind_text_table[DF_IconKind_WarningBig]);
ui_labelf("Could not find \"%S\".", full_path);
}
UI_PrefHeight(ui_em(3, 1))
UI_Row UI_Padding(ui_pct(1, 0))
UI_PrefWidth(ui_text_dim(10, 1))
UI_CornerRadius(ui_top_font_size()/3)
UI_PrefWidth(ui_text_dim(10, 1))
UI_Focus(UI_FocusKind_On)
DF_Palette(DF_PaletteCode_NeutralPopButton)
if(ui_clicked(ui_buttonf("Find alternative...")))
{
DF_CmdParams params = df_cmd_params_from_view(ws, panel, view);
params.cmd_spec = df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_PickFile);
df_cmd_params_mark_slot(&params, DF_CmdParamSlot_CmdSpec);
df_push_cmd__root(&params, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunCommand));
cv->pick_file_override_target = view->entity;
}
scratch_end(scratch);
}
}
//////////////////////////////
//- rjf: code is not missing, but not ready -> equip loading info to this view
//
if(!entity_is_missing && info.lines_count == 0)
{
df_view_equip_loading_info(view, 1, info.bytes_processed, info.bytes_to_process);
}
//////////////////////////////
//- rjf: build code contents
//
if(!entity_is_missing && key_has_data)
{
df_code_view_build(ws, panel, view, cv, code_area_rect, data, &info);
}
//////////////////////////////
//- rjf: build bottom bar
//
if(!entity_is_missing && key_has_data)
{
ui_set_next_rect(shift_2f32(bottom_bar_rect, scale_2f32(rect.p0, -1.f)));
ui_set_next_flags(UI_BoxFlag_DrawBackground);
UI_Row
UI_TextAlignment(UI_TextAlign_Center)
UI_PrefWidth(ui_text_dim(10, 1))
UI_FlagsAdd(UI_BoxFlag_DrawTextWeak)
{
if(file_is_out_of_date)
{
UI_Box *box = &ui_g_nil_box;
UI_Palette(ui_build_palette(ui_top_palette(), .text = df_rgba_from_theme_color(DF_ThemeColor_TextNegative)))
UI_Font(df_font_from_slot(DF_FontSlot_Icons))
UI_RunFlags(F_RunFlag_Smooth)
{
box = ui_build_box_from_stringf(UI_BoxFlag_DrawText|UI_BoxFlag_Clickable, "%S###file_ood_warning", df_g_icon_kind_text_table[DF_IconKind_WarningBig]);
}
UI_Signal sig = ui_signal_from_box(box);
if(ui_hovering(sig)) UI_Tooltip
{
UI_PrefWidth(ui_children_sum(1)) UI_Row UI_PrefWidth(ui_text_dim(1, 1))
{
ui_labelf("This file has changed since ", out_of_date_dbgi_name);
UI_Palette(ui_build_palette(ui_top_palette(), .text = df_rgba_from_theme_color(DF_ThemeColor_TextNeutral))) ui_label(out_of_date_dbgi_name);
ui_labelf(" was produced.");
}
}
}
UI_Font(df_font_from_slot(DF_FontSlot_Code))
{
ui_label(path);
ui_spacer(ui_em(1.5f, 1));
ui_labelf("Line: %I64d, Column: %I64d", cv->cursor.line, cv->cursor.column);
ui_spacer(ui_pct(1, 0));
ui_labelf("(read only)");
ui_labelf("%s",
info.line_end_kind == TXT_LineEndKind_LF ? "lf" :
info.line_end_kind == TXT_LineEndKind_CRLF ? "crlf" :
"bin");
}
}
}
txt_scope_close(txt_scope);
hs_scope_close(hs_scope);
scratch_end(scratch);
}
#endif
//~ TODO(rjf): OLD vvvvvvvv
#if 1
DF_VIEW_SETUP_FUNCTION_DEF(Code)
{
// rjf: set up state
@@ -7298,6 +7453,7 @@ DF_VIEW_UI_FUNCTION_DEF(Code)
scratch_end(scratch);
ProfEnd();
}
#endif
////////////////////////////////
//~ rjf: Disassembly @view_hook_impl
+2 -2
View File
@@ -471,8 +471,8 @@ internal void df_entity_lister_item_array_sort_by_strength__in_place(DF_EntityLi
//~ rjf: Code Views
internal void df_code_view_init(DF_CodeViewState *cv, DF_View *view);
internal void df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, U128 key, TXT_LangKind lang_kind);
internal void df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, U128 key, TXT_LangKind lang_kind);
internal void df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info);
internal void df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info);
////////////////////////////////
//~ rjf: Watch Views
+4 -1
View File
@@ -14,7 +14,10 @@ internal U128
hs_hash_from_data(String8 data)
{
U128 u128 = {0};
blake2b((U8 *)&u128.u64[0], sizeof(u128), data.str, data.size, 0, 0);
if(data.size != 0)
{
blake2b((U8 *)&u128.u64[0], sizeof(u128), data.str, data.size, 0, 0);
}
return u128;
}
+10
View File
@@ -2885,6 +2885,16 @@ ui_pop_rect(void)
return popped;
}
internal void
ui_set_next_rect(Rng2F32 rect)
{
Vec2F32 size = dim_2f32(rect);
ui_set_next_fixed_x(rect.x0);
ui_set_next_fixed_y(rect.y0);
ui_set_next_fixed_width(size.x);
ui_set_next_fixed_height(size.y);
}
internal UI_Size
ui_push_pref_size(Axis2 axis, UI_Size v)
{
+1
View File
@@ -976,6 +976,7 @@ internal UI_TextAlign ui_set_next_text_alignment(UI_TextAlign v);
//- rjf: helpers
internal Rng2F32 ui_push_rect(Rng2F32 rect);
internal Rng2F32 ui_pop_rect(void);
internal void ui_set_next_rect(Rng2F32 rect);
internal UI_Size ui_push_pref_size(Axis2 axis, UI_Size v);
internal UI_Size ui_pop_pref_size(Axis2 axis);
internal UI_Size ui_set_next_pref_size(Axis2 axis, UI_Size v);