minimum base width feature for code wrapping

master
Allen Webster 2016-10-24 19:02:10 -04:00
parent 39dbddfa3f
commit e76dac4994
4 changed files with 38 additions and 23 deletions

View File

@ -12,6 +12,7 @@
// App Structs
#define DEFAULT_DISPLAY_WIDTH 672
#define DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH 450
typedef enum App_State{
APP_STATE_EDIT,
@ -1659,6 +1660,7 @@ App_Init_Sig(app_init){
// NOTE(allen): file setup
working_set_init(system, &models->working_set, partition, &vars->models.mem.general);
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH;
// NOTE(allen): clipboard setup
models->working_set.clipboard_max_size = ArrayCount(models->working_set.clipboards);

View File

@ -91,6 +91,7 @@ struct Text_Effect{
struct Editing_File_Settings{
i32 base_map_id;
i32 display_width;
i32 minimum_base_display_width;
b32 dos_write_mode;
b32 virtual_white;
i16 font_id;
@ -217,6 +218,7 @@ struct Working_Set{
File_Node *sync_check_iter;
i32 default_display_width;
i32 default_minimum_base_display_width;
};
//
@ -452,6 +454,7 @@ working_set_alloc(Working_Set *working_set){
result->unique_buffer_id = ++working_set->unique_file_counter;
dll_insert(&working_set->used_sentinel, node);
result->settings.display_width = working_set->default_display_width;
result->settings.minimum_base_display_width = working_set->default_minimum_base_display_width;
++working_set->file_count;
}

View File

@ -281,6 +281,13 @@ view_file_display_width(View *view){
return(result);
}
inline f32
view_file_minimum_base_width(View *view){
Editing_File *file = view->file_data.file;
f32 result = (f32)file->settings.display_width;
return(result);
}
inline f32
view_file_height(View *view){
i32_Rect file_rect = view->file_region;
@ -389,7 +396,6 @@ view_compute_cursor(View *view, Buffer_Seek seek, b32 return_hint){
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.seek = seek;
params.width = view_file_display_width(view);
params.font_height = (f32)font->height;
params.adv = font->advance_data;
params.wrap_line_index = file->state.wrap_line_index;
@ -974,6 +980,7 @@ struct Code_Wrap_State{
Cpp_Token *token_ptr;
Cpp_Token *end_token;
f32 base_x;
f32 paren_nesting[32];
i32 paren_safe_top;
i32 paren_top;
@ -1394,17 +1401,19 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
params.buffer = &file->state.buffer;
params.wrap_line_index = file->state.wrap_line_index;
params.adv = adv;
params.width = (f32)file->settings.display_width;
params.virtual_white = file->settings.virtual_white;
f32 width = (f32)file->settings.display_width;
f32 minimum_base_width = (f32)file->settings.minimum_base_display_width;
i32 size = buffer_size(params.buffer);
Buffer_Measure_Wrap_State state = {0};
Buffer_Layout_Stop stop = {0};
f32 edge_tolerance = 50.f;
if (edge_tolerance > params.width){
edge_tolerance = params.width;
if (edge_tolerance > width){
edge_tolerance = width;
}
f32 line_shift = 0.f;
@ -1425,7 +1434,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
wrap_state_init(&wrap_state, file, adv);
use_tokens = 1;
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(params.width));
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, FLOOR32(width));
max_wrap_indent_mark = partition_remaining(part)/sizeof(Wrap_Indent_Pair);
wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark);
@ -1477,7 +1486,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
f32 adv = params.adv[ch];
x += adv;
self_x += adv;
if (self_x > params.width){
if (self_x > width){
goto doublebreak;
}
}
@ -1497,7 +1506,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
doublebreak:;
wrap_unit_end = i;
if (x > params.width){
if (x > width){
do_wrap = 1;
file_allocate_wrap_positions_as_needed(system, general, file, wrap_position_index);
file->state.wrap_positions[wrap_position_index++] = stop.pos;
@ -1511,10 +1520,18 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
case BLStatus_NeedWrapLineShift:
case BLStatus_NeedLineShift:
{
f32 current_width = width;
if (use_tokens){
Code_Wrap_State original_wrap_state = wrap_state;
i32 next_line_start = params.buffer->line_starts[stop.line_index+1];
f32 base_adjusted_width = wrap_state.base_x + minimum_base_width;
if (minimum_base_width != 0 && current_width < base_adjusted_width){
current_width = base_adjusted_width;
}
if (stop.status == BLStatus_NeedLineShift){
real_count = 0;
potential_count = 0;
@ -1531,8 +1548,9 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
wrap_indent_marks[real_count].line_shift = clamp_bottom(0.f, current_shift);
++real_count;
wrap_state.base_x = wrap_state.paren_nesting[0];
for (; wrap_state.token_ptr < wrap_state.end_token; ){
Code_Wrap_Step step = {0};
b32 emit_comment_position = 0;
b32 first_word = 1;
@ -1578,7 +1596,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
f32 adv = params.adv[ch];
x += adv;
if (!first_word && x > params.width){
if (!first_word && x > current_width){
emit_comment_position = 1;
goto doublebreak_stage1;
}
@ -1626,7 +1644,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
}
b32 need_to_choose_a_wrap = 0;
if (step.final_x > params.width){
if (step.final_x > current_width){
need_to_choose_a_wrap = 1;
}
@ -1778,14 +1796,13 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
if (line_shift < 0){
line_shift = 0;
}
}
else{
line_shift = 0.f;
}
if (line_shift > params.width - edge_tolerance){
line_shift = params.width - edge_tolerance;
if (line_shift > current_width - edge_tolerance){
line_shift = current_width - edge_tolerance;
}
if (stop.wrap_line_index >= file->state.line_indent_max){
@ -1794,8 +1811,6 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
file->state.line_indents[stop.wrap_line_index] = line_shift;
file->state.wrap_line_count = stop.wrap_line_index;
//wrap_state_set_x(&wrap_state, line_shift);
}break;
}
}while(stop.status != BLStatus_Finished);
@ -4220,8 +4235,7 @@ append_label(String *string, i32 indent_level, char *message){
}
internal void
show_gui_line(GUI_Target *target, String *string,
i32 indent_level, i32 h_align, char *message, char *follow_up){
show_gui_line(GUI_Target *target, String *string, i32 indent_level, i32 h_align, char *message, char *follow_up){
string->size = 0;
append_label(string, indent_level, message);
if (follow_up){

View File

@ -203,7 +203,6 @@ struct Buffer_Measure_Wrap_Params{
Buffer_Type *buffer;
i32 *wrap_line_index;
f32 *adv;
f32 width;
b32 virtual_white;
};
@ -235,8 +234,7 @@ struct Buffer_Measure_Wrap_State{
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
internal_4tech Buffer_Layout_Stop
buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params,
f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
buffer_measure_wrap_y(Buffer_Measure_Wrap_State *S_ptr, Buffer_Measure_Wrap_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
Buffer_Measure_Wrap_State S = *S_ptr;
Buffer_Layout_Stop S_stop;
@ -710,7 +708,6 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character)
struct Buffer_Cursor_Seek_Params{
Buffer_Type *buffer;
Buffer_Seek seek;
f32 width;
f32 font_height;
f32 *adv;
i32 *wrap_line_index;
@ -745,8 +742,7 @@ struct Buffer_Cursor_Seek_State{
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
internal_4tech Buffer_Layout_Stop
buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params,
f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params params, f32 line_shift, b32 do_wrap, i32 wrap_unit_end){
Buffer_Cursor_Seek_State S = *S_ptr;
Buffer_Layout_Stop S_stop;