New UI system up and running

This commit is contained in:
Allen Webster 2019-10-13 23:58:49 -07:00
parent c8a4b7e20a
commit e307b67f4e
7 changed files with 511 additions and 512 deletions

17
4ed.cpp
View File

@ -339,6 +339,7 @@ App_Init_Sig(app_init){
// NOTE(allen): live set
Arena *arena = models->arena;
{
models->live_set.node_arena = reserve_arena(models->tctx);
models->live_set.count = 0;
models->live_set.max = MAX_VIEWS;
models->live_set.views = push_array(arena, View, models->live_set.max);
@ -848,8 +849,20 @@ App_Step_Sig(app_step){
begin_render_section(target, models->frame_counter, literal_dt, animation_dt);
models->in_render_mode = true;
if (models->render_caller != 0){
models->render_caller(&models->app_links, frame);
Live_Views *live_views = &models->live_set;
Layout *layout = &models->layout;
for (Node *node = layout->open_panels.next;
node != &layout->open_panels;
node = node->next){
Panel *panel = CastFromMember(Panel, node, node);
View *view = panel->view;
View_Context_Node *ctx = view->ctx;
if (ctx != 0){
Render_Caller_Function *render_caller = ctx->ctx.render_caller;
if (render_caller != 0){
render_caller(&models->app_links, frame, view_get_id(live_views, view));
}
}
}
models->in_render_mode = false;

View File

@ -445,6 +445,51 @@ view_set_file(Models *models, View *view, Editing_File *file){
////////////////////////////////
function View_Context_Node*
view__alloc_context_node(Live_Views *views){
View_Context_Node *node = views->free_nodes;
if (node != 0){
sll_stack_pop(views->free_nodes);
}
else{
node = push_array(views->node_arena, View_Context_Node, 1);
}
return(node);
}
function void
view__free_context_node(Live_Views *views, View_Context_Node *node){
sll_stack_push(views->free_nodes, node);
}
function void
view_push_context(Models *models, View *view, View_Context *ctx){
View_Context_Node *node = view__alloc_context_node(&models->live_set);
sll_stack_push(view->ctx, node);
block_copy_struct(&node->ctx, ctx);
}
function void
view_pop_context(Models *models, View *view){
View_Context_Node *node = view->ctx;
if (node != 0){
sll_stack_pop(view->ctx);
view__free_context_node(&models->live_set, node);
}
}
function View_Context
view_current_context(Models *models, View *view){
View_Context ctx = {};
View_Context_Node *node = view->ctx;
if (node != 0){
block_copy_struct(&ctx, &node->ctx);
}
return(ctx);
}
////////////////////////////////
internal App_Coroutine_State
get_co_state(Application_Links *app){
App_Coroutine_State state = {};
@ -512,6 +557,11 @@ function void
view_init(Models *models, View *view, Editing_File *initial_buffer,
Custom_Command_Function *event_context_base){
view_set_file(models, view, initial_buffer);
View_Context first_ctx = {};
first_ctx.render_caller = models->render_caller;
view_push_context(models, view, &first_ctx);
view->co = coroutine_create(&models->coroutines, view_event_context_base__inner);
Co_In in = {};
in.models = models;
@ -607,51 +657,6 @@ co_send_core_event(Models *models, View *view, Core_Code code){
////////////////////////////////
function View_Context_Node*
view__alloc_context_node(Live_Views *views){
View_Context_Node *node = views->free_nodes;
if (node != 0){
sll_stack_pop(views->free_nodes);
}
else{
node = push_array(views->node_arena, View_Context_Node, 1);
}
return(node);
}
function void
view__free_context_node(Live_Views *views, View_Context_Node *node){
sll_stack_push(views->free_nodes, node);
}
function void
view_push_context(Models *models, View *view, View_Context *ctx){
View_Context_Node *node = view__alloc_context_node(&models->live_set);
sll_stack_push(view->ctx, node);
block_copy_struct(&node->ctx, ctx);
}
function void
view_pop_context(Models *models, View *view){
View_Context_Node *node = view->ctx;
if (node != 0){
sll_stack_pop(view->ctx);
view__free_context_node(&models->live_set, node);
}
}
function View_Context
view_current_context(Models *models, View *view){
View_Context ctx = {};
View_Context_Node *node = view->ctx;
if (node != 0){
block_copy_struct(&ctx, &node->ctx);
}
return(ctx);
}
////////////////////////////////
internal b32
file_is_viewed(Layout *layout, Editing_File *file){
b32 is_viewed = false;

View File

@ -325,27 +325,94 @@ get_token_color_cpp(Token token){
}
internal void
default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id, Rect_f32 view_inner_rect){
Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll);
default_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id){
View_ID active_view = get_active_view(app, AccessAll);
b32 is_active_view = (active_view == view_id);
Rect_f32 view_rect = view_get_screen_rect(app, view_id);
Rect_f32 inner = rect_inner(view_rect, 3);
draw_rectangle(app, view_rect, 0.f,
get_margin_color(is_active_view?UIHighlight_Active:UIHighlight_None));
draw_rectangle(app, inner, 0.f, Stag_Back);
Rect_f32 prev_clip = draw_set_clip(app, inner);
Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll);
Face_ID face_id = get_face_id(app, buffer);
Face_Metrics face_metrics = get_face_metrics(app, face_id);
f32 line_height = face_metrics.line_height;
Rect_f32 sub_region = default_view_buffer_region(app, view_id, view_inner_rect);
Rect_f32 buffer_rect = rect_intersect(sub_region, view_inner_rect);
// NOTE(allen): Frame
Rect_f32 r_cursor = inner;
// NOTE(allen): Filebar
b64 showing_file_bar = false;
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) && showing_file_bar){
Rect_f32 bar = r_cursor;
bar.y1 = bar.y0 + line_height + 2.f;
r_cursor.y0 = bar.y1;
draw_rectangle(app, bar, 0.f, Stag_Bar);
Fancy_Color base_color = fancy_id(Stag_Base);
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
Scratch_Block scratch(app);
i64 cursor_position = view_get_cursor_pos(app, view_id);
Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(cursor_position));
Fancy_String_List list = {};
String_Const_u8 unique_name = push_buffer_unique_name(app, scratch, buffer);
push_fancy_string(scratch, &list, base_color, unique_name);
push_fancy_stringf(scratch, &list, base_color, " - Row: %3.lld Col: %3.lld -", cursor.line, cursor.col);
b64 is_dos_mode = false;
if (buffer_get_setting(app, buffer, BufferSetting_Eol, &is_dos_mode)){
if (is_dos_mode){
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos"));
}
else{
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix"));
}
}
else{
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???"));
}
{
Dirty_State dirty = buffer_get_dirty_state(app, buffer);
u8 space[3];
String_u8 str = Su8(space, 0, 3);
if (dirty != 0){
string_append(&str, string_u8_litexpr(" "));
}
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
string_append(&str, string_u8_litexpr("*"));
}
if (HasFlag(dirty, DirtyState_UnloadedChanges)){
string_append(&str, string_u8_litexpr("!"));
}
push_fancy_string(scratch, &list, pop2_color, str.string);
}
Vec2 p = bar.p0 + V2(0.f, 2.f);
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
}
Rect_f32 sub_region = default_view_buffer_region(app, view_id, inner);
Rect_f32 buffer_rect = rect_intersect(sub_region, inner);
Buffer_Scroll scroll = view_get_buffer_scroll(app, view_id);
Buffer_Point buffer_point = scroll.position;
Text_Layout_ID text_layout_id = text_layout_create(app, buffer, buffer_rect, buffer_point);
Interval_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
View_ID active_view = get_active_view(app, AccessAll);
b32 is_active_view = (active_view == view_id);
Scratch_Block scratch(app);
{
Rect_f32 prev_clip_sub = draw_set_clip(app, buffer_rect);
// NOTE(allen): Token colorizing
Token_Array token_array = get_token_array_from_buffer(app, buffer);
if (token_array.tokens != 0){
@ -411,8 +478,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Managed_Scope scopes[2];
scopes[0] = buffer_get_managed_scope(app, compilation_buffer);
scopes[1] = buffer_get_managed_scope(app, buffer);
Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scopes, ArrayCount(scopes));
Managed_Object *markers_object = scope_attachment(app, scope, sticky_jump_marker_handle, Managed_Object);
Managed_Scope comp_scope = get_managed_scope_with_multiple_dependencies(app, scopes, ArrayCount(scopes));
Managed_Object *markers_object = scope_attachment(app, comp_scope, sticky_jump_marker_handle, Managed_Object);
Temp_Memory temp = begin_temp(scratch);
i32 count = managed_object_get_item_count(app, *markers_object);
@ -517,10 +584,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
}
}
{
Rect_f32 prev_clip = draw_set_clip(app, buffer_rect);
draw_text_layout(app, text_layout_id);
draw_set_clip(app, prev_clip);
draw_set_clip(app, prev_clip_sub);
}
// NOTE(allen): FPS HUD
@ -579,66 +644,6 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
animate_in_n_milliseconds(app, 1000);
}
// NOTE(allen): Frame
Rect_f32 r_cursor = view_inner_rect;
// NOTE(allen): Filebar
b64 showing_file_bar = false;
if (view_get_setting(app, view_id, ViewSetting_ShowFileBar, &showing_file_bar) && showing_file_bar){
Rect_f32 bar = r_cursor;
bar.y1 = bar.y0 + line_height + 2.f;
r_cursor.y0 = bar.y1;
draw_rectangle(app, bar, 0.f, Stag_Bar);
Fancy_Color base_color = fancy_id(Stag_Base);
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
Temp_Memory temp = begin_temp(scratch);
i64 cursor_position = view_get_cursor_pos(app, view_id);
Buffer_Cursor cursor = view_compute_cursor(app, view_id, seek_pos(cursor_position));
Fancy_String_List list = {};
String_Const_u8 unique_name = push_buffer_unique_name(app, scratch, buffer);
push_fancy_string(scratch, &list, base_color, unique_name);
push_fancy_stringf(scratch, &list, base_color, " - Row: %3.lld Col: %3.lld -", cursor.line, cursor.col);
b64 is_dos_mode = false;
if (buffer_get_setting(app, buffer, BufferSetting_Eol, &is_dos_mode)){
if (is_dos_mode){
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos"));
}
else{
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix"));
}
}
else{
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???"));
}
{
Dirty_State dirty = buffer_get_dirty_state(app, buffer);
u8 space[3];
String_u8 str = Su8(space, 0, 3);
if (dirty != 0){
string_append(&str, string_u8_litexpr(" "));
}
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
string_append(&str, string_u8_litexpr("*"));
}
if (HasFlag(dirty, DirtyState_UnloadedChanges)){
string_append(&str, string_u8_litexpr("!"));
}
push_fancy_string(scratch, &list, pop2_color, str.string);
}
Vec2 p = bar.p0 + V2(0.f, 2.f);
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
end_temp(temp);
}
// NOTE(allen): Query Bars
{
Query_Bar *space[32];
@ -683,7 +688,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
draw_rectangle(app, left_margin, 0.f, Stag_Line_Numbers_Back);
Rect_f32 prev_clip = draw_set_clip(app, left_margin);
Rect_f32 prev_clip_line_numbers = draw_set_clip(app, left_margin);
Fancy_Color line_color = fancy_id(Stag_Line_Numbers_Text);
@ -701,44 +706,14 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
line_number += 1;
}
draw_set_clip(app, prev_clip);
draw_set_clip(app, prev_clip_line_numbers);
}
text_layout_free(app, text_layout_id);
}
internal void
default_render_view(Application_Links *app, Frame_Info frame_info, View_ID view, b32 is_active){
Rect_f32 view_rect = view_get_screen_rect(app, view);
Rect_f32 inner = rect_inner(view_rect, 3);
draw_rectangle(app, view_rect, 0.f,
get_margin_color(is_active?UIHighlight_Active:UIHighlight_None));
draw_rectangle(app, inner, 0.f, Stag_Back);
Rect_f32 prev_clip = draw_set_clip(app, inner);
Managed_Scope scope = view_get_managed_scope(app, view);
View_Render_Hook **hook_ptr = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
if (*hook_ptr == 0){
default_buffer_render_caller(app, frame_info, view, inner);
}
else{
View_Render_Hook *hook = *hook_ptr;
hook(app, view, frame_info, inner);
}
draw_set_clip(app, prev_clip);
}
RENDER_CALLER_SIG(default_render_caller){
View_ID active_view_id = get_active_view(app, AccessAll);
for (View_ID view_id = get_view_next(app, 0, AccessAll);
view_id != 0;
view_id = get_view_next(app, view_id, AccessAll)){
default_render_view(app, frame_info, view_id, (active_view_id == view_id));
}
}
HOOK_SIG(default_exit){
// If this returns false it cancels the exit.
b32 result = true;

View File

@ -69,7 +69,7 @@ begin_lister(Application_Links *app, Arena *arena, View_ID view, void *user_data
}
function void
lister_render(Application_Links *app, View_ID view, Frame_Info frame_info, Rect_f32 inner){
lister_render(Application_Links *app, Frame_Info frame_info, View_ID view){
Scratch_Block scratch(app);
Lister *lister = view_get_lister(view);
@ -77,9 +77,20 @@ lister_render(Application_Links *app, View_ID view, Frame_Info frame_info, Rect_
return;
}
Rect_f32 region = view_get_screen_rect(app, view);
// TODO(allen): eliminate this. bad bad bad bad :(
region = rect_inner(region, 3.f);
////////////////////////////////
View_ID active_view = get_active_view(app, AccessAll);
b32 is_active_view = (active_view == view);
Rect_f32 view_rect = view_get_screen_rect(app, view);
Rect_f32 inner = rect_inner(view_rect, 3);
draw_rectangle(app, view_rect, 0.f,
get_margin_color(is_active_view?UIHighlight_Active:UIHighlight_None));
draw_rectangle(app, inner, 0.f, Stag_Back);
Rect_f32 prev_clip = draw_set_clip(app, inner);
////////////////////////////////
Rect_f32 region = inner;
Mouse_State mouse = get_mouse_state(app);
Vec2_f32 m_p = V2f32(mouse.p);
@ -104,7 +115,7 @@ lister_render(Application_Links *app, View_ID view, Frame_Info frame_info, Rect_
}
Range_f32 x = rect_range_x(layout.list_rect);
Rect_f32 prev_clip = draw_set_clip(app, layout.list_rect);
draw_set_clip(app, layout.list_rect);
i32 count = lister->data.filtered.count;
Range_f32 scroll_range = If32(0.f, clamp_bot(0.f, count*block_height - block_height));
@ -341,9 +352,9 @@ lister_run(Application_Links *app, View_ID view, Lister *lister){
lister->data.filter_restore_point = begin_temp(lister->arena);
lister_update_filtered_list(app, view, lister);
Managed_Scope scope = view_get_managed_scope(app, view);
View_Render_Hook **hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
*hook = lister_render;
View_Context ctx = view_current_context(app, view);
ctx.render_caller = lister_render;
view_push_context(app, view, &ctx);
for (;;){
User_Input in = get_user_input(app, EventPropertyGroup_Any, EventProperty_Escape);
@ -488,8 +499,7 @@ lister_run(Application_Links *app, View_ID view, Lister *lister){
}
}
hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
*hook = 0;
view_pop_context(app, view);
}
function Lister_Prealloced_String

View File

@ -662,8 +662,21 @@ log_graph_render__tag(Arena *arena, Fancy_String_List *line, Log_Parse *log, Log
}
internal void
log_graph_render(Application_Links *app, View_ID view, Frame_Info frame_info, Rect_f32 inner){
log_graph_render(Application_Links *app, Frame_Info frame_info, View_ID view){
if (log_parse.arena != 0){
////////////////////////////////
View_ID active_view = get_active_view(app, AccessAll);
b32 is_active_view = (active_view == view);
Rect_f32 view_rect = view_get_screen_rect(app, view);
Rect_f32 inner = rect_inner(view_rect, 3);
draw_rectangle(app, view_rect, 0.f,
get_margin_color(is_active_view?UIHighlight_Active:UIHighlight_None));
draw_rectangle(app, inner, 0.f, Stag_Back);
Rect_f32 prev_clip = draw_set_clip(app, inner);
////////////////////////////////
Face_ID face_id = get_face_id(app, 0);
f32 y_scroll = log_graph.y_scroll;
Log_Event *selected_event = log_graph.selected_event;
@ -900,6 +913,7 @@ log_graph_render(Application_Links *app, View_ID view, Frame_Info frame_info, Re
}
log_graph.has_unused_click = false;
draw_set_clip(app, prev_clip);
}
}
@ -972,21 +986,6 @@ log_graph__click_jump_to_event_source(Application_Links *app, Vec2_f32 m_p){
}
}
#if 0
internal void
fill_log_graph_command_map(Mapping *mapping){
MappingScope();
SelectMapping(mapping);
SelectMap(default_log_graph_map);
//Bind(log_graph__escape, KeyCode_Escape);
//BindMouseWheel(log_graph__scroll_wheel);
//BindMouse(log_graph__click_jump_to_event_source, MouseCode_Left);
//BindMouse(log_graph__click_select_event, MouseCode_Right);
Bind(log_graph__page_up, KeyCode_PageUp);
Bind(log_graph__page_down, KeyCode_PageDown);
}
#endif
CUSTOM_COMMAND_SIG(show_the_log_graph)
CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
{
@ -996,14 +995,14 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
if (log_view == 0){
log_view = get_active_view(app, AccessAll);
}
Managed_Scope scope = view_get_managed_scope(app, log_view);
View_Render_Hook **hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
*hook = log_graph_render;
View_ID view = log_view;
View_Context ctx = view_current_context(app, log_view);
ctx.render_caller = log_graph_render;
view_push_context(app, log_view, &ctx);
for (;;){
User_Input in = get_user_input(app,
EventPropertyGroup_AnyUserInput,
KeyCode_Escape);
User_Input in = get_user_input(app, EventPropertyGroup_AnyUserInput, KeyCode_Escape);
if (in.abort){
log_view = 0;
break;
@ -1049,8 +1048,7 @@ CUSTOM_DOC("Parses *log* and displays the 'log graph' UI")
}
}
hook = scope_attachment(app, scope, view_render_hook, View_Render_Hook*);
*hook = 0;
view_pop_context(app, view);
}
// BOTTOM

View File

@ -101,8 +101,17 @@ STRUCT Character_Predicate{
u8 b[32];
};
struct Frame_Info{
i32 index;
f32 literal_dt;
f32 animation_dt;
};
typedef void Render_Caller_Function(Application_Links *app, Frame_Info frame_info, View_ID view);
#define RENDER_CALLER_SIG(name) void name(Application_Links *app, Frame_Info frame_info, View_ID view)
struct View_Context{
Void_Func ctx_ptr;
Render_Caller_Function *render_caller;
b32 hides_buffer;
};
@ -472,14 +481,6 @@ STRUCT User_Input{
b32 abort;
};
STRUCT Frame_Info{
i32 index;
f32 literal_dt;
f32 animation_dt;
};
TYPEDEF_FUNC void Render_Callback(struct Application_Links *app);
typedef i32 Hook_ID;
enum{
HookID_FileOutOfSync,
@ -505,9 +506,6 @@ enum{
TYPEDEF_FUNC i32 Hook_Function(struct Application_Links *app);
#define HOOK_SIG(name) i32 name(struct Application_Links *app)
TYPEDEF_FUNC void Render_Caller_Function(struct Application_Links *app, Frame_Info frame_info);
#define RENDER_CALLER_SIG(name) void name(struct Application_Links *app, Frame_Info frame_info)
TYPEDEF_FUNC i32 Buffer_Hook_Function(struct Application_Links *app, Buffer_ID buffer_id);
#define BUFFER_HOOK_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id)

View File

@ -372,7 +372,7 @@ static Command_Metadata fcoder_metacmd_table[202] = {
{ PROC_LINKS(if_read_only_goto_position, 0), "if_read_only_goto_position", 26, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor.", 106, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 562 },
{ PROC_LINKS(if_read_only_goto_position_same_panel, 0), "if_read_only_goto_position_same_panel", 37, "If the buffer in the active view is writable, inserts a character, otherwise performs goto_jump_at_cursor_same_panel.", 117, "w:\\4ed\\code\\custom\\4coder_jump_sticky.cpp", 41, 579 },
{ PROC_LINKS(view_jump_list_with_lister, 0), "view_jump_list_with_lister", 26, "When executed on a buffer with jumps, creates a persistent lister for all the jumps", 83, "w:\\4ed\\code\\custom\\4coder_jump_lister.cpp", 41, 102 },
{ PROC_LINKS(show_the_log_graph, 0), "show_the_log_graph", 18, "Parses *log* and displays the 'log graph' UI", 44, "w:\\4ed\\code\\custom\\4coder_log_parser.cpp", 40, 990 },
{ PROC_LINKS(show_the_log_graph, 0), "show_the_log_graph", 18, "Parses *log* and displays the 'log graph' UI", 44, "w:\\4ed\\code\\custom\\4coder_log_parser.cpp", 40, 989 },
{ PROC_LINKS(copy, 0), "copy", 4, "Copy the text in the range from the cursor to the mark onto the clipboard.", 74, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 19 },
{ PROC_LINKS(cut, 0), "cut", 3, "Cut the text in the range from the cursor to the mark onto the clipboard.", 73, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 28 },
{ PROC_LINKS(paste, 0), "paste", 5, "At the cursor, insert the text at the top of the clipboard.", 59, "w:\\4ed\\code\\custom\\4coder_clipboard.cpp", 39, 39 },