push_fancy_stringf

master
Allen Webster 2019-02-25 16:17:24 -08:00
parent 4b55e6e293
commit 8af9849f67
4 changed files with 75 additions and 35 deletions

View File

@ -514,27 +514,25 @@ RENDER_CALLER_SIG(default_render_caller){
char space[256]; char space[256];
String str = make_fixed_width_string(space); String str = make_fixed_width_string(space);
Fancy_Color white = fancy_from_rgba_color(1.f, 1.f, 1.f, 1.f);
Fancy_Color pink = fancy_from_rgba_color(1.f, 0.f, 1.f, 1.f);
Fancy_Color green = fancy_from_rgba_color(0.f, 1.f, 0.f, 1.f);
Fancy_String_List list = {}; Fancy_String_List list = {};
push_fancy_string(&arena, &list, make_lit_string("FPS: "), fancy_from_rgba_color(1.f, 0.f, 1.f, 1.f)); push_fancy_stringf(&arena, &list, pink , "FPS: ");
push_fancy_string(&arena, &list, make_lit_string("["), fancy_from_rgba_color(0.f, 1.f, 0.f, 1.f)); push_fancy_stringf(&arena, &list, green, "[");
{ push_fancy_stringf(&arena, &list, white, "%5d", frame_index);
str.size = 0; push_fancy_stringf(&arena, &list, green, "]: ");
append_int_to_str_left_pad(&str, frame_index, 6, ' ');
push_fancy_string(&arena, &list, str, fancy_from_rgba_color(1.f, 1.f, 1.f, 1.f));
}
push_fancy_string(&arena, &list, make_lit_string("]: "), fancy_from_rgba_color(0.f, 1.f, 0.f, 1.f));
for (i32 k = 0; k < 2; k += 1){ for (i32 k = 0; k < 2; k += 1){
f32 dt = dts[k]; f32 dt = dts[k];
str.size = 0; str.size = 0;
if (dt == 0.f){ if (dt == 0.f){
append_padding(&str, '-', str.size + 10); push_fancy_stringf(&arena, &list, white, "-----");
} }
else{ else{
append_int_to_str_left_pad(&str, round32(1.f/dt), 10, ' '); push_fancy_stringf(&arena, &list, white, "%5d", round32(1.f/dt));
} }
push_fancy_string(&arena, &list, str, fancy_from_rgba_color(1.f, 1.f, 1.f, 1.f)); push_fancy_stringf(&arena, &list, green, " | ");
push_fancy_string(&arena, &list, make_lit_string(" | "), fancy_from_rgba_color(0.f, 1.f, 0.f, 1.f));
} }
draw_fancy_string(app, font_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f)); draw_fancy_string(app, font_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f));

View File

