Remove scroll_i and fix the bopping around of the view for single file side by side editing

master
Allen Webster 2019-02-09 18:56:29 -08:00
parent 66a06053b6
commit 357125c8b2
4 changed files with 97 additions and 33 deletions

View File

@ -23,6 +23,18 @@ edit_pre_state_change(System_Functions *system, Heap *heap, Models *models, Edit
file_set_dirty_flag(file, DirtyState_UnsavedChanges); file_set_dirty_flag(file, DirtyState_UnsavedChanges);
} }
file_unmark_edit_finished(file); file_unmark_edit_finished(file);
Layout *layout = &models->layout;
for (Panel *panel = layout_get_first_open_panel(layout);
panel != 0;
panel = layout_get_next_open_panel(layout, panel)){
View *view = panel->view;
if (view->transient.file_data.file == file){
Full_Cursor render_cursor = view_get_render_cursor(system, view);
Full_Cursor target_cursor = view_get_render_cursor_target(system, view);
view->transient.temp_view_top_left_pos = render_cursor.pos;
view->transient.temp_view_top_left_target_pos = target_cursor.pos;
}
}
} }
internal void internal void
@ -54,7 +66,6 @@ edit_fix_markers__read_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID
node != 0; node != 0;
node = node->next){ node = node->next){
if (node->buffer_id != buffer_id) continue; if (node->buffer_id != buffer_id) continue;
Marker *markers = (Marker*)(node + 1); Marker *markers = (Marker*)(node + 1);
Assert(sizeof(*markers) == node->std_header.item_size); Assert(sizeof(*markers) == node->std_header.item_size);
i32 count = node->std_header.count; i32 count = node->std_header.count;
@ -69,6 +80,18 @@ edit_fix_markers__read_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID
} }
} }
internal f32
edit_fix_markers__compute_scroll_y(i32 line_height, f32 old_y_val, f32 new_y_val_aligned){
f32 y_offset = MOD(old_y_val, line_height);
f32 y_position = new_y_val_aligned + y_offset;
return(y_position);
}
internal i32
edit_fix_markers__compute_scroll_y(i32 line_height, i32 old_y_val, f32 new_y_val_aligned){
return((i32)edit_fix_markers__compute_scroll_y(line_height, (f32)old_y_val, new_y_val_aligned));
}
internal void internal void
edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Edit_Array edits){ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Edit_Array edits){
Partition *part = &models->mem.part; Partition *part = &models->mem.part;
@ -82,7 +105,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
Buffer_ID file_id = file->id.id; Buffer_ID file_id = file->id.id;
Assert(file_lifetime_object != 0); Assert(file_lifetime_object != 0);
i32 cursor_max = layout_get_open_panel_count(layout)*3; i32 cursor_max = layout_get_open_panel_count(layout)*4;
i32 total_marker_count = 0; i32 total_marker_count = 0;
{ {
total_marker_count += file_lifetime_object->workspace.total_marker_count; total_marker_count += file_lifetime_object->workspace.total_marker_count;
@ -115,9 +138,10 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
View *view = panel->view; View *view = panel->view;
if (view->transient.file_data.file == file){ if (view->transient.file_data.file == file){
File_Edit_Positions edit_pos = view_get_edit_pos(view); File_Edit_Positions edit_pos = view_get_edit_pos(view);
write_cursor_with_index(cursors, &cursor_count, edit_pos.cursor_pos ); write_cursor_with_index(cursors, &cursor_count, edit_pos.cursor_pos);
write_cursor_with_index(cursors, &cursor_count, view->transient.mark); write_cursor_with_index(cursors, &cursor_count, view->transient.mark);
write_cursor_with_index(cursors, &cursor_count, edit_pos.scroll_i ); write_cursor_with_index(cursors, &cursor_count, view->transient.temp_view_top_left_pos);
write_cursor_with_index(cursors, &cursor_count, view->transient.temp_view_top_left_target_pos);
} }
} }
@ -149,7 +173,6 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
buffer_update_cursors( cursors, cursor_count, edit.range.first, edit.range.one_past_last, edit.length, false); buffer_update_cursors( cursors, cursor_count, edit.range.first, edit.range.one_past_last, edit.length, false);
buffer_update_cursors(r_cursors, r_cursor_count, edit.range.first, edit.range.one_past_last, edit.length, true); buffer_update_cursors(r_cursors, r_cursor_count, edit.range.first, edit.range.one_past_last, edit.length, true);
} }
buffer_unsort_cursors(cursors, cursor_count); buffer_unsort_cursors(cursors, cursor_count);
cursor_count = 0; cursor_count = 0;
@ -166,22 +189,31 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
GUI_Scroll_Vars scroll = edit_pos.scroll; GUI_Scroll_Vars scroll = edit_pos.scroll;
view->transient.mark = cursors[cursor_count++].pos; view->transient.mark = cursors[cursor_count++].pos;
i32 new_scroll_i = cursors[cursor_count++].pos; i32 line_height = view->transient.line_height;
if (edit_pos.scroll_i != new_scroll_i){ i32 top_left_pos = cursors[cursor_count++].pos;
edit_pos.scroll_i = new_scroll_i; i32 top_left_target_pos = cursors[cursor_count++].pos;
view_set_edit_pos(view, edit_pos); f32 new_y_val_aligned = 0;
if (view->transient.temp_view_top_left_pos != top_left_pos){
Full_Cursor temp_cursor = file_compute_cursor(system, file, seek_pos(edit_pos.scroll_i)); Full_Cursor new_position_cursor = file_compute_cursor(system, file, seek_pos(top_left_pos));
f32 y_offset = MOD(edit_pos.scroll.scroll_y, view->transient.line_height);
f32 y_position = temp_cursor.wrapped_y;
if (file->settings.unwrapped_lines){ if (file->settings.unwrapped_lines){
y_position = temp_cursor.unwrapped_y; new_y_val_aligned = new_position_cursor.unwrapped_y;
} }
y_position += y_offset; else{
new_y_val_aligned = new_position_cursor.wrapped_y;
scroll.target_y += round32(y_position - scroll.scroll_y); }
scroll.scroll_y = y_position; scroll.scroll_y = edit_fix_markers__compute_scroll_y(line_height, scroll.scroll_y, new_y_val_aligned);
}
if (view->transient.temp_view_top_left_target_pos != top_left_target_pos){
if (top_left_target_pos != top_left_pos){
Full_Cursor new_position_cursor = file_compute_cursor(system, file, seek_pos(top_left_target_pos));
if (file->settings.unwrapped_lines){
new_y_val_aligned = new_position_cursor.unwrapped_y;
}
else{
new_y_val_aligned = new_position_cursor.wrapped_y;
}
}
scroll.target_y = edit_fix_markers__compute_scroll_y(line_height, scroll.target_y, new_y_val_aligned);
} }
view_set_cursor_and_scroll(view, new_cursor, true, view->transient.file_data.file->settings.unwrapped_lines, scroll); view_set_cursor_and_scroll(view, new_cursor, true, view->transient.file_data.file->settings.unwrapped_lines, scroll);

