diff --git a/4coder_API.html b/4coder_API.html index b4e705e6..ba20221f 100644 --- a/4coder_API.html +++ b/4coder_API.html @@ -1657,7 +1657,6 @@ char * file_name;
int32_t file_name_len;
char * buffer_name;
int32_t buffer_name_len;
-int32_t buffer_cursor_pos;
bool32 is_lexed;
int32_t map_id;
@@ -1702,10 +1701,6 @@ int32_t map_id;
This field specifies the length of the buffer_name string.
-
buffer_cursor_pos
-
This is a hold over from an old system, consider it deprecated.
-
-
is_lexed
If this is not a null summary, this field indicates whether the buffer is set to lex tokens.
diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 36b22175..e4ca30d8 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -632,9 +632,10 @@ SEEK_COMMAND(alphanumeric_or_camel, left, BoundaryAlphanumeric | BoundaryCamelC static void write_string(Application_Links *app, String string){ unsigned int access = AccessOpen; - Buffer_Summary buffer = get_active_buffer(app, access); + View_Summary view = app->get_active_view(app, access); + Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, access); app->buffer_replace_range(app, &buffer, - buffer.buffer_cursor_pos, buffer.buffer_cursor_pos, + view.cursor.pos, view.cursor.pos, string.str, string.size); } diff --git a/4coder_types.h b/4coder_types.h index c8f21370..b680e8eb 100644 --- a/4coder_types.h +++ b/4coder_types.h @@ -461,8 +461,6 @@ struct Buffer_Summary{ /* DOC(This field specifies the length of the buffer_name string.) */ int32_t buffer_name_len; - /* DOC(This is a hold over from an old system, consider it deprecated.) */ - int32_t buffer_cursor_pos; /* DOC(If this is not a null summary, this field indicates whether the buffer is set to lex tokens.) */ bool32 is_lexed; /* DOC(If this is not a null summary, this field specifies the id of the command map for this buffer.) */ diff --git a/4ed.cpp b/4ed.cpp index ab780df5..6b43db58 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -320,16 +320,16 @@ COMMAND_DECL(center_view){ f32 y = 0, h = 0; if (view->file_data.unwrapped_lines){ - y = view->recent.cursor.unwrapped_y; + y = view->edit_poss.cursor.unwrapped_y; } else{ - y = view->recent.cursor.wrapped_y; + y = view->edit_poss.cursor.wrapped_y; } h = view_file_height(view); y = clamp_bottom(0.f, y - h*.5f); - view->recent.scroll.target_y = ROUND32(y); + view->edit_poss.scroll.target_y = ROUND32(y); } COMMAND_DECL(left_adjust_view){ @@ -338,39 +338,14 @@ COMMAND_DECL(left_adjust_view){ f32 x = 0; if (view->file_data.unwrapped_lines){ - x = view->recent.cursor.unwrapped_x; + x = view->edit_poss.cursor.unwrapped_x; } else{ - x = view->recent.cursor.wrapped_x; + x = view->edit_poss.cursor.wrapped_x; } x = clamp_bottom(0.f, x - 30.f); - view->recent.scroll.target_x = ROUND32(x); -} - -COMMAND_DECL(set_cursor){ - REQ_READABLE_VIEW(view); - REQ_FILE(file, view); - USE_VARS(vars); - - i32_Rect file_region = view->file_region; - Mouse_State mouse = direct_get_mouse_state(&vars->available_input); - - f32 max_y = view_file_height(view); - f32 max_x = view_file_width(view); - GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated; - - f32 rx = (f32)(mouse.x - file_region.x0); - f32 ry = (f32)(mouse.y - file_region.y0); - - if (ry >= 0){ - if (rx >= 0 && rx < max_x && ry >= 0 && ry < max_y){ - view_cursor_move(view, - rx + scroll_vars.scroll_x, - ry + scroll_vars.scroll_y, - 1); - } - } + view->edit_poss.scroll.target_x = ROUND32(x); } COMMAND_DECL(word_complete){ @@ -383,49 +358,40 @@ COMMAND_DECL(word_complete){ General_Memory *general = &models->mem.general; Working_Set *working_set = &models->working_set; Complete_State *complete_state = &vars->complete_state; - Search_Range *ranges; - Search_Match match; + Search_Range *ranges = 0; - Temp_Memory temp; + Buffer_Type *buffer = &file->state.buffer; + i32 size_of_buffer = buffer_size(buffer); - Buffer_Type *buffer; - Buffer_Backify_Type loop; - char *data; - i32 end; - i32 size_of_buffer; + i32 cursor_pos = 0; + i32 word_start = 0; + i32 word_end = 0; + char c = 0; - i32 cursor_pos, word_start, word_end; - char c; - - char *spare; - i32 size; - - i32 match_size; - b32 do_init = 0; - - buffer = &file->state.buffer; - size_of_buffer = buffer_size(buffer); + char *spare = 0; + i32 size = 0; + b32 do_init = false; if (view->mode.rewrite != 2){ - do_init = 1; + do_init = true; } view->next_mode.rewrite = 2; - if (complete_state->initialized == 0){ - do_init = 1; + do_init = true; } if (do_init){ - word_end = view->recent.cursor.pos; + word_end = view->edit_poss.cursor.pos; word_start = word_end; cursor_pos = word_end - 1; - // TODO(allen): macros for these buffer loops and some method of breaking out of them. - for (loop = buffer_backify_loop(buffer, cursor_pos, 0); + // TODO(allen): macros for these buffer loops and some method + // of breaking out of them. + for (Buffer_Backify_Type loop = buffer_backify_loop(buffer, cursor_pos, 0); buffer_backify_good(&loop); buffer_backify_next(&loop)){ - end = loop.absolute_pos; - data = loop.data - loop.absolute_pos; + i32 end = loop.absolute_pos; + char *data = loop.data - loop.absolute_pos; for (; cursor_pos >= end; --cursor_pos){ c = data[cursor_pos]; if (char_is_alpha(c)){ @@ -495,10 +461,12 @@ COMMAND_DECL(word_complete){ if (size > 0){ for (;;){ - match = search_next_match(part, &complete_state->set, &complete_state->iter); + i32 match_size = 0; + Search_Match match = + search_next_match(part, &complete_state->set, &complete_state->iter); if (match.found_match){ - temp = begin_temp_memory(part); + Temp_Memory temp = begin_temp_memory(part); match_size = match.end - match.start; spare = (char*)push_array(part, char, match_size); buffer_stringify(match.buffer, match.start, match.end, spare); @@ -674,21 +642,18 @@ COMMAND_DECL(toggle_line_wrap){ REQ_READABLE_VIEW(view); REQ_FILE(file, view); + // TODO(allen): WHAT TO DO HERE??? Relative_Scrolling scrolling = view_get_relative_scrolling(view); if (view->file_data.unwrapped_lines){ view->file_data.unwrapped_lines = 0; file->settings.unwrapped_lines = 0; - view->recent.scroll.target_x = 0; - view->recent.cursor = view_compute_cursor_from_pos( - view, view->recent.cursor.pos); - view->recent.preferred_x = view->recent.cursor.wrapped_x; + view->edit_poss.scroll.target_x = 0; + view_cursor_move(view, view->edit_poss.cursor.pos); } else{ view->file_data.unwrapped_lines = 1; file->settings.unwrapped_lines = 1; - view->recent.cursor = - view_compute_cursor_from_pos(view, view->recent.cursor.pos); - view->recent.preferred_x = view->recent.cursor.unwrapped_x; + view_cursor_move(view, view->edit_poss.cursor.pos); } view_set_relative_scrolling(view, scrolling); } @@ -718,7 +683,7 @@ case_change_range(System_Functions *system, Mem_Options *mem, View *view, Editing_File *file, u8 a, u8 z, u8 char_delta){ #if BUFFER_EXPERIMENT_SCALPEL <= 0 - Range range = make_range(view->recent.cursor.pos, view->recent.mark); + Range range = make_range(view->edit_poss.cursor.pos, view->edit_poss.mark); if (range.start < range.end){ Edit_Step step = {}; step.type = ED_NORMAL; @@ -929,25 +894,24 @@ COMMAND_DECL(page_down){ REQ_READABLE_VIEW(view); i32 height = CEIL32(view_file_height(view)); - i32 max_target_y = view->recent.scroll.max_y; + f32 y = view_get_cursor_y(view); + f32 x = view->edit_poss.preferred_x; - view->recent.scroll.target_y = - clamp_top(view->recent.scroll.target_y + height, max_target_y); - - view->recent.cursor = - view_compute_cursor_from_xy(view, 0, view->recent.scroll.target_y + (height - view->line_height)*.5f); + Full_Cursor cursor = + view_compute_cursor_from_xy(view, x, y+height); + edit_pos_set_cursor(&view->edit_poss, cursor, false, view->file_data.unwrapped_lines); } COMMAND_DECL(page_up){ REQ_READABLE_VIEW(view); i32 height = CEIL32(view_file_height(view)); + f32 y = view_get_cursor_y(view); + f32 x = view->edit_poss.preferred_x; - view->recent.scroll.target_y = - clamp_bottom(0, view->recent.scroll.target_y - height); - - view->recent.cursor = - view_compute_cursor_from_xy(view, 0, view->recent.scroll.target_y + (height - view->line_height)*.5f); + Full_Cursor cursor = + view_compute_cursor_from_xy(view, x, y-height); + edit_pos_set_cursor(&view->edit_poss, cursor, false, view->file_data.unwrapped_lines); } COMMAND_DECL(open_color_tweaker){ @@ -2569,7 +2533,11 @@ App_Step_Sig(app_step){ summary.mouse = mouse_state; } - GUI_Scroll_Vars *scroll_vars = view->current_scroll; + GUI_Scroll_Vars *scroll_vars = &view->edit_poss.scroll; + if (view->showing_ui != VUI_None){ + scroll_vars = &view->gui_scroll; + } + Input_Process_Result ip_result = do_step_file_view(system, view, panel->inner, active, &summary, *scroll_vars, view->scroll_region); @@ -2584,8 +2552,16 @@ App_Step_Sig(app_step){ consume_input(&vars->available_input, Input_MouseRightButton, "file view step"); } - Assert(view->current_scroll == scroll_vars); - *scroll_vars = ip_result.vars; + + if (!gui_scroll_eq(scroll_vars, &ip_result.vars)){ + if (scroll_vars == &view->edit_poss.scroll){ + edit_pos_set_scroll(&view->edit_poss, ip_result.vars); + } + else{ + *scroll_vars = ip_result.vars; + } + } + view->scroll_region = ip_result.region; } } @@ -2731,14 +2707,15 @@ App_Step_Sig(app_step){ String welcome = make_lit_string("Welcome to " VERSION "\n" "If you're new to 4coder there's no tutorial yet :(\n" - "you can use the key combo control + o to look for a file\n" + "you can use the key combo to look for a file\n" "and if you load README.txt you'll find all the key combos there are.\n" "\n" "Newest features:\n" "-A scratch buffer is now opened with 4coder automatically\n" - "- toggels mouse suppression mode\n" - "-Experimental new work-flow for building a jumping to errors\n" - " (only available in power for this version)\n" + "-A new mouse suppression mode toggled by \n" + "-New 4coder_API.html documentation file included for the custom layer API\n" + "-Experimental new work-flow for building and jumping to errors\n" + " (only available in power for this build)\n" "\n" "New in alpha 4.0.8:\n" "-Eliminated the parameter stack\n" @@ -2750,12 +2727,12 @@ App_Step_Sig(app_step){ "\n" "New in alpha 4.0.6:\n" "-Tied the view scrolling and the list arrow navigation together\n" - "-Scroll bars are now toggleable with ALT-s for show and ALT-w for hide\n" + "-Scroll bars are now toggleable with for show and for hide\n" "\n" "New in alpha 4.0.5:\n" "-New indent rule\n" "-app->buffer_compute_cursor in the customization API\n" - "-f keys are available\n" + "-f keys are available in the customization system now\n" "\n" "New in alpha 4.0.3 and 4.0.4:\n" "-Scroll bar on files and file lists\n" @@ -2949,8 +2926,15 @@ App_Step_Sig(app_step){ draw_rectangle(target, full, back_color); draw_push_clip(target, panel->inner); - do_render_file_view(system, view, cmd->view, + + GUI_Scroll_Vars *scroll_vars = &view->edit_poss.scroll; + if (view->showing_ui != VUI_None){ + scroll_vars = &view->gui_scroll; + } + + do_render_file_view(system, view, scroll_vars, cmd->view, panel->inner, active, target, &dead_input); + draw_pop_clip(target); u32 margin_color; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index e93f95d6..8163b314 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -25,7 +25,6 @@ fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *wor buffer->is_lexed = file->settings.tokens_exist; buffer->buffer_id = file->id.id; buffer->size = file->state.buffer.size; - buffer->buffer_cursor_pos = file->state.cursor_pos; buffer->file_name_len = file->name.source_path.size; buffer->buffer_name_len = file->name.live_name.size; @@ -67,12 +66,12 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_ view->buffer_id = buffer_id; - view->mark = view_compute_cursor_from_pos(vptr, vptr->recent.mark); - view->cursor = vptr->recent.cursor; - view->preferred_x = vptr->recent.preferred_x; + view->mark = view_compute_cursor_from_pos(vptr, vptr->edit_poss.mark); + view->cursor = vptr->edit_poss.cursor; + view->preferred_x = vptr->edit_poss.preferred_x; view->file_region = vptr->file_region; - view->scroll_vars = *vptr->current_scroll; + view->scroll_vars = vptr->edit_poss.scroll; } } } @@ -683,20 +682,14 @@ DOC_SEE(4coder_Buffer_Positioning_System) bool32 result = false; int32_t size = 0; - int32_t next_cursor = 0, pos = 0; if (file){ size = buffer_size(&file->state.buffer); if (0 <= start && start <= end && end <= size){ result = true; - pos = file->state.cursor_pos; - if (pos < start) next_cursor = pos; - else if (pos < end) next_cursor = start; - else next_cursor = pos + end - start - len; - file_replace_range(cmd->system, cmd->models, - file, start, end, str, len, next_cursor); + file, start, end, str, len, 0); } fill_buffer_summary(buffer, file, cmd); } @@ -1242,12 +1235,10 @@ DOC_SEE(Buffer_Seek) if (seek.type == buffer_seek_line_char && seek.character <= 0){ seek.character = 1; } - vptr->recent.cursor = view_compute_cursor(vptr, seek); - if (set_preferred_x){ - vptr->recent.preferred_x = view_get_cursor_x(vptr); - } + Full_Cursor cursor = view_compute_cursor(vptr, seek); + edit_pos_set_cursor(&vptr->edit_poss, cursor, + set_preferred_x, vptr->file_data.unwrapped_lines); fill_view_summary(view, vptr, cmd); - file->state.cursor_pos = vptr->recent.cursor.pos; } } @@ -1271,10 +1262,10 @@ DOC_SEE(Buffer_Seek) result = true; if (seek.type != buffer_seek_pos){ cursor = view_compute_cursor(vptr, seek); - vptr->recent.mark = cursor.pos; + vptr->edit_poss.mark = cursor.pos; } else{ - vptr->recent.mark = seek.pos; + vptr->edit_poss.mark = seek.pos; } fill_view_summary(view, vptr, cmd); } diff --git a/4ed_file.cpp b/4ed_file.cpp index 09ed78c1..36f8db48 100644 --- a/4ed_file.cpp +++ b/4ed_file.cpp @@ -112,8 +112,6 @@ struct Editing_File_State{ i16 font_id; Buffer_Type buffer; - i32 cursor_pos; - Undo_Data undo; Cpp_Token_Stack token_stack; diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 04ae5673..956fcc8b 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -162,16 +162,23 @@ file_viewing_data_zero(){ return(data); } -struct Recent_File_Data{ +enum Edit_Pos_Set_Type{ + EditPos_None, + EditPos_CursorSet, + EditPos_ScrollSet +}; +struct File_Edit_Positions{ GUI_Scroll_Vars scroll; Full_Cursor cursor; i32 mark; f32 preferred_x; i32 scroll_i; + + i32 last_set_type; }; -inline Recent_File_Data -recent_file_data_zero(){ - Recent_File_Data data = {0}; +inline File_Edit_Positions +file_edit_positions_zero(){ + File_Edit_Positions data = {0}; return(data); } @@ -223,16 +230,17 @@ struct View{ Command_Map *map; File_Viewing_Data file_data; + +#if 0 i32 prev_cursor_pos; Scroll_Context prev_context; - +#endif + i32_Rect file_region_prev; i32_Rect file_region; i32_Rect scroll_region; - Recent_File_Data recent; - - GUI_Scroll_Vars *current_scroll; + File_Edit_Positions edit_poss; View_UI showing_ui; GUI_Target gui_target; @@ -679,7 +687,7 @@ inline i32 view_compute_max_target_y(View *view){ i32 lowest_line = view_compute_lowest_line(view); i32 line_height = view->line_height; - f32 view_height = view_file_height(view); + f32 view_height = clamp_bottom((f32)line_height, view_file_height(view)); i32 max_target_y = view_compute_max_target_y(lowest_line, line_height, view_height); return(max_target_y); } @@ -1490,6 +1498,28 @@ view_set_temp_highlight(View *view, i32 pos, i32 end_pos){ view->file_data.show_temp_highlight = 1; } +internal void +edit_pos_set_cursor(File_Edit_Positions *edit_poss, + Full_Cursor cursor, + b32 set_preferred_x, + b32 unwrapped_lines){ + edit_poss->cursor = cursor; + if (set_preferred_x){ + edit_poss->preferred_x = cursor.wrapped_x; + if (unwrapped_lines){ + edit_poss->preferred_x = cursor.unwrapped_x; + } + } + edit_poss->last_set_type = EditPos_CursorSet; +} + +internal void +edit_pos_set_scroll(File_Edit_Positions *edit_poss, + GUI_Scroll_Vars scroll){ + edit_poss->scroll = scroll; + edit_poss->last_set_type = EditPos_ScrollSet; +} + inline i32 view_get_cursor_pos(View *view){ i32 result; @@ -1497,40 +1527,41 @@ view_get_cursor_pos(View *view){ result = view->file_data.temp_highlight.pos; } else{ - result = view->recent.cursor.pos; + result = view->edit_poss.cursor.pos; } return result; } inline f32 view_get_cursor_x(View *view){ - f32 result; - Full_Cursor *cursor; + f32 result = 0; + + Full_Cursor *cursor = &view->edit_poss.cursor; if (view->file_data.show_temp_highlight){ cursor = &view->file_data.temp_highlight; } - else{ - cursor = &view->recent.cursor; - } + + result = cursor->wrapped_y; if (view->file_data.unwrapped_lines){ result = cursor->unwrapped_x; } - else{ - result = cursor->wrapped_x; - } + return result; } inline f32 view_get_cursor_y(View *view){ - Full_Cursor *cursor; - f32 result; + f32 result = 0; - if (view->file_data.show_temp_highlight) cursor = &view->file_data.temp_highlight; - else cursor = &view->recent.cursor; + Full_Cursor *cursor = &view->edit_poss.cursor; + if (view->file_data.show_temp_highlight){ + cursor = &view->file_data.temp_highlight; + } - if (view->file_data.unwrapped_lines) result = cursor->unwrapped_y; - else result = cursor->wrapped_y; + result = cursor->wrapped_y; + if (view->file_data.unwrapped_lines){ + result = cursor->unwrapped_y; + } return result; } @@ -1592,8 +1623,11 @@ view_move_cursor_to_view(View *view, GUI_Scroll_Vars scroll){ else{ cursor_y -= line_height; } - view->recent.cursor = - view_compute_cursor_from_xy(view, view->recent.preferred_x, cursor_y); + + Full_Cursor new_cursor = + view_compute_cursor_from_xy(view, view->edit_poss.preferred_x, cursor_y); + edit_pos_set_cursor(&view->edit_poss, new_cursor, + false, view->file_data.unwrapped_lines); } } @@ -1663,16 +1697,19 @@ view_set_file(View *view, Editing_File *file, Models *models){ if (file){ view->file_data.unwrapped_lines = file->settings.unwrapped_lines; - Recent_File_Data *recent = &view->recent; - *recent = recent_file_data_zero(); + // TODO(allen): Here is where the fancy logic goes for + // File_Edit_Positions stuff. + + File_Edit_Positions *edit_poss = &view->edit_poss; + *edit_poss = file_edit_positions_zero(); if (file_is_ready(file)){ view_measure_wraps(&models->mem.general, view); - recent->cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos); - recent->scroll.max_y = view_compute_max_target_y(view); - recent->preferred_x = view_get_cursor_x(view); + edit_poss->cursor = view_compute_cursor_from_pos(view, 0); + edit_poss->scroll.max_y = view_compute_max_target_y(view); + edit_poss->preferred_x = view_get_cursor_x(view); - view_move_view_to_cursor(view, &recent->scroll, true); + view_move_view_to_cursor(view, &edit_poss->scroll, true); view->reinit_scrolling = 1; } } @@ -1687,24 +1724,24 @@ internal Relative_Scrolling view_get_relative_scrolling(View *view){ Relative_Scrolling result; f32 cursor_y = view_get_cursor_y(view); - result.scroll_y = cursor_y - view->recent.scroll.scroll_y; - result.target_y = cursor_y - view->recent.scroll.target_y; + result.scroll_y = cursor_y - view->edit_poss.scroll.scroll_y; + result.target_y = cursor_y - view->edit_poss.scroll.target_y; return(result); } internal void view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){ f32 cursor_y = view_get_cursor_y(view); - view->recent.scroll.scroll_y = cursor_y - scrolling.scroll_y; - view->recent.scroll.target_y = + + view->edit_poss.scroll.scroll_y = cursor_y - scrolling.scroll_y; + view->edit_poss.scroll.target_y = ROUND32(clamp_bottom(0.f, cursor_y - scrolling.target_y)); } inline void view_cursor_move(View *view, Full_Cursor cursor){ - view->recent.cursor = cursor; - view->recent.preferred_x = view_get_cursor_x(view); - view->file_data.file->state.cursor_pos = view->recent.cursor.pos; + edit_pos_set_cursor(&view->edit_poss, cursor, + true, view->file_data.unwrapped_lines); view->file_data.show_temp_highlight = 0; } @@ -1945,7 +1982,6 @@ file_edit_cursor_fix(System_Functions *system, i32 cursor_max = layout->panel_max_count * 2; Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max); - f32 y_offset = 0, y_position = 0; i32 cursor_count = 0; View *view; @@ -1956,9 +1992,9 @@ file_edit_cursor_fix(System_Functions *system, view = panel->view; if (view->file_data.file == file){ view_measure_wraps(general, view); - write_cursor_with_index(cursors, &cursor_count, view->recent.cursor.pos); - write_cursor_with_index(cursors, &cursor_count, view->recent.mark - 1); - write_cursor_with_index(cursors, &cursor_count, view->recent.scroll_i - 1); + write_cursor_with_index(cursors, &cursor_count, view->edit_poss.cursor.pos); + write_cursor_with_index(cursors, &cursor_count, view->edit_poss.mark - 1); + write_cursor_with_index(cursors, &cursor_count, view->edit_poss.scroll_i - 1); } } @@ -1980,27 +2016,25 @@ file_edit_cursor_fix(System_Functions *system, view = panel->view; if (view && view->file_data.file == file){ view_cursor_move(view, cursors[cursor_count++].pos); - view->recent.preferred_x = view_get_cursor_x(view); - view->recent.mark = cursors[cursor_count++].pos + 1; + view->edit_poss.mark = cursors[cursor_count++].pos + 1; i32 new_scroll_i = cursors[cursor_count++].pos + 1; - if (view->recent.scroll_i != new_scroll_i){ - view->recent.scroll_i = new_scroll_i; - temp_cursor = view_compute_cursor_from_pos(view, view->recent.scroll_i); - y_offset = MOD(view->recent.scroll.scroll_y, view->line_height); + if (view->edit_poss.scroll_i != new_scroll_i){ + view->edit_poss.scroll_i = new_scroll_i; + temp_cursor = view_compute_cursor_from_pos(view, view->edit_poss.scroll_i); + f32 y_offset = MOD(view->edit_poss.scroll.scroll_y, view->line_height); + f32 y_position = temp_cursor.wrapped_y; if (view->file_data.unwrapped_lines){ - y_position = temp_cursor.unwrapped_y + y_offset; - view->recent.scroll.target_y += - ROUND32(y_position - view->recent.scroll.scroll_y); - view->recent.scroll.scroll_y = y_position; - } - else{ - y_position = temp_cursor.wrapped_y + y_offset; - view->recent.scroll.target_y += - ROUND32(y_position - view->recent.scroll.scroll_y); - view->recent.scroll.scroll_y = y_position; + y_position = temp_cursor.unwrapped_y; } + y_position += y_offset; + + GUI_Scroll_Vars scroll = view->edit_poss.scroll; + scroll.target_y += + ROUND32(y_position - scroll.scroll_y); + scroll.scroll_y = y_position; + edit_pos_set_scroll(&view->edit_poss, scroll); } } } @@ -2238,7 +2272,7 @@ view_undo_redo(System_Functions *system, file_do_single_edit(system, models, file, spec, hist_normal); view_cursor_move(view, step.edit.start + step.edit.len); - view->recent.mark = view->recent.cursor.pos; + view->edit_poss.mark = view->edit_poss.cursor.pos; Style *style = main_style(models); view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, @@ -2370,7 +2404,7 @@ view_history_step(System_Functions *system, Models *models, View *view, History_ view_cursor_move(view, step.edit.start + step.edit.len); break; } - view->recent.mark = view->recent.cursor.pos; + view->edit_poss.mark = view->edit_poss.cursor.pos; } else{ TentativeAssert(spec.step.special_type == 1); @@ -2536,7 +2570,7 @@ view_clean_whitespace(System_Functions *system, Models *models, View *view){ char *inv_str = (char*)part->base + part->pos; Edit_Spec spec = file_compute_whitespace_edit(mem, file, - view->recent.cursor.pos, + view->edit_poss.cursor.pos, edits, str_base, str_size, inverse_array, inv_str, part->max - part->pos, edit_count); @@ -3037,8 +3071,7 @@ remeasure_file_view(System_Functions *system, View *view){ Relative_Scrolling relative = view_get_relative_scrolling(view); view_measure_wraps(&view->persistent.models->mem.general, view); if (view->file_data.show_temp_highlight == 0){ - view_cursor_move(view, view->recent.cursor.pos); - view->recent.preferred_x = view_get_cursor_x(view); + view_cursor_move(view, view->edit_poss.cursor.pos); } view_set_relative_scrolling(view, relative); } @@ -3048,7 +3081,6 @@ inline void view_show_GUI(View *view, View_UI ui){ view->map = &view->persistent.models->map_ui; view->showing_ui = ui; - view->current_scroll = &view->gui_scroll; view->changed_context_in_step = 1; } @@ -3065,7 +3097,6 @@ view_show_interactive(System_Functions *system, View *view, view->interaction = interaction; view->dest = make_fixed_width_string(view->dest_); view->list_i = 0; - view->current_scroll = &view->gui_scroll; view->map = &models->map_ui; @@ -3081,7 +3112,6 @@ view_show_theme(View *view){ view->color_mode = CV_Mode_Library; view->color = super_color_create(0xFF000000); view->current_color_editing = 0; - view->current_scroll = &view->gui_scroll; view->changed_context_in_step = 1; } @@ -3094,10 +3124,12 @@ view_show_file(View *view){ else{ view->map = get_map(view->persistent.models, mapid_global); } - view->showing_ui = VUI_None; - view->current_scroll = &view->recent.scroll; - view->recent.scroll.max_y = view_compute_max_target_y(view); - view->changed_context_in_step = 1; + + if (view->showing_ui != VUI_None){ + view->showing_ui = VUI_None; + view->changed_context_in_step = true; + view->reinit_scrolling = true; + } } internal void @@ -3486,7 +3518,7 @@ intbar_draw_string(Render_Target *target, File_Bar *bar, String str, u32 char_co bar->pos_x += font_string_width(target, font_id, str); } -internal void +internal GUI_Scroll_Vars view_reinit_scrolling(View *view){ Editing_File *file = view->file_data.file; f32 w = 0, h = 0; @@ -3509,69 +3541,55 @@ view_reinit_scrolling(View *view){ target_y = clamp_bottom(0, FLOOR32(cursor_y - h*.5f)); } - view->recent.scroll.target_y = target_y; - view->recent.scroll.scroll_y = (f32)target_y; - view->recent.scroll.prev_target_y = -1000; + GUI_Scroll_Vars scroll = {0}; - view->recent.scroll.target_x = target_x; - view->recent.scroll.scroll_x = (f32)target_x; - view->recent.scroll.prev_target_x = -1000; -} - -enum CursorScroll_State{ - CursorScroll_NoChange = 0x0, - CursorScroll_Cursor = 0x1, - CursorScroll_Scroll = 0x2, - CursorScroll_ContextChange = 0x4 -}; - -internal u32 -view_get_cursor_scroll_change_state(View *view){ - u32 result = 0; - i32 pos = 0; - Scroll_Context context = {0}; - - if (view->gui_target.did_file){ - pos = view_get_cursor_pos(view); - if ((view->prev_cursor_pos != pos)){ - result |= CursorScroll_Cursor; - } - } - - if (view->current_scroll){ - if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_original)){ - result |= CursorScroll_Scroll; - } - } - - if (context.mode == VUI_None){ - context.file = view->file_data.file; - } - else{ - context.file = view->prev_context.file; - } - context.scroll = view->gui_target.scroll_id; - context.mode = view->showing_ui; - - if (!context_eq(view->prev_context, context)){ - result |= CursorScroll_ContextChange; - } - - return(result); + scroll.target_y = target_y; + scroll.scroll_y = (f32)target_y; + scroll.prev_target_y = -1000; + + scroll.target_x = target_x; + scroll.scroll_x = (f32)target_x; + scroll.prev_target_x = -1000; + + return(scroll); } +// TODO(allen): GTFO! internal void view_begin_cursor_scroll_updates(View *view){ + +#if 0 if (view->file_data.file && view->file_data.file == view->prev_context.file){ Assert(view->prev_cursor_pos == view_get_cursor_pos(view)); } +#endif + } internal void view_end_cursor_scroll_updates(View *view){ - i32 cursor_scroll_state = - view_get_cursor_scroll_change_state(view); + i32 set_type = view->edit_poss.last_set_type; + switch (set_type){ + case EditPos_None: break; + + case EditPos_CursorSet: + { + if (view->gui_target.did_file){ + view->edit_poss.scroll.max_y = view_compute_max_target_y(view); + } + view_move_view_to_cursor(view, &view->edit_poss.scroll, false); + gui_post_scroll_vars(&view->gui_target, &view->edit_poss.scroll, view->scroll_region); + }break; + + case EditPos_ScrollSet: + { + view_move_cursor_to_view(view, view->edit_poss.scroll); + gui_post_scroll_vars(&view->gui_target, &view->edit_poss.scroll, view->scroll_region); + }break; + } + +#if 0 switch (cursor_scroll_state){ case CursorScroll_NoChange:break; @@ -3601,6 +3619,7 @@ view_end_cursor_scroll_updates(View *view){ view->prev_context.file = view->file_data.file; view->prev_context.scroll = view->gui_target.scroll_id; view->prev_context.mode = view->showing_ui; +#endif } internal b32 @@ -4020,8 +4039,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su b32 show_scrollbar = !view->hide_scrollbar; - view->current_scroll = 0; - if (view->showing_ui != VUI_None){ b32 did_esc = 0; Key_Event_Data key; @@ -4057,11 +4074,15 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su scroll_context.id[1] = view->showing_ui; scroll_context.id[0] = (u64)(view->file_data.file); - view->current_scroll = &view->recent.scroll; + // TODO(allen): ???? + +#if 0 gui_get_scroll_vars(target, scroll_context, &view->recent.scroll, &view->scroll_region); - - gui_begin_scrollable(target, scroll_context, view->recent.scroll, +#endif + + gui_begin_scrollable(target, scroll_context, + view->edit_poss.scroll, delta, show_scrollbar); gui_do_file(target); gui_end_scrollable(target); @@ -4072,8 +4093,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su switch (view->showing_ui){ case VUI_Menu: { - view->current_scroll = &view->gui_scroll; - String message = make_lit_string("Menu"); String empty_string = {0}; GUI_id id = {0}; @@ -4096,8 +4115,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case VUI_Config: { - view->current_scroll = &view->gui_scroll; - String message = make_lit_string("Config"); String empty_string = {0}; GUI_id id = {0}; @@ -4114,8 +4131,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case VUI_Theme: { - view->current_scroll = &view->gui_scroll; - if (view != active_view){ view->hot_file_view = active_view; } @@ -4149,8 +4164,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su message = make_lit_string("Theme Library - Click to Select"); gui_do_text_field(target, message, empty_string); - view->current_scroll = &view->gui_scroll; - gui_get_scroll_vars(target, scroll_context, &view->gui_scroll, &view->scroll_region); + gui_get_scroll_vars(target, scroll_context, &view->scroll_region); gui_begin_scrollable(target, scroll_context, view->gui_scroll, 9 * view->line_height, show_scrollbar); @@ -4223,8 +4237,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su view->color_mode = CV_Mode_Library; } - view->current_scroll = &view->gui_scroll; - gui_get_scroll_vars(target, scroll_context, &view->gui_scroll, &view->scroll_region); + gui_get_scroll_vars(target, scroll_context, &view->scroll_region); gui_begin_scrollable(target, scroll_context, view->gui_scroll, 9 * view->line_height, show_scrollbar); @@ -4311,8 +4324,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su String comp_dest = make_fixed_width_string(comp_dest_space); i32 comp_action = 0; - view->current_scroll = &view->gui_scroll; - GUI_id id = {0}; id.id[1] = VUI_Interactive + ((u64)view->interaction << 32); @@ -4369,7 +4380,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su scroll_context.id[0] = (u64)(hdir); if (gui_get_scroll_vars(target, scroll_context, - &view->gui_scroll, &view->scroll_region)){ + &view->scroll_region)){ snap_into_view = 1; } gui_begin_scrollable(target, scroll_context, view->gui_scroll, @@ -4380,7 +4391,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su if (gui_begin_list(target, id, view->list_i, 0, snap_into_view, &update)){ // TODO(allen): Allow me to handle key consumption correctly here! - gui_standard_list(target, id, view->current_scroll, view->scroll_region, + gui_standard_list(target, id, &view->gui_scroll, + view->scroll_region, &keys, &view->list_i, &update); } @@ -4435,8 +4447,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case IAct_Kill: message = make_lit_string("Kill: "); break; } - Absolutes absolutes; - Editing_File *file; Working_Set *working_set = &models->working_set; Editing_Layout *layout = &models->layout; GUI_Item_Update update = {0}; @@ -4455,13 +4465,14 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } } + Absolutes absolutes = {0}; get_absolutes(view->dest, &absolutes, 1, 1); gui_do_text_field(target, message, view->dest); scroll_context.id[0] = (u64)(working_set); if (gui_get_scroll_vars(target, scroll_context, - &view->gui_scroll, &view->scroll_region)){ + &view->scroll_region)){ snap_into_view = 1; } gui_begin_scrollable(target, scroll_context, view->gui_scroll, @@ -4470,7 +4481,8 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su id.id[0] = (u64)(working_set) + 1; if (gui_begin_list(target, id, view->list_i, 0, snap_into_view, &update)){ - gui_standard_list(target, id, view->current_scroll, view->scroll_region, + gui_standard_list(target, id, &view->gui_scroll, + view->scroll_region, &keys, &view->list_i, &update); } @@ -4487,7 +4499,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su used_nodes = &working_set->used_sentinel; for (dll_items(node, used_nodes)){ - file = (Editing_File*)node; + Editing_File *file = (Editing_File*)node; Assert(!file->is_dummy); if (filename_match(view->dest, &absolutes, file->name.live_name, 1)){ @@ -4519,7 +4531,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su } for (i = 0; i < reserved_top; ++i){ - file = reserved_files[i]; + Editing_File *file = reserved_files[i]; message = string_zero(); if (!file->settings.unimportant){ @@ -4621,8 +4633,6 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su GUI_id id = {0}; id.id[1] = VUI_Debug + ((u64)view->debug_vars.mode << 32); - view->current_scroll = &view->gui_scroll; - // TODO(allen): // + Incoming input // + Memory info @@ -4925,27 +4935,28 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su view_ptr->file_data.line_count, view_ptr->file_data.line_max); - GUI_Scroll_Vars scroll = *view_ptr->current_scroll; - SHOW_GUI_BLANK(0); SHOW_GUI_REGION(1, h_align, "scroll region", view_ptr->scroll_region); SHOW_GUI_BLANK(0); - SHOW_GUI_LINE(1, "recent file data"); + SHOW_GUI_LINE(1, "file editing positions"); { - Recent_File_Data *recent = &view_ptr->recent; + File_Edit_Positions *edit_poss = &view_ptr->edit_poss; - SHOW_GUI_SCROLL(2, h_align, "scroll:", recent->scroll); + SHOW_GUI_SCROLL(2, h_align, "scroll:", edit_poss->scroll); SHOW_GUI_BLANK (2); - SHOW_GUI_CURSOR(2, h_align, "cursor:", recent->cursor); + SHOW_GUI_CURSOR(2, h_align, "cursor:", edit_poss->cursor); SHOW_GUI_BLANK (2); - SHOW_GUI_INT (2, h_align, "mark", recent->mark); - SHOW_GUI_FLOAT (2, h_align, "preferred_x", recent->preferred_x); - SHOW_GUI_INT (2, h_align, "scroll_i", recent->scroll_i); + SHOW_GUI_INT (2, h_align, "mark", edit_poss->mark); + SHOW_GUI_FLOAT (2, h_align, "preferred_x", edit_poss->preferred_x); + SHOW_GUI_INT (2, h_align, "scroll_i", edit_poss->scroll_i); } SHOW_GUI_BLANK (0); - SHOW_GUI_SCROLL(1, h_align, "curent scroll:", scroll); + SHOW_GUI_SCROLL(1, h_align, "curent scroll:", view_ptr->edit_poss.scroll); + + SHOW_GUI_BLANK (0); + SHOW_GUI_SCROLL(1, h_align, "gui scroll:", view_ptr->gui_scroll); SHOW_GUI_BLANK (0); SHOW_GUI_LINE (1, "gui target"); @@ -4965,7 +4976,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su SHOW_GUI_REGION (2, h_align, "region_original", view_ptr->gui_target.region_original); SHOW_GUI_BLANK (2); - SHOW_GUI_SCROLL (2, h_align, "scroll_updated", view_ptr->gui_target.scroll_updated); +// SHOW_GUI_SCROLL (2, h_align, "scroll_updated", view_ptr->gui_target.scroll_updated); SHOW_GUI_REGION (2, h_align, "region_updated", view_ptr->gui_target.region_updated); @@ -4991,7 +5002,7 @@ internal f32 view_get_scroll_y(View *view){ f32 v; if (view->showing_ui == VUI_None){ - v = view->recent.scroll.scroll_y; + v = view->edit_poss.scroll.scroll_y; } else{ v = view->gui_scroll.scroll_y; @@ -5115,15 +5126,16 @@ do_step_file_view(System_Functions *system, case guicom_file: { - i32 new_max_y = view_compute_max_target_y(view); - + // NOTE(allen): Set the file region first because the + // computation of view_compute_max_target_y depends on it. view->file_region = gui_session.rect; - result.vars.max_y = new_max_y; if (view->reinit_scrolling){ - view_reinit_scrolling(view); + result.vars = view_reinit_scrolling(view); result.is_animating = true; } + result.vars.max_y = view_compute_max_target_y(view); + if (file_step(view, gui_session.rect, user_input, is_active, &result.consumed_l)){ result.is_animating = true; } @@ -5326,8 +5338,8 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target Buffer_Render_Options opts = {}; f32 *wraps = view->file_data.line_wrap_y; - f32 scroll_x = view->recent.scroll.scroll_x; - f32 scroll_y = view->recent.scroll.scroll_y; + f32 scroll_x = view->edit_poss.scroll.scroll_x; + f32 scroll_y = view->edit_poss.scroll.scroll_y; // NOTE(allen): For now we will temporarily adjust scroll_y to try // to prevent the view moving around until floating sections are added @@ -5340,7 +5352,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target (f32)max_x, advance_data, (f32)line_height); - view->recent.scroll_i = render_cursor.pos; + view->edit_poss.scroll_i = render_cursor.pos; buffer_get_render_data(&file->state.buffer, items, max, &count, (f32)rect.x0, (f32)rect.y0, @@ -5362,7 +5374,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target at_cursor_color = style->main.at_highlight_color; } else{ - cursor_begin = view->recent.cursor.pos; + cursor_begin = view->edit_poss.cursor.pos; cursor_end = cursor_begin + 1; cursor_color = style->main.cursor_color; at_cursor_color = style->main.at_cursor_color; @@ -5452,7 +5464,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target char_color = color_blend(char_color, fade_amount, fade_color); - if (ind == view->recent.mark && prev_ind != ind){ + if (ind == view->edit_poss.mark && prev_ind != ind){ draw_rectangle_outline(target, char_rect, mark_color); } if (item->glyphid != 0){ @@ -5570,9 +5582,9 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re char line_number_space[30]; String line_number = make_fixed_width_string(line_number_space); append(&line_number, " L#"); - append_int_to_str(&line_number, view->recent.cursor.line); + append_int_to_str(&line_number, view->edit_poss.cursor.line); append(&line_number, " C#"); - append_int_to_str(&line_number, view->recent.cursor.character); + append_int_to_str(&line_number, view->edit_poss.cursor.character); intbar_draw_string(target, &bar, line_number, base_color); @@ -5775,7 +5787,7 @@ draw_style_preview(GUI_Target *gui_target, Render_Target *target, View *view, i3 } internal i32 -do_render_file_view(System_Functions *system, View *view, +do_render_file_view(System_Functions *system, View *view, GUI_Scroll_Vars *scroll, View *active, i32_Rect rect, b32 is_active, Render_Target *target, Input_Summary *user_input){ @@ -5801,8 +5813,7 @@ do_render_file_view(System_Functions *system, View *view, h->type; h = NextHeader(h)){ interpret_result = gui_interpret(gui_target, &gui_session, h, - *view->current_scroll, - view->scroll_region); + *scroll, view->scroll_region); if (interpret_result.has_info){ if (gui_session.clip_y > clip_rect.y0){ @@ -5818,9 +5829,6 @@ do_render_file_view(System_Functions *system, View *view, case guicom_file: { - if (view->reinit_scrolling){ - view_reinit_scrolling(view); - } if (file && file_is_ready(file)){ result = draw_file_loaded(view, gui_session.rect, is_active, target); } @@ -6196,7 +6204,9 @@ inline void view_change_size(General_Memory *general, View *view){ if (view->file_data.file){ view_measure_wraps(general, view); - view->recent.cursor = view_compute_cursor_from_pos(view, view->recent.cursor.pos); + Full_Cursor cursor = view_compute_cursor_from_pos(view, view->edit_poss.cursor.pos); + edit_pos_set_cursor(&view->edit_poss, cursor, + false, view->file_data.unwrapped_lines); } } @@ -6219,7 +6229,6 @@ live_set_alloc_view(Live_Views *live_set, Panel *panel, Models *models){ result.view->panel = panel; result.view->persistent.models = models; - result.view->current_scroll = &result.view->recent.scroll; update_view_line_height(models, result.view); diff --git a/4ed_gui.cpp b/4ed_gui.cpp index 996cbff5..b5321c73 100644 --- a/4ed_gui.cpp +++ b/4ed_gui.cpp @@ -124,7 +124,7 @@ struct GUI_Target{ GUI_Scroll_Vars scroll_original; i32_Rect region_original; - GUI_Scroll_Vars scroll_updated; + //GUI_Scroll_Vars scroll_updated; i32_Rect region_updated; // TODO(allen): Would rather have a way of tracking this @@ -656,14 +656,11 @@ gui_scroll_eq(GUI_Scroll_Vars *a, GUI_Scroll_Vars *b){ // TODO(allen): Rethink this a little, seems like there are two separate things we want to do here: // Getting the updated scroll vars, and telling the user when scrolling actions occur. internal b32 -gui_get_scroll_vars(GUI_Target *target, GUI_id scroll_context_id, GUI_Scroll_Vars *vars_out, i32_Rect *region_out){ +gui_get_scroll_vars(GUI_Target *target, GUI_id scroll_context_id, i32_Rect *region_out){ b32 result = 0; if (gui_id_eq(scroll_context_id, target->scroll_id)){ - *vars_out = target->scroll_updated; *region_out = target->region_updated; - vars_out->target_y = clamp(0, vars_out->target_y, vars_out->max_y); - if (gui_id_eq(target->active, gui_id_scrollbar())){ result = 1; target->animating = 1; @@ -674,9 +671,7 @@ gui_get_scroll_vars(GUI_Target *target, GUI_id scroll_context_id, GUI_Scroll_Var internal void gui_post_scroll_vars(GUI_Target *target, GUI_Scroll_Vars *vars_in, i32_Rect region_in){ - if (!gui_scroll_eq(vars_in, &target->scroll_updated) || - !rect_equal(region_in, target->region_updated)){ - target->scroll_updated = *vars_in; + if (!rect_equal(region_in, target->region_updated)){ target->region_updated = region_in; target->animating = 1; target->active = gui_id_scrollbar(); @@ -694,7 +689,6 @@ gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id, h = gui_push_simple_command(target, guicom_scrollable); target->scroll_original = scroll_vars; - target->scroll_updated = scroll_vars; target->scroll_id = scroll_context_id; if (show_bar){ @@ -1230,6 +1224,12 @@ gui_compute_view_jump(i32_Rect scroll_region, i32_Rect position){ internal GUI_Scroll_Vars gui_do_jump(GUI_Target *target, GUI_View_Jump jump, GUI_Scroll_Vars vars){ + if (jump.view_max < 0){ + jump.view_max = 0; + } + if (jump.view_min < 0){ + jump.view_min = 0; + } if (vars.target_y < jump.view_min){ vars.target_y = jump.view_min; }