@ -2,6 +2,8 @@
* Fancy string - immediate mode renderer for colored strings * Fancy string - immediate mode renderer for colored strings
*/ */
// TOP
static Fancy_Color static Fancy_Color
blend_color(id_color a, f32 t, id_color b){ blend_color(id_color a, f32 t, id_color b){
Fancy_Color result = {}; Fancy_Color result = {};
@ -83,11 +85,11 @@ is_valid(Fancy_Color source){
} }
static Fancy_String * static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, String value, Fancy_Color fore){ push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, String value){
Fancy_String *result = push_array(arena, Fancy_String, 1); Fancy_String *result = push_array(arena, Fancy_String, 1);
result->value = string_push_copy(arena, value); result->value = string_push_copy(arena, value);
result->fore = fore; result->fore = fore;
result->back = pass_through_fancy_color(); result->back = back;
result->pre_margin = 0; result->pre_margin = 0;
result->post_margin = 0; result->post_margin = 0;
result->next = 0; result->next = 0;
@ -99,9 +101,53 @@ push_fancy_string(Arena *arena, Fancy_String_List *list, String value, Fancy_Col
return(result); return(result);
} }
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, String value){
return(push_fancy_string(arena, list, fore, pass_through_fancy_color(), value));
}
static Fancy_String * static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, String value){ push_fancy_string(Arena *arena, Fancy_String_List *list, String value){
return(push_fancy_string(arena, list, value, pass_through_fancy_color())); return(push_fancy_string(arena, list, pass_through_fancy_color(), pass_through_fancy_color(), value));
}
static Fancy_String*
push_fancy_vstringf(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, char *format, va_list args){
// TODO(casey): Allen, ideally we would have our own formatter here that just outputs into a buffer and can't ever "run out of space".
char temp[1024];
int32_t length = vsprintf(temp, format, args);
Fancy_String *result = 0;
if (length > 0){
result = push_fancy_string(arena, list, fore, back, make_string(temp, length));
}
return(result);
}
static Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, char *format, ...){
va_list args;
va_start(args, format);
Fancy_String *result = push_fancy_vstringf(arena, list, fore, back, format, args);
va_end(args);
return(result);
}
static Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_String_List *list, Fancy_Color fore, char *format, ...){
va_list args;
va_start(args, format);
Fancy_String *result = push_fancy_vstringf(arena, list, fore, pass_through_fancy_color(), format, args);
va_end(args);
return(result);
}
static Fancy_String*
push_fancy_stringf(Arena *arena, Fancy_String_List *list, char *format, ...){
va_list args;
va_start(args, format);
Fancy_String *result = push_fancy_vstringf(arena, list, pass_through_fancy_color(), pass_through_fancy_color(), format, args);
va_end(args);
return(result);
} }
static Vec2 static Vec2
@ -123,3 +169,6 @@ draw_fancy_string(Application_Links *app, Face_ID font_id, Fancy_String *string,
} }
return(P); return(P);
} }
// BOTTOM

View File