View File

@ -12,18 +12,18 @@
#if !defined(FRED_FILE_H) #if !defined(FRED_FILE_H)
#define FRED_FILE_H #define FRED_FILE_H
enum Edit_Pos_Set_Type{ typedef i32 Edit_Pos_Set_Type;
enum{
EditPos_None, EditPos_None,
EditPos_CursorSet, EditPos_CursorSet,
EditPos_ScrollSet EditPos_ScrollSet
}; };
struct File_Edit_Positions{ struct File_Edit_Positions{
Edit_Pos_Set_Type last_set_type;
GUI_Scroll_Vars scroll; GUI_Scroll_Vars scroll;
i32 cursor_pos; i32 cursor_pos;
f32 preferred_x; f32 preferred_x;
i32 scroll_i; //i32 scroll_i;
i32 last_set_type;
b32 in_view;
}; };
// TODO(NAME): do(replace Text_Effect with markers over time) // TODO(NAME): do(replace Text_Effect with markers over time)

View File

@ -1190,9 +1190,43 @@ do_core_render(Application_Links *app){
items, item_count); items, item_count);
} }
internal Full_Cursor
view_get_render_cursor(System_Functions *system, View *view, f32 scroll_y){
Full_Cursor result = {};
Editing_File *file = view->transient.file_data.file;
if (file->settings.unwrapped_lines){
result = file_compute_cursor_hint(system, file, seek_unwrapped_xy(0, scroll_y, false));
}
else{
result = file_compute_cursor(system, file, seek_wrapped_xy(0, scroll_y, false));
}
return(result);
}
internal Full_Cursor
view_get_render_cursor(System_Functions *system, View *view){
File_Edit_Positions edit_pos = view_get_edit_pos(view);
f32 scroll_y = edit_pos.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
// to the gui system.
scroll_y += view->transient.widget_height;
return(view_get_render_cursor(system, view, scroll_y));
}
internal Full_Cursor
view_get_render_cursor_target(System_Functions *system, View *view){
File_Edit_Positions edit_pos = view_get_edit_pos(view);
f32 scroll_y = (f32)edit_pos.scroll.target_y;
// NOTE(allen): For now we will temporarily adjust scroll_y to try
// to prevent the view moving around until floating sections are added
// to the gui system.
scroll_y += view->transient.widget_height;
return(view_get_render_cursor(system, view, scroll_y));
}
internal void internal void
render_loaded_file_in_view(System_Functions *system, View *view, Models *models, render_loaded_file_in_view(System_Functions *system, View *view, Models *models, i32_Rect rect, b32 is_active, Render_Target *target){
i32_Rect rect, b32 is_active, Render_Target *target){
Editing_File *file = view->transient.file_data.file; Editing_File *file = view->transient.file_data.file;
i32 line_height = view->transient.line_height; i32 line_height = view->transient.line_height;
@ -1226,16 +1260,12 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
// to the gui system. // to the gui system.
scroll_y += view->transient.widget_height; scroll_y += view->transient.widget_height;
Full_Cursor render_cursor = {}; Full_Cursor render_cursor = view_get_render_cursor(system, view);
if (!file->settings.unwrapped_lines){
render_cursor = file_compute_cursor_hint(system, file, seek_wrapped_xy(0, scroll_y, 0));
}
else{
render_cursor = file_compute_cursor_hint(system, file, seek_unwrapped_xy(0, scroll_y, 0));
}
#if 0
// TODO(allen): do(eliminate scroll_i nonsense) // TODO(allen): do(eliminate scroll_i nonsense)
view->transient.edit_pos_.scroll_i = render_cursor.pos; view->transient.edit_pos_.scroll_i = render_cursor.pos;
#endif
i32 item_count = 0; i32 item_count = 0;
i32 end_pos = 0; i32 end_pos = 0;

View File

@ -39,6 +39,9 @@ struct View_Transient{
File_Edit_Positions edit_pos_; File_Edit_Positions edit_pos_;
i32 mark; i32 mark;
i32 temp_view_top_left_pos;
i32 temp_view_top_left_target_pos;
b32 ui_mode; b32 ui_mode;
UI_Quit_Function_Type *ui_quit; UI_Quit_Function_Type *ui_quit;
UI_Control ui_control; UI_Control ui_control;
@ -56,7 +59,6 @@ struct View_Transient{
// It's what I've always wanted!!!! :D // It's what I've always wanted!!!! :D
i32 line_height; i32 line_height;
// TODO(allen): Do I still use mode?
Query_Set query_set; Query_Set query_set;
f32 widget_height; f32 widget_height;