@ -275,7 +275,7 @@ static Command_Metadata fcoder_metacmd_table[233] = {
{ PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1060 }, { PROC_LINKS(close_all_code, 0), "close_all_code", 14, "Closes any buffer with a filename ending with an extension configured to be recognized as a code file type.", 107, "w:\\4ed\\code\\4coder_project_commands.cpp", 39, 1060 },
{ PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 203 }, { PROC_LINKS(close_build_panel, 0), "close_build_panel", 17, "If the special build panel is open, closes it.", 46, "w:\\4ed\\code\\4coder_build_commands.cpp", 37, 203 },
{ PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 503 }, { PROC_LINKS(close_panel, 0), "close_panel", 11, "Closes the currently active panel if it is not the only panel open.", 67, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 503 },
{ PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 981 }, { PROC_LINKS(command_lister, 0), "command_lister", 14, "Opens an interactive list of all registered commands.", 53, "w:\\4ed\\code\\4coder_lists.cpp", 28, 974 },
{ PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 135 }, { PROC_LINKS(comment_line, 0), "comment_line", 12, "Insert '//' at the beginning of the line after leading whitespace.", 66, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 135 },
{ PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 159 }, { PROC_LINKS(comment_line_toggle, 0), "comment_line_toggle", 19, "Turns uncommented lines into commented lines and vice versa for comments starting with '//'.", 92, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 159 },
{ 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\\4coder_clipboard.cpp", 32, 26 }, { 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\\4coder_clipboard.cpp", 32, 26 },
@ -318,11 +318,11 @@ static Command_Metadata fcoder_metacmd_table[233] = {
{ PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 79 }, { PROC_LINKS(if0_off, 0), "if0_off", 7, "Surround the range between the cursor and mark with an '#if 0' and an '#endif'", 78, "w:\\4ed\\code\\4coder_combined_write_commands.cpp", 46, 79 },
{ PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 586 }, { PROC_LINKS(increase_face_size, 0), "increase_face_size", 18, "Increase the size of the face used by the current buffer.", 57, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 586 },
{ PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 564 }, { PROC_LINKS(increase_line_wrap, 0), "increase_line_wrap", 18, "Increases the current buffer's width for line wrapping.", 55, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 564 },
{ PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 782 }, { PROC_LINKS(interactive_kill_buffer, 0), "interactive_kill_buffer", 23, "Interactively kill an open buffer.", 34, "w:\\4ed\\code\\4coder_lists.cpp", 28, 775 },
{ PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 892 }, { PROC_LINKS(interactive_new, 0), "interactive_new", 15, "Interactively creates a new file.", 33, "w:\\4ed\\code\\4coder_lists.cpp", 28, 885 },
{ PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 924 }, { PROC_LINKS(interactive_open, 0), "interactive_open", 16, "Interactively opens a file.", 27, "w:\\4ed\\code\\4coder_lists.cpp", 28, 917 },
{ PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 854 }, { PROC_LINKS(interactive_open_or_new, 0), "interactive_open_or_new", 23, "Interactively open a file out of the file system.", 49, "w:\\4ed\\code\\4coder_lists.cpp", 28, 847 },
{ PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 763 }, { PROC_LINKS(interactive_switch_buffer, 0), "interactive_switch_buffer", 25, "Interactively switch to an open buffer.", 39, "w:\\4ed\\code\\4coder_lists.cpp", 28, 756 },
{ PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1583 }, { PROC_LINKS(kill_buffer, 0), "kill_buffer", 11, "Kills the current buffer.", 25, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 1583 },
{ PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 26 }, { PROC_LINKS(kill_rect, 0), "kill_rect", 9, "Delete characters in a rectangular region. Range testing is done by unwrapped-xy coordinates.", 93, "w:\\4ed\\code\\4coder_experiments.cpp", 34, 26 },
{ PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 166 }, { PROC_LINKS(left_adjust_view, 0), "left_adjust_view", 16, "Sets the left size of the view near the x position of the cursor.", 65, "w:\\4ed\\code\\4coder_base_commands.cpp", 36, 166 },

View File

@ -622,29 +622,23 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
} }
static void static void
begin_integrated_lister__buffer_list(Application_Links *app, char *query_string, begin_integrated_lister__buffer_list(Application_Links *app, char *query_string, Lister_Activation_Function_Type *activate_procedure,
Lister_Activation_Function_Type *activate_procedure, void *user_data, int32_t user_data_size, View_Summary *target_view){
void *user_data, int32_t user_data_size,
View_Summary *target_view){
Lister_Handlers handlers = lister_get_default_handlers(); Lister_Handlers handlers = lister_get_default_handlers();
handlers.activate = activate_procedure; handlers.activate = activate_procedure;
handlers.refresh = generate_all_buffers_list; handlers.refresh = generate_all_buffers_list;
begin_integrated_lister__with_refresh_handler(app, query_string, handlers, user_data, user_data_size, begin_integrated_lister__with_refresh_handler(app, query_string, handlers, user_data, user_data_size, target_view);
target_view);
} }
static void static void
begin_integrated_lister__file_system_list(Application_Links *app, char *query_string, begin_integrated_lister__file_system_list(Application_Links *app, char *query_string, Lister_Activation_Function_Type *activate_procedure,
Lister_Activation_Function_Type *activate_procedure, void *user_data, int32_t user_data_size, View_Summary *target_view){
void *user_data, int32_t user_data_size,
View_Summary *target_view){
Lister_Handlers handlers = lister_get_default_handlers(); Lister_Handlers handlers = lister_get_default_handlers();
handlers.activate = activate_procedure; handlers.activate = activate_procedure;
handlers.refresh = generate_hot_directory_file_list; handlers.refresh = generate_hot_directory_file_list;
handlers.write_character = lister__write_character__file_path; handlers.write_character = lister__write_character__file_path;
handlers.backspace = lister__backspace_text_field__file_path; handlers.backspace = lister__backspace_text_field__file_path;
begin_integrated_lister__with_refresh_handler(app, query_string, handlers, user_data, user_data_size, begin_integrated_lister__with_refresh_handler(app, query_string, handlers, user_data, user_data_size, target_view);
target_view);
} }
//////////////////////////////// ////////////////////////////////
@ -657,8 +651,7 @@ enum{
}; };
static void static void
activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *view, Lister_State *state,
View_Summary *view, Lister_State *state,
String text_field, void *user_data, bool32 clicked){ String text_field, void *user_data, bool32 clicked){
int32_t behavior = (int32_t)PtrAsInt(user_data); int32_t behavior = (int32_t)PtrAsInt(user_data);
Buffer_ID buffer_id = *(Buffer_ID*)(state->lister.data.user_data); Buffer_ID buffer_id = *(Buffer_ID*)(state->lister.data.user_data);