made the view's scroll vars the official authoritative copy

master
Allen Webster 2016-05-23 10:41:39 -04:00
parent 199c2a2fc0
commit 13fa946ca0
4 changed files with 366 additions and 312 deletions

View File

@ -80,10 +80,10 @@ CUSTOM_COMMAND_SIG(if0_off){
View_Summary view; View_Summary view;
Buffer_Summary buffer; Buffer_Summary buffer;
char text1[] = "#if 0"; char text1[] = "\n#if 0";
int size1 = sizeof(text1) - 1; int size1 = sizeof(text1) - 1;
char text2[] = "#endif"; char text2[] = "#endif\n";
int size2 = sizeof(text2) - 1; int size2 = sizeof(text2) - 1;
Range range; Range range;

257
4ed.cpp
View File

@ -201,8 +201,8 @@ COMMAND_DECL(write_character){
character = command->key.character; character = command->key.character;
if (character != 0){ if (character != 0){
pos = view->file_data.cursor.pos; pos = view->recent->cursor.pos;
next_cursor_pos = view->file_data.cursor.pos + 1; next_cursor_pos = view->recent->cursor.pos + 1;
view_replace_range(system, models, view, pos, pos, &character, 1, next_cursor_pos); view_replace_range(system, models, view, pos, pos, &character, 1, next_cursor_pos);
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
} }
@ -258,27 +258,27 @@ COMMAND_DECL(seek_left){
i32 pos[4] = {0}; i32 pos[4] = {0};
if (flags & (1)){ if (flags & (1)){
pos[0] = buffer_seek_whitespace_left(&file->state.buffer, view->file_data.cursor.pos); pos[0] = buffer_seek_whitespace_left(&file->state.buffer, view->recent->cursor.pos);
} }
if (flags & (1 << 1)){ if (flags & (1 << 1)){
if (file->state.tokens_complete){ if (file->state.tokens_complete){
pos[1] = seek_token_left(&file->state.token_stack, view->file_data.cursor.pos); pos[1] = seek_token_left(&file->state.token_stack, view->recent->cursor.pos);
} }
else{ else{
pos[1] = buffer_seek_whitespace_left(&file->state.buffer, view->file_data.cursor.pos); pos[1] = buffer_seek_whitespace_left(&file->state.buffer, view->recent->cursor.pos);
} }
} }
if (flags & (1 << 2)){ if (flags & (1 << 2)){
pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, view->file_data.cursor.pos); pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, view->recent->cursor.pos);
if (flags & (1 << 3)){ if (flags & (1 << 3)){
pos[3] = buffer_seek_range_camel_left(&file->state.buffer, view->file_data.cursor.pos, pos[2]); pos[3] = buffer_seek_range_camel_left(&file->state.buffer, view->recent->cursor.pos, pos[2]);
} }
} }
else{ else{
if (flags & (1 << 3)){ if (flags & (1 << 3)){
pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, view->file_data.cursor.pos); pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, view->recent->cursor.pos);
} }
} }
@ -313,27 +313,27 @@ COMMAND_DECL(seek_right){
for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size; for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size;
if (flags & (1)){ if (flags & (1)){
pos[0] = buffer_seek_whitespace_right(&file->state.buffer, view->file_data.cursor.pos); pos[0] = buffer_seek_whitespace_right(&file->state.buffer, view->recent->cursor.pos);
} }
if (flags & (1 << 1)){ if (flags & (1 << 1)){
if (file->state.tokens_complete){ if (file->state.tokens_complete){
pos[1] = seek_token_right(&file->state.token_stack, view->file_data.cursor.pos); pos[1] = seek_token_right(&file->state.token_stack, view->recent->cursor.pos);
} }
else{ else{
pos[1] = buffer_seek_whitespace_right(&file->state.buffer, view->file_data.cursor.pos); pos[1] = buffer_seek_whitespace_right(&file->state.buffer, view->recent->cursor.pos);
} }
} }
if (flags & (1 << 2)){ if (flags & (1 << 2)){
pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, view->file_data.cursor.pos); pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, view->recent->cursor.pos);
if (flags & (1 << 3)){ if (flags & (1 << 3)){
pos[3] = buffer_seek_range_camel_right(&file->state.buffer, view->file_data.cursor.pos, pos[2]); pos[3] = buffer_seek_range_camel_right(&file->state.buffer, view->recent->cursor.pos, pos[2]);
} }
} }
else{ else{
if (flags & (1 << 3)){ if (flags & (1 << 3)){
pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, view->file_data.cursor.pos); pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, view->recent->cursor.pos);
} }
} }
@ -350,7 +350,7 @@ COMMAND_DECL(seek_whitespace_up){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_up(&file->state.buffer, view->file_data.cursor.pos); i32 pos = buffer_seek_whitespace_up(&file->state.buffer, view->recent->cursor.pos);
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -359,7 +359,7 @@ COMMAND_DECL(seek_whitespace_down){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
i32 pos = buffer_seek_whitespace_down(&file->state.buffer, view->file_data.cursor.pos); i32 pos = buffer_seek_whitespace_down(&file->state.buffer, view->recent->cursor.pos);
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -370,10 +370,10 @@ COMMAND_DECL(center_view){
f32 y, h; f32 y, h;
if (view->file_data.unwrapped_lines){ if (view->file_data.unwrapped_lines){
y = view->file_data.cursor.unwrapped_y; y = view->recent->cursor.unwrapped_y;
} }
else{ else{
y = view->file_data.cursor.wrapped_y; y = view->recent->cursor.wrapped_y;
} }
h = view_file_height(view); h = view_file_height(view);
@ -427,7 +427,7 @@ COMMAND_DECL(word_complete){
} }
if (do_init){ if (do_init){
word_end = view->file_data.cursor.pos; word_end = view->recent->cursor.pos;
word_start = word_end; word_start = word_end;
cursor_pos = word_end - 1; cursor_pos = word_end - 1;
@ -547,7 +547,7 @@ COMMAND_DECL(set_mark){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
view->file_data.mark = (i32)view->file_data.cursor.pos; view->recent->mark = (i32)view->recent->cursor.pos;
} }
COMMAND_DECL(copy){ COMMAND_DECL(copy){
@ -576,7 +576,7 @@ COMMAND_DECL(copy){
} }
} }
Range range = make_range(view->file_data.cursor.pos, view->file_data.mark); Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (start_set) range.start = r_start; if (start_set) range.start = r_start;
if (end_set) range.end = r_end; if (end_set) range.end = r_end;
if (range.start < range.end){ if (range.start < range.end){
@ -610,7 +610,7 @@ COMMAND_DECL(cut){
} }
} }
Range range = make_range(view->file_data.cursor.pos, view->file_data.mark); Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (start_set) range.start = r_start; if (start_set) range.start = r_start;
if (end_set) range.end = r_end; if (end_set) range.end = r_end;
if (range.start < range.end){ if (range.start < range.end){
@ -619,7 +619,7 @@ COMMAND_DECL(cut){
clipboard_copy(system, &models->mem.general, &models->working_set, range, file); clipboard_copy(system, &models->mem.general, &models->working_set, range, file);
view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos); view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos);
view->file_data.mark = range.start; view->recent->mark = range.start;
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
} }
} }
@ -638,13 +638,13 @@ COMMAND_DECL(paste){
view->next_mode.rewrite = 1; view->next_mode.rewrite = 1;
src = working_set_clipboard_head(&models->working_set); src = working_set_clipboard_head(&models->working_set);
pos_left = view->file_data.cursor.pos; pos_left = view->recent->cursor.pos;
next_cursor_pos = pos_left+src->size; next_cursor_pos = pos_left+src->size;
view_replace_range(system, models, view, pos_left, pos_left, src->str, src->size, next_cursor_pos); view_replace_range(system, models, view, pos_left, pos_left, src->str, src->size, next_cursor_pos);
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
view->file_data.mark = pos_left; view->recent->mark = pos_left;
Style *style = main_style(models); Style *style = main_style(models);
u32 paste_color = style->main.paste_color; u32 paste_color = style->main.paste_color;
@ -669,7 +669,7 @@ COMMAND_DECL(paste_next){
if (models->working_set.clipboard_size > 0 && view->mode.rewrite == 1){ if (models->working_set.clipboard_size > 0 && view->mode.rewrite == 1){
view->next_mode.rewrite = 1; view->next_mode.rewrite = 1;
range = make_range(view->file_data.mark, view->file_data.cursor.pos); range = make_range(view->recent->mark, view->recent->cursor.pos);
src = working_set_clipboard_roll_down(&models->working_set); src = working_set_clipboard_roll_down(&models->working_set);
next_cursor_pos = range.start+src->size; next_cursor_pos = range.start+src->size;
view_replace_range(system, view_replace_range(system,
@ -677,7 +677,7 @@ COMMAND_DECL(paste_next){
src->str, src->size, next_cursor_pos); src->str, src->size, next_cursor_pos);
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
view->file_data.mark = range.start; view->recent->mark = range.start;
Style *style = main_style(models); Style *style = main_style(models);
u32 paste_color = style->main.paste_color; u32 paste_color = style->main.paste_color;
@ -700,13 +700,13 @@ COMMAND_DECL(delete_range){
Range range; Range range;
i32 next_cursor_pos; i32 next_cursor_pos;
range = make_range(view->file_data.cursor.pos, view->file_data.mark); range = make_range(view->recent->cursor.pos, view->recent->mark);
if (range.start < range.end){ if (range.start < range.end){
next_cursor_pos = range.start; next_cursor_pos = range.start;
Assert(range.end <= buffer_size(&file->state.buffer)); Assert(range.end <= buffer_size(&file->state.buffer));
view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos); view_replace_range(system, models, view, range.start, range.end, 0, 0, next_cursor_pos);
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
view->file_data.mark = range.start; view->recent->mark = range.start;
} }
} }
@ -1020,16 +1020,16 @@ COMMAND_DECL(toggle_line_wrap){
view->file_data.unwrapped_lines = 0; view->file_data.unwrapped_lines = 0;
file->settings.unwrapped_lines = 0; file->settings.unwrapped_lines = 0;
view->recent->scroll.target_x = 0; view->recent->scroll.target_x = 0;
view->file_data.cursor =view_compute_cursor_from_pos( view->recent->cursor =view_compute_cursor_from_pos(
view, view->file_data.cursor.pos); view, view->recent->cursor.pos);
view->file_data.preferred_x = view->file_data.cursor.wrapped_x; view->recent->preferred_x = view->recent->cursor.wrapped_x;
} }
else{ else{
view->file_data.unwrapped_lines = 1; view->file_data.unwrapped_lines = 1;
file->settings.unwrapped_lines = 1; file->settings.unwrapped_lines = 1;
view->file_data.cursor = view->recent->cursor =
view_compute_cursor_from_pos(view, view->file_data.cursor.pos); view_compute_cursor_from_pos(view, view->recent->cursor.pos);
view->file_data.preferred_x = view->file_data.cursor.unwrapped_x; view->recent->preferred_x = view->recent->cursor.unwrapped_x;
} }
view_set_relative_scrolling(view, scrolling); view_set_relative_scrolling(view, scrolling);
} }
@ -1059,7 +1059,7 @@ case_change_range(System_Functions *system,
Mem_Options *mem, View *view, Editing_File *file, Mem_Options *mem, View *view, Editing_File *file,
u8 a, u8 z, u8 char_delta){ u8 a, u8 z, u8 char_delta){
#if BUFFER_EXPERIMENT_SCALPEL <= 0 #if BUFFER_EXPERIMENT_SCALPEL <= 0
Range range = make_range(view->file_data.cursor.pos, view->file_data.mark); Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (range.start < range.end){ if (range.start < range.end){
Edit_Step step = {}; Edit_Step step = {};
step.type = ED_NORMAL; step.type = ED_NORMAL;
@ -1167,7 +1167,7 @@ COMMAND_DECL(auto_tab_range){
} }
if (file->state.token_stack.tokens && file->state.tokens_complete && !file->state.still_lexing){ if (file->state.token_stack.tokens && file->state.tokens_complete && !file->state.still_lexing){
Range range = make_range(view->file_data.cursor.pos, view->file_data.mark); Range range = make_range(view->recent->cursor.pos, view->recent->mark);
if (start_set) range.start = r_start; if (start_set) range.start = r_start;
if (end_set) range.end = r_end; if (end_set) range.end = r_end;
view_auto_tab_tokens(system, models, view, range.start, range.end, opts); view_auto_tab_tokens(system, models, view, range.start, range.end, opts);
@ -1316,7 +1316,7 @@ COMMAND_DECL(move_left){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
i32 pos = view->file_data.cursor.pos; i32 pos = view->recent->cursor.pos;
if (pos > 0) --pos; if (pos > 0) --pos;
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -1326,7 +1326,7 @@ COMMAND_DECL(move_right){
REQ_FILE(file, view); REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer); i32 size = buffer_size(&file->state.buffer);
i32 pos = view->file_data.cursor.pos; i32 pos = view->recent->cursor.pos;
if (pos < size) ++pos; if (pos < size) ++pos;
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -1337,7 +1337,7 @@ COMMAND_DECL(delete){
REQ_FILE(file, view); REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer); i32 size = buffer_size(&file->state.buffer);
i32 cursor_pos = view->file_data.cursor.pos; i32 cursor_pos = view->recent->cursor.pos;
if (0 < size && cursor_pos < size){ if (0 < size && cursor_pos < size){
i32 start, end; i32 start, end;
start = cursor_pos; start = cursor_pos;
@ -1357,7 +1357,7 @@ COMMAND_DECL(backspace){
REQ_FILE(file, view); REQ_FILE(file, view);
i32 size = buffer_size(&file->state.buffer); i32 size = buffer_size(&file->state.buffer);
i32 cursor_pos = view->file_data.cursor.pos; i32 cursor_pos = view->recent->cursor.pos;
if (cursor_pos > 0 && cursor_pos <= size){ if (cursor_pos > 0 && cursor_pos <= size){
i32 start, end; i32 start, end;
end = cursor_pos; end = cursor_pos;
@ -1366,7 +1366,7 @@ COMMAND_DECL(backspace){
i32 shift = (end - start); i32 shift = (end - start);
Assert(shift > 0); Assert(shift > 0);
i32 next_cursor_pos = view->file_data.cursor.pos - shift; i32 next_cursor_pos = view->recent->cursor.pos - shift;
view_replace_range(system, models, view, start, end, 0, 0, next_cursor_pos); view_replace_range(system, models, view, start, end, 0, 0, next_cursor_pos);
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
} }
@ -1379,10 +1379,10 @@ COMMAND_DECL(move_up){
f32 font_height = (f32)get_font_info(models->font_set, models->global_font.font_id)->height; f32 font_height = (f32)get_font_info(models->font_set, models->global_font.font_id)->height;
f32 cy = view_get_cursor_y(view)-font_height; f32 cy = view_get_cursor_y(view)-font_height;
f32 px = view->file_data.preferred_x; f32 px = view->recent->preferred_x;
if (cy >= 0){ if (cy >= 0){
view->file_data.cursor = view_compute_cursor_from_xy(view, px, cy); view->recent->cursor = view_compute_cursor_from_xy(view, px, cy);
file->state.cursor_pos = view->file_data.cursor.pos; file->state.cursor_pos = view->recent->cursor.pos;
} }
} }
@ -1394,16 +1394,16 @@ COMMAND_DECL(move_down){
f32 font_height = (f32)get_font_info(models->font_set, models->global_font.font_id)->height; f32 font_height = (f32)get_font_info(models->font_set, models->global_font.font_id)->height;
f32 cy = view_get_cursor_y(view)+font_height; f32 cy = view_get_cursor_y(view)+font_height;
f32 px = view->file_data.preferred_x; f32 px = view->recent->preferred_x;
view->file_data.cursor = view_compute_cursor_from_xy(view, px, cy); view->recent->cursor = view_compute_cursor_from_xy(view, px, cy);
file->state.cursor_pos = view->file_data.cursor.pos; file->state.cursor_pos = view->recent->cursor.pos;
} }
COMMAND_DECL(seek_end_of_line){ COMMAND_DECL(seek_end_of_line){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
i32 pos = view_find_end_of_line(view, view->file_data.cursor.pos); i32 pos = view_find_end_of_line(view, view->recent->cursor.pos);
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -1411,7 +1411,7 @@ COMMAND_DECL(seek_beginning_of_line){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
REQ_FILE(file, view); REQ_FILE(file, view);
i32 pos = view_find_beginning_of_line(view, view->file_data.cursor.pos); i32 pos = view_find_beginning_of_line(view, view->recent->cursor.pos);
view_cursor_move(view, pos); view_cursor_move(view, pos);
} }
@ -1424,7 +1424,7 @@ COMMAND_DECL(page_down){
view->recent->scroll.target_y += height; view->recent->scroll.target_y += height;
if (view->recent->scroll.target_y > max_target_y) view->recent->scroll.target_y = max_target_y; if (view->recent->scroll.target_y > max_target_y) view->recent->scroll.target_y = max_target_y;
view->file_data.cursor = view_compute_cursor_from_xy( view->recent->cursor = view_compute_cursor_from_xy(
view, 0, view->recent->scroll.target_y + (height - view->font_height)*.5f); view, 0, view->recent->scroll.target_y + (height - view->font_height)*.5f);
} }
@ -1437,7 +1437,7 @@ COMMAND_DECL(page_up){
view->recent->scroll.target_y -= height; view->recent->scroll.target_y -= height;
if (view->recent->scroll.target_y < min_target_y) view->recent->scroll.target_y = min_target_y; if (view->recent->scroll.target_y < min_target_y) view->recent->scroll.target_y = min_target_y;
view->file_data.cursor = view_compute_cursor_from_xy( view->recent->cursor = view_compute_cursor_from_xy(
view, 0, view->recent->scroll.target_y + (height - view->font_height)*.5f); view, 0, view->recent->scroll.target_y + (height - view->font_height)*.5f);
} }
@ -1470,9 +1470,9 @@ COMMAND_DECL(close_minor_view){
COMMAND_DECL(cursor_mark_swap){ COMMAND_DECL(cursor_mark_swap){
REQ_READABLE_VIEW(view); REQ_READABLE_VIEW(view);
i32 pos = view->file_data.cursor.pos; i32 pos = view->recent->cursor.pos;
view_cursor_move(view, view->file_data.mark); view_cursor_move(view, view->recent->mark);
view->file_data.mark = pos; view->recent->mark = pos;
} }
COMMAND_DECL(user_callback){ COMMAND_DECL(user_callback){
@ -1729,7 +1729,7 @@ COMMAND_DECL(command_line){
if (!script){ if (!script){
file2 = view->file_data.file; file2 = view->file_data.file;
if (file2){ if (file2){
range = make_range(view->file_data.cursor.pos, view->file_data.mark); range = make_range(view->recent->cursor.pos, view->recent->mark);
size = range.end - range.start; size = range.end - range.start;
script = push_array(part, char, size + 1); script = push_array(part, char, size + 1);
buffer_stringify(&file2->state.buffer, range.start, range.end, script); buffer_stringify(&file2->state.buffer, range.start, range.end, script);
@ -1827,9 +1827,9 @@ fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_
view->hidden_buffer_id = 0; view->hidden_buffer_id = 0;
} }
view->mark = view_compute_cursor_from_pos(vptr, vptr->file_data.mark); view->mark = view_compute_cursor_from_pos(vptr, vptr->recent->mark);
view->cursor = vptr->file_data.cursor; view->cursor = vptr->recent->cursor;
view->preferred_x = vptr->file_data.preferred_x; view->preferred_x = vptr->recent->preferred_x;
} }
} }
} }
@ -2294,12 +2294,12 @@ extern "C"{
if (seek.type == buffer_seek_line_char && seek.character <= 0){ if (seek.type == buffer_seek_line_char && seek.character <= 0){
seek.character = 1; seek.character = 1;
} }
vptr->file_data.cursor = view_compute_cursor(vptr, seek); vptr->recent->cursor = view_compute_cursor(vptr, seek);
if (set_preferred_x){ if (set_preferred_x){
vptr->file_data.preferred_x = view_get_cursor_x(vptr); vptr->recent->preferred_x = view_get_cursor_x(vptr);
} }
fill_view_summary(view, vptr, live_set, &cmd->models->working_set); fill_view_summary(view, vptr, live_set, &cmd->models->working_set);
file->state.cursor_pos = vptr->file_data.cursor.pos; file->state.cursor_pos = vptr->recent->cursor.pos;
} }
} }
} }
@ -2323,10 +2323,10 @@ extern "C"{
result = 1; result = 1;
if (seek.type != buffer_seek_pos){ if (seek.type != buffer_seek_pos){
cursor = view_compute_cursor(vptr, seek); cursor = view_compute_cursor(vptr, seek);
vptr->file_data.mark = cursor.pos; vptr->recent->mark = cursor.pos;
} }
else{ else{
vptr->file_data.mark = seek.pos; vptr->recent->mark = seek.pos;
} }
fill_view_summary(view, vptr, live_set, &cmd->models->working_set); fill_view_summary(view, vptr, live_set, &cmd->models->working_set);
} }
@ -3575,30 +3575,6 @@ App_Step_Sig(app_step){
} }
} }
// NOTE(allen): update child processes
if (dt > 0){
Temp_Memory temp = begin_temp_memory(&models->mem.part);
u32 max = Kbytes(32);
char *dest = push_array(&models->mem.part, char, max);
i32 count = vars->cli_processes.count;
for (i32 i = 0; i < count; ++i){
CLI_Process *proc = vars->cli_processes.procs + i;
Editing_File *file = proc->out_file;
if (file != 0){
i32 r = update_cli_handle_with_file(system, models, &proc->cli, file, dest, max, 0);
if (r < 0){
*proc = vars->cli_processes.procs[--count];
--i;
}
}
}
vars->cli_processes.count = count;
end_temp_memory(temp);
}
// NOTE(allen): reorganizing panels on screen // NOTE(allen): reorganizing panels on screen
{ {
i32 prev_width = models->layout.full_width; i32 prev_width = models->layout.full_width;
@ -3714,6 +3690,41 @@ App_Step_Sig(app_step){
} }
} }
// NOTE(allen): begin allowing the cursors and scroll locations
// to move around.
{
Panel *panel = 0, *used_panels = 0;
used_panels = &models->layout.used_sentinel;
for (dll_items(panel, used_panels)){
Assert(panel->view);
view_begin_cursor_scroll_updates(panel->view);
}
}
// NOTE(allen): update child processes
if (dt > 0){
Temp_Memory temp = begin_temp_memory(&models->mem.part);
u32 max = Kbytes(32);
char *dest = push_array(&models->mem.part, char, max);
i32 count = vars->cli_processes.count;
for (i32 i = 0; i < count; ++i){
CLI_Process *proc = vars->cli_processes.procs + i;
Editing_File *file = proc->out_file;
if (file != 0){
i32 r = update_cli_handle_with_file(system, models, &proc->cli, file, dest, max, 0);
if (r < 0){
*proc = vars->cli_processes.procs[--count];
--i;
}
}
}
vars->cli_processes.count = count;
end_temp_memory(temp);
}
// NOTE(allen): prepare to start executing commands // NOTE(allen): prepare to start executing commands
Command_Data *cmd = &vars->command_data; Command_Data *cmd = &vars->command_data;
@ -3968,11 +3979,12 @@ App_Step_Sig(app_step){
Mouse_State mouse_state = get_mouse_state(&available_input); Mouse_State mouse_state = get_mouse_state(&available_input);
{ {
Panel *panel, *used_panels; Panel *panel = 0, *used_panels = 0;
View *view, *active_view; View *view = 0, *active_view = 0;
b32 active; b32 active = 0;
Input_Summary input; Input_Summary input = {0};
Input_Process_Result result = {0};
active_view = cmd->panel->view; active_view = cmd->panel->view;
used_panels = &models->layout.used_sentinel; used_panels = &models->layout.used_sentinel;
for (dll_items(panel, used_panels)){ for (dll_items(panel, used_panels)){
@ -3986,16 +3998,24 @@ App_Step_Sig(app_step){
for (dll_items(panel, used_panels)){ for (dll_items(panel, used_panels)){
view = panel->view; view = panel->view;
Assert(view->current_scroll);
active = (panel == cmd->panel); active = (panel == cmd->panel);
input = (active)?(active_input):(dead_input); input = (active)?(active_input):(dead_input);
if (panel == mouse_panel && !mouse->out_of_window){ if (panel == mouse_panel && !mouse->out_of_window){
input.mouse = mouse_state; input.mouse = mouse_state;
} }
if (do_input_file_view(system, exchange, view, panel->inner, active, &input)){
result = do_input_file_view(system, exchange, view, panel->inner, active,
&input, *view->current_scroll, view->scroll_region);
if (result.is_animating){
app_result.animating = 1; app_result.animating = 1;
} }
*view->current_scroll = result.vars;
view->scroll_region = result.region;
} }
#if 0
// TODO(allen): This is perhaps not the best system... // TODO(allen): This is perhaps not the best system...
// The problem is that the exact region and scroll position is pretty important // The problem is that the exact region and scroll position is pretty important
// for some commands, so this is here to eliminate the one frame of lag. // for some commands, so this is here to eliminate the one frame of lag.
@ -4003,10 +4023,11 @@ App_Step_Sig(app_step){
// change a lot soon anyway.// NOTE(allen): // change a lot soon anyway.// NOTE(allen):
for (dll_items(panel, used_panels)){ for (dll_items(panel, used_panels)){
view = panel->view; view = panel->view;
if (view->current_scroll){ Assert(view->current_scroll);
gui_get_scroll_vars(&view->gui_target, view->showing_ui, view->current_scroll, &view->scroll_region); view->current_scroll = ;
} gui_get_scroll_vars(&view->gui_target, view->showing_ui, view->current_scroll, &view->scroll_region);
} }
#endif
} }
update_command_data(vars, cmd); update_command_data(vars, cmd);
@ -4550,35 +4571,6 @@ App_Step_Sig(app_step){
} }
} }
// NOTE(allen): post scroll vars back to the view's gui targets
{
View *view = 0;
Panel *panel = 0, *used_panels = 0;
i32 cursor_scroll_state = 0;
used_panels = &models->layout.used_sentinel;
for (dll_items(panel, used_panels)){
view = panel->view;
cursor_scroll_state = view_get_cursor_scroll_change_state(view);
switch (cursor_scroll_state){
case CursorScroll_NoChange:break;
case CursorScroll_Cursor:
case CursorScroll_Both:
view_move_view_to_cursor(view);
break;
case CursorScroll_Scroll:
gui_post_scroll_vars(&view->gui_target, view->current_scroll);
break;
}
view_record_prev_cursor(view);
}
}
// NOTE(allen): send style change messages if the style has changed // NOTE(allen): send style change messages if the style has changed
if (models->global_font.font_changed){ if (models->global_font.font_changed){
models->global_font.font_changed = 0; models->global_font.font_changed = 0;
@ -4602,6 +4594,17 @@ App_Step_Sig(app_step){
} }
} }
// NOTE(allen): post scroll vars back to the view's gui targets
{
Panel *panel = 0, *used_panels = 0;
used_panels = &models->layout.used_sentinel;
for (dll_items(panel, used_panels)){
Assert(panel->view);
view_end_cursor_scroll_updates(panel->view);
}
}
// NOTE(allen): rendering // NOTE(allen): rendering
{ {
begin_render_section(target, system); begin_render_section(target, system);

View File

@ -154,11 +154,6 @@ enum Color_View_Mode{
struct File_Viewing_Data{ struct File_Viewing_Data{
Editing_File *file; Editing_File *file;
Full_Cursor cursor;
i32 mark;
f32 preferred_x;
i32 scroll_i;
Full_Cursor temp_highlight; Full_Cursor temp_highlight;
i32 temp_highlight_end_pos; i32 temp_highlight_end_pos;
b32 show_temp_highlight; b32 show_temp_highlight;
@ -179,6 +174,11 @@ file_viewing_data_zero(){
struct Recent_File_Data{ struct Recent_File_Data{
u64 unique_buffer_id; u64 unique_buffer_id;
GUI_Scroll_Vars scroll; GUI_Scroll_Vars scroll;
Full_Cursor cursor;
i32 mark;
f32 preferred_x;
i32 scroll_i;
}; };
struct View{ struct View{
@ -1337,7 +1337,7 @@ view_get_cursor_pos(View *view){
result = view->file_data.temp_highlight.pos; result = view->file_data.temp_highlight.pos;
} }
else{ else{
result = view->file_data.cursor.pos; result = view->recent->cursor.pos;
} }
return result; return result;
} }
@ -1350,7 +1350,7 @@ view_get_cursor_x(View *view){
cursor = &view->file_data.temp_highlight; cursor = &view->file_data.temp_highlight;
} }
else{ else{
cursor = &view->file_data.cursor; cursor = &view->recent->cursor;
} }
if (view->file_data.unwrapped_lines){ if (view->file_data.unwrapped_lines){
result = cursor->unwrapped_x; result = cursor->unwrapped_x;
@ -1367,7 +1367,7 @@ view_get_cursor_y(View *view){
f32 result; f32 result;
if (view->file_data.show_temp_highlight) cursor = &view->file_data.temp_highlight; if (view->file_data.show_temp_highlight) cursor = &view->file_data.temp_highlight;
else cursor = &view->file_data.cursor; else cursor = &view->recent->cursor;
if (view->file_data.unwrapped_lines) result = cursor->unwrapped_y; if (view->file_data.unwrapped_lines) result = cursor->unwrapped_y;
else result = cursor->wrapped_y; else result = cursor->wrapped_y;
@ -1424,7 +1424,7 @@ view_set_file(View *view, Editing_File *file, Models *models){
if (file_is_ready(file)){ if (file_is_ready(file)){
view_measure_wraps(&models->mem.general, view); view_measure_wraps(&models->mem.general, view);
view->file_data.cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos); view->recent->cursor = view_compute_cursor_from_pos(view, file->state.cursor_pos);
if (!found_recent_entry){ if (!found_recent_entry){
view->reinit_scrolling = 1; view->reinit_scrolling = 1;
} }
@ -1462,9 +1462,9 @@ view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){
inline void inline void
view_cursor_move(View *view, Full_Cursor cursor){ view_cursor_move(View *view, Full_Cursor cursor){
view->file_data.cursor = cursor; view->recent->cursor = cursor;
view->file_data.preferred_x = view_get_cursor_x(view); view->recent->preferred_x = view_get_cursor_x(view);
view->file_data.file->state.cursor_pos = view->file_data.cursor.pos; view->file_data.file->state.cursor_pos = view->recent->cursor.pos;
view->file_data.show_temp_highlight = 0; view->file_data.show_temp_highlight = 0;
} }
@ -1720,9 +1720,9 @@ file_edit_cursor_fix(System_Functions *system,
view = panel->view; view = panel->view;
if (view->file_data.file == file){ if (view->file_data.file == file){
view_measure_wraps(general, view); view_measure_wraps(general, view);
write_cursor_with_index(cursors, &cursor_count, view->file_data.cursor.pos); write_cursor_with_index(cursors, &cursor_count, view->recent->cursor.pos);
write_cursor_with_index(cursors, &cursor_count, view->file_data.mark - 1); write_cursor_with_index(cursors, &cursor_count, view->recent->mark - 1);
write_cursor_with_index(cursors, &cursor_count, view->file_data.scroll_i - 1); write_cursor_with_index(cursors, &cursor_count, view->recent->scroll_i - 1);
} }
} }
@ -1744,15 +1744,15 @@ file_edit_cursor_fix(System_Functions *system,
view = panel->view; view = panel->view;
if (view && view->file_data.file == file){ if (view && view->file_data.file == file){
view_cursor_move(view, cursors[cursor_count++].pos); view_cursor_move(view, cursors[cursor_count++].pos);
view->file_data.preferred_x = view_get_cursor_x(view); view->recent->preferred_x = view_get_cursor_x(view);
view->file_data.mark = cursors[cursor_count++].pos + 1; view->recent->mark = cursors[cursor_count++].pos + 1;
i32 new_scroll_i = cursors[cursor_count++].pos + 1; i32 new_scroll_i = cursors[cursor_count++].pos + 1;
if (view->file_data.scroll_i != new_scroll_i){ if (view->recent->scroll_i != new_scroll_i){
view->file_data.scroll_i = new_scroll_i; view->recent->scroll_i = new_scroll_i;
temp_cursor = view_compute_cursor_from_pos(view, view->file_data.scroll_i); temp_cursor = view_compute_cursor_from_pos(view, view->recent->scroll_i);
y_offset = MOD(view->recent->scroll.scroll_y, view->font_height); y_offset = MOD(view->recent->scroll.scroll_y, view->font_height);
if (view->file_data.unwrapped_lines){ if (view->file_data.unwrapped_lines){
y_position = temp_cursor.unwrapped_y + y_offset; y_position = temp_cursor.unwrapped_y + y_offset;
view->recent->scroll.target_y += (y_position - view->recent->scroll.scroll_y); view->recent->scroll.target_y += (y_position - view->recent->scroll.scroll_y);
@ -2003,7 +2003,7 @@ view_undo_redo(System_Functions *system,
if (expected_type == ED_UNDO) view_cursor_move(view, step.pre_pos); if (expected_type == ED_UNDO) view_cursor_move(view, step.pre_pos);
else view_cursor_move(view, step.post_pos); else view_cursor_move(view, step.post_pos);
view->file_data.mark = view->file_data.cursor.pos; view->recent->mark = view->recent->cursor.pos;
Style *style = main_style(models); Style *style = main_style(models);
view_post_paste_effect(view, 10, step.edit.start, step.edit.len, view_post_paste_effect(view, 10, step.edit.start, step.edit.len,
@ -2135,7 +2135,7 @@ view_history_step(System_Functions *system, Models *models, View *view, History_
view_cursor_move(view, step.pre_pos); view_cursor_move(view, step.pre_pos);
break; break;
} }
view->file_data.mark = view->file_data.cursor.pos; view->recent->mark = view->recent->cursor.pos;
} }
else{ else{
TentativeAssert(spec.step.special_type == 1); TentativeAssert(spec.step.special_type == 1);
@ -2334,7 +2334,7 @@ view_clean_whitespace(System_Functions *system, Models *models, View *view){
char *inv_str = (char*)part->base + part->pos; char *inv_str = (char*)part->base + part->pos;
Edit_Spec spec = Edit_Spec spec =
file_compute_whitespace_edit(mem, file, view->file_data.cursor.pos, edits, str_base, str_size, file_compute_whitespace_edit(mem, file, view->recent->cursor.pos, edits, str_base, str_size,
inverse_array, inv_str, part->max - part->pos, edit_count); inverse_array, inv_str, part->max - part->pos, edit_count);
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal); file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
@ -2737,7 +2737,7 @@ view_auto_tab_tokens(System_Functions *system, Models *models,
char *inv_str = (char*)part->base + part->pos; char *inv_str = (char*)part->base + part->pos;
Edit_Spec spec = Edit_Spec spec =
file_compute_whitespace_edit(mem, file, view->file_data.cursor.pos, file_compute_whitespace_edit(mem, file, view->recent->cursor.pos,
batch.edits, batch.str_base, batch.str_size, batch.edits, batch.str_base, batch.str_size,
inverse_array, inv_str, part->max - part->pos, batch.edit_count); inverse_array, inv_str, part->max - part->pos, batch.edit_count);
@ -2746,7 +2746,7 @@ view_auto_tab_tokens(System_Functions *system, Models *models,
end_temp_memory(temp); end_temp_memory(temp);
{ {
i32 start = view->file_data.cursor.pos; i32 start = view->recent->cursor.pos;
Hard_Start_Result hard_start = buffer_find_hard_start(buffer, start, 4); Hard_Start_Result hard_start = buffer_find_hard_start(buffer, start, 4);
view_cursor_move(view, hard_start.char_pos); view_cursor_move(view, hard_start.char_pos);
@ -2828,8 +2828,8 @@ remeasure_file_view(System_Functions *system, View *view){
if (file_is_ready(view->file_data.file)){ if (file_is_ready(view->file_data.file)){
Relative_Scrolling relative = view_get_relative_scrolling(view); Relative_Scrolling relative = view_get_relative_scrolling(view);
view_measure_wraps(&view->models->mem.general, view); view_measure_wraps(&view->models->mem.general, view);
view_cursor_move(view, view->file_data.cursor.pos); view_cursor_move(view, view->recent->cursor.pos);
view->file_data.preferred_x = view_get_cursor_x(view); view->recent->preferred_x = view_get_cursor_x(view);
view_set_relative_scrolling(view, relative); view_set_relative_scrolling(view, relative);
} }
} }
@ -3077,40 +3077,36 @@ view_reinit_scrolling(View *view){
f32 w, h; f32 w, h;
f32 cursor_x, cursor_y; f32 cursor_x, cursor_y;
f32 target_x, target_y; f32 target_x, target_y;
view->reinit_scrolling = 0; view->reinit_scrolling = 0;
target_x = 0; target_x = 0;
target_y = 0; target_y = 0;
if (file && file_is_ready(file)){ if (file && file_is_ready(file)){
cursor_x = view_get_cursor_x(view); cursor_x = view_get_cursor_x(view);
cursor_y = view_get_cursor_y(view); cursor_y = view_get_cursor_y(view);
w = view_file_width(view); w = view_file_width(view);
h = view_file_height(view); h = view_file_height(view);
if (cursor_x >= target_x + w){ if (cursor_x >= target_x + w){
target_x = (f32)(cursor_x - w*.5f); target_x = (f32)(cursor_x - w*.5f);
} }
target_y = (f32)FLOOR32(cursor_y - h*.5f); target_y = (f32)FLOOR32(cursor_y - h*.5f);
if (target_y < view->recent->scroll.min_y){ if (target_y < view->recent->scroll.min_y){
target_y = view->recent->scroll.min_y; target_y = view->recent->scroll.min_y;
} }
} }
view->recent->scroll.target_y = target_y; view->recent->scroll.target_y = target_y;
view->recent->scroll.scroll_y = target_y; view->recent->scroll.scroll_y = target_y;
view->recent->scroll.prev_target_y = -1000.f; view->recent->scroll.prev_target_y = -1000.f;
view->recent->scroll.min_y = view->gui_target.scroll_updated.min_y;
view->recent->scroll.max_y = view->gui_target.scroll_updated.max_y;
view->recent->scroll.target_x = target_x; view->recent->scroll.target_x = target_x;
view->recent->scroll.scroll_x = target_x; view->recent->scroll.scroll_x = target_x;
view->recent->scroll.prev_target_x = -1000.f; view->recent->scroll.prev_target_x = -1000.f;
gui_post_scroll_vars(&view->gui_target, &view->recent->scroll);
} }
#define CursorMaxY_(m,h) ((m) - (h)*3) #define CursorMaxY_(m,h) ((m) - (h)*3)
@ -3143,8 +3139,8 @@ view_move_cursor_to_view(View *view){
else{ else{
cursor_y -= line_height; cursor_y -= line_height;
} }
view->file_data.cursor = view->recent->cursor =
view_compute_cursor_from_xy(view, view->file_data.preferred_x, cursor_y); view_compute_cursor_from_xy(view, view->recent->preferred_x, cursor_y);
} }
} }
@ -3152,14 +3148,14 @@ internal void
view_move_view_to_cursor(View *view){ view_move_view_to_cursor(View *view){
f32 line_height = (f32)view->font_height; f32 line_height = (f32)view->font_height;
f32 delta_y = 3.f*line_height; f32 delta_y = 3.f*line_height;
f32 max_visible_y = view_file_height(view); f32 max_visible_y = view_file_height(view);
f32 max_x = view_file_width(view); f32 max_x = view_file_width(view);
f32 cursor_y = view_get_cursor_y(view); f32 cursor_y = view_get_cursor_y(view);
f32 cursor_x = view_get_cursor_x(view); f32 cursor_x = view_get_cursor_x(view);
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated; GUI_Scroll_Vars scroll_vars = *view->current_scroll;
f32 target_y = scroll_vars.target_y; f32 target_y = scroll_vars.target_y;
f32 target_x = scroll_vars.target_x; f32 target_x = scroll_vars.target_x;
@ -3172,20 +3168,20 @@ view_move_view_to_cursor(View *view){
if (cursor_y < target_y + cursor_min_y){ if (cursor_y < target_y + cursor_min_y){
target_y = cursor_y - delta_y - cursor_min_y; target_y = cursor_y - delta_y - cursor_min_y;
} }
if (target_y > scroll_vars.max_y) target_y = scroll_vars.max_y; if (target_y > scroll_vars.max_y) target_y = scroll_vars.max_y;
if (target_y < scroll_vars.min_y) target_y = view->recent->scroll.min_y; if (target_y < scroll_vars.min_y) target_y = view->recent->scroll.min_y;
if (cursor_x < target_x){ if (cursor_x < target_x){
target_x = (f32)Max(0, cursor_x - max_x/2); target_x = (f32)Max(0, cursor_x - max_x/2);
} }
else if (cursor_x >= target_x + max_x){ else if (cursor_x >= target_x + max_x){
target_x = (f32)(cursor_x - max_x/2); target_x = (f32)(cursor_x - max_x/2);
} }
if (target_x != scroll_vars.target_x || target_y != scroll_vars.target_y){ if (target_x != scroll_vars.target_x || target_y != scroll_vars.target_y){
view->gui_target.scroll_updated.target_x = target_x; view->current_scroll->target_x = target_x;
view->gui_target.scroll_updated.target_y = target_y; view->current_scroll->target_y = target_y;
} }
} }
@ -3209,7 +3205,7 @@ view_get_cursor_scroll_change_state(View *view){
} }
if (view->current_scroll){ if (view->current_scroll){
if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_updated)){ if (!gui_scroll_eq(view->current_scroll, &view->gui_target.scroll_original)){
view_change = 1; view_change = 1;
} }
} }
@ -3235,7 +3231,30 @@ view_get_cursor_scroll_change_state(View *view){
} }
internal void internal void
view_record_prev_cursor(View *view){ view_begin_cursor_scroll_updates(View *view){
Assert(view->prev_cursor_pos == view_get_cursor_pos(view));
}
internal void
view_end_cursor_scroll_updates(View *view){
i32 cursor_scroll_state =
view_get_cursor_scroll_change_state(view);
switch (cursor_scroll_state){
case CursorScroll_NoChange:break;
case CursorScroll_Cursor:
case CursorScroll_Both:
view_move_view_to_cursor(view);
gui_post_scroll_vars(&view->gui_target, view->current_scroll, view->scroll_region);
break;
case CursorScroll_Scroll:
view_move_cursor_to_view(view);
gui_post_scroll_vars(&view->gui_target, view->current_scroll, view->scroll_region);
break;
}
if (view->gui_target.did_file){ if (view->gui_target.did_file){
view->prev_cursor_pos = view_get_cursor_pos(view); view->prev_cursor_pos = view_get_cursor_pos(view);
} }
@ -3249,14 +3268,8 @@ file_step(View *view, i32_Rect region, Input_Summary *user_input, b32 is_active)
f32 max_visible_y = view_file_height(view); f32 max_visible_y = view_file_height(view);
f32 max_x = view_file_width(view); f32 max_x = view_file_width(view);
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated; GUI_Scroll_Vars scroll_vars = *view->current_scroll;
#if 0
if (!gui_id_eq(view->gui_target.active, gui_id_scrollbar())){
view_move_view_to_cursor(view);
}
#endif
if (file->state.paste_effect.tick_down > 0){ if (file->state.paste_effect.tick_down > 0){
--file->state.paste_effect.tick_down; --file->state.paste_effect.tick_down;
is_animating = 1; is_animating = 1;
@ -3589,14 +3602,20 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_begin_serial_section(target); gui_begin_serial_section(target);
{ {
f32 delta = 9.f * view->font_height; f32 delta = 9.f * view->font_height;
GUI_id scroll_context = {0};
scroll_context.id[1] = view->showing_ui;
scroll_context.id[0] = (u64)(view->file_data.file);
view->current_scroll = &view->recent->scroll; view->current_scroll = &view->recent->scroll;
if (gui_get_scroll_vars(target, view->showing_ui, gui_get_scroll_vars(target, scroll_context,
&view->recent->scroll, &view->scroll_region);
#if 0
if (gui_get_scroll_vars(target, scroll_context,
&view->recent->scroll, &view->scroll_region)){ &view->recent->scroll, &view->scroll_region)){
view_move_cursor_to_view(view); view_move_cursor_to_view(view);
} }
#endif
gui_begin_scrollable(target, view->showing_ui, view->recent->scroll, gui_begin_scrollable(target, scroll_context, view->recent->scroll,
delta, show_scrollbar); delta, show_scrollbar);
gui_do_file(target); gui_do_file(target);
gui_end_scrollable(target); gui_end_scrollable(target);
@ -3654,38 +3673,43 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
String message = {0}; String message = {0};
String empty_string = {0}; String empty_string = {0};
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Theme + ((u64)view->color_mode << 32); id.id[1] = VUI_Theme + ((u64)view->color_mode << 32);
GUI_id scroll_context = {0};
scroll_context.id[0] = 0;
scroll_context.id[1] = VUI_Theme + ((u64)view->color_mode << 32);
switch (view->color_mode){ switch (view->color_mode){
case CV_Mode_Library: case CV_Mode_Library:
message = make_lit_string("Current Theme - Click to Edit"); message = make_lit_string("Current Theme - Click to Edit");
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
id.id[0] = (u64)(main_style(models)); id.id[0] = (u64)(main_style(models));
if (gui_do_style_preview(target, id, 0)){ if (gui_do_style_preview(target, id, 0)){
view->color_mode = CV_Mode_Adjusting; view->color_mode = CV_Mode_Adjusting;
} }
message = make_lit_string("Set Font"); message = make_lit_string("Set Font");
id.id[0] = (u64)(&models->global_font); id.id[0] = (u64)(&models->global_font);
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Font; view->color_mode = CV_Mode_Font;
} }
message = make_lit_string("Theme Library - Click to Select"); message = make_lit_string("Theme Library - Click to Select");
gui_do_text_field(target, message, empty_string); gui_do_text_field(target, message, empty_string);
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region); gui_get_scroll_vars(target, scroll_context, &view->gui_scroll, &view->scroll_region);
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, gui_begin_scrollable(target, scroll_context, view->gui_scroll,
9.f * view->font_height, show_scrollbar); 9.f * view->font_height, show_scrollbar);
{ {
i32 count = models->styles.count; i32 count = models->styles.count;
Style *style; Style *style;
i32 i; i32 i;
for (i = 1; i < count; ++i, ++style){ for (i = 1; i < count; ++i, ++style){
style = get_style(models, i); style = get_style(models, i);
id.id[0] = (u64)(style); id.id[0] = (u64)(style);
@ -3694,28 +3718,28 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
gui_end_scrollable(target); gui_end_scrollable(target);
break; break;
case CV_Mode_Font: case CV_Mode_Font:
{ {
Font_Set *font_set = models->font_set; Font_Set *font_set = models->font_set;
Font_Info *info = 0; Font_Info *info = 0;
i16 i = 1, count = (i16)models->font_set->count + 1; i16 i = 1, count = (i16)models->font_set->count + 1;
i16 font_id = 0, new_font_id = 0; i16 font_id = 0, new_font_id = 0;
String message = make_lit_string("Back"); String message = make_lit_string("Back");
id.id[0] = 0; id.id[0] = 0;
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
} }
font_id = models->global_font.font_id; font_id = models->global_font.font_id;
new_font_id = font_id; new_font_id = font_id;
for (i = 1; i < count; ++i){ for (i = 1; i < count; ++i){
info = get_font_info(font_set, i); info = get_font_info(font_set, i);
id.id[0] = (u64)i; id.id[0] = (u64)i;
@ -3732,38 +3756,38 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_do_font_button(target, id, i, message); gui_do_font_button(target, id, i, message);
} }
} }
models->global_font.font_id = (i16)(new_font_id); models->global_font.font_id = (i16)(new_font_id);
}break; }break;
case CV_Mode_Adjusting: case CV_Mode_Adjusting:
{ {
Style *style = main_style(models); Style *style = main_style(models);
u32 *edit_color = 0; u32 *edit_color = 0;
u32 *fore = 0, *back = 0; u32 *fore = 0, *back = 0;
i32 i = 0; i32 i = 0;
String message = make_lit_string("Back"); String message = make_lit_string("Back");
id.id[0] = 0; id.id[0] = 0;
if (gui_do_button(target, id, message)){ if (gui_do_button(target, id, message)){
view->color_mode = CV_Mode_Library; view->color_mode = CV_Mode_Library;
} }
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region); gui_get_scroll_vars(target, scroll_context, &view->gui_scroll, &view->scroll_region);
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, gui_begin_scrollable(target, scroll_context, view->gui_scroll,
9.f * view->font_height, show_scrollbar); 9.f * view->font_height, show_scrollbar);
i32 next_color_editing = view->current_color_editing; i32 next_color_editing = view->current_color_editing;
for (i = 0; i < ArrayCount(colors_to_edit); ++i){ for (i = 0; i < ArrayCount(colors_to_edit); ++i){
edit_color = style_index_by_tag(&style->main, colors_to_edit[i].target); edit_color = style_index_by_tag(&style->main, colors_to_edit[i].target);
id.id[0] = (u64)(edit_color); id.id[0] = (u64)(edit_color);
fore = style_index_by_tag(&style->main, colors_to_edit[i].fore); fore = style_index_by_tag(&style->main, colors_to_edit[i].fore);
back = style_index_by_tag(&style->main, colors_to_edit[i].back); back = style_index_by_tag(&style->main, colors_to_edit[i].back);
if (gui_do_color_button(target, id, *fore, *back, colors_to_edit[i].text)){ if (gui_do_color_button(target, id, *fore, *back, colors_to_edit[i].text)){
next_color_editing = i; next_color_editing = i;
view->color_cursor = 0; view->color_cursor = 0;
@ -3832,38 +3856,41 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
{ {
GUI_id id = {0}; GUI_id id = {0};
id.id[1] = VUI_Interactive + ((u64)view->interaction << 32); id.id[1] = VUI_Interactive + ((u64)view->interaction << 32);
GUI_id scroll_context = {0};
scroll_context.id[1] = VUI_Theme + ((u64)view->color_mode << 32);
switch (view->interaction){ switch (view->interaction){
case IInt_Sys_File_List: case IInt_Sys_File_List:
{ {
b32 use_item_in_list = 1; b32 use_item_in_list = 1;
b32 activate_directly = 0; b32 activate_directly = 0;
if (view->action == IAct_Save_As || view->action == IAct_New){ if (view->action == IAct_Save_As || view->action == IAct_New){
use_item_in_list = 0; use_item_in_list = 0;
} }
String message = {0}; String message = {0};
switch (view->action){ switch (view->action){
case IAct_Open: message = make_lit_string("Open: "); break; case IAct_Open: message = make_lit_string("Open: "); break;
case IAct_Save_As: message = make_lit_string("Save As: "); break; case IAct_Save_As: message = make_lit_string("Save As: "); break;
case IAct_New: message = make_lit_string("New: "); break; case IAct_New: message = make_lit_string("New: "); break;
} }
Exhaustive_File_Loop loop; Exhaustive_File_Loop loop;
Exhaustive_File_Info file_info; Exhaustive_File_Info file_info;
GUI_Item_Update update = {0}; GUI_Item_Update update = {0};
Hot_Directory *hdir = &models->hot_directory; Hot_Directory *hdir = &models->hot_directory;
b32 do_new_directory = 0; b32 do_new_directory = 0;
b32 snap_into_view = 0; b32 snap_into_view = 0;
i32 i = 0; i32 i = 0;
{ {
Single_Line_Input_Step step = {0}; Single_Line_Input_Step step = {0};
Key_Event_Data key = {0}; Key_Event_Data key = {0};
i32 i; i32 i;
for (i = 0; i < keys.count; ++i){ for (i = 0; i < keys.count; ++i){
key = get_single_key(&keys, i); key = get_single_key(&keys, i);
step = app_single_file_input_step(system, &models->working_set, key, step = app_single_file_input_step(system, &models->working_set, key,
@ -3876,21 +3903,23 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
} }
} }
} }
gui_do_text_field(target, message, hdir->string); gui_do_text_field(target, message, hdir->string);
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
if (gui_get_scroll_vars(target, view->showing_ui, &view->gui_scroll, &view->scroll_region)){ scroll_context.id[0] = (u64)(hdir);
if (gui_get_scroll_vars(target, scroll_context,
&view->gui_scroll, &view->scroll_region)){
snap_into_view = 1; snap_into_view = 1;
} }
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, gui_begin_scrollable(target, scroll_context, view->gui_scroll,
9.f * view->font_height, show_scrollbar); 9.f * view->font_height, show_scrollbar);
id.id[0] = (u64)(hdir) + 1; id.id[0] = (u64)(hdir) + 1;
if (gui_begin_list(target, id, view->list_i, 0, if (gui_begin_list(target, id, view->list_i, 0,
snap_into_view, &update)){ snap_into_view, &update)){
gui_standard_list(target, id, view->scroll_region, gui_standard_list(target, id, view->current_scroll, view->scroll_region,
&keys, &view->list_i, &update); &keys, &view->list_i, &update);
} }
@ -3920,14 +3949,14 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
if (activate_directly){ if (activate_directly){
interactive_view_complete(view, hdir->string, 0); interactive_view_complete(view, hdir->string, 0);
} }
if (do_new_directory){ if (do_new_directory){
hot_directory_reload(system, hdir, &models->working_set); hot_directory_reload(system, hdir, &models->working_set);
} }
gui_end_scrollable(target); gui_end_scrollable(target);
}break; }break;
case IInt_Live_File_List: case IInt_Live_File_List:
{ {
b32 snap_into_view = 0; b32 snap_into_view = 0;
@ -3964,17 +3993,18 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
gui_do_text_field(target, message, view->dest); gui_do_text_field(target, message, view->dest);
view->current_scroll = &view->gui_scroll; view->current_scroll = &view->gui_scroll;
if (gui_get_scroll_vars(target, view->showing_ui, scroll_context.id[0] = (u64)(working_set);
if (gui_get_scroll_vars(target, scroll_context,
&view->gui_scroll, &view->scroll_region)){ &view->gui_scroll, &view->scroll_region)){
snap_into_view = 1; snap_into_view = 1;
} }
gui_begin_scrollable(target, view->showing_ui, view->gui_scroll, gui_begin_scrollable(target, scroll_context, view->gui_scroll,
9.f * view->font_height, show_scrollbar); 9.f * view->font_height, show_scrollbar);
id.id[0] = (u64)(working_set) + 1; id.id[0] = (u64)(working_set) + 1;
if (gui_begin_list(target, id, view->list_i, if (gui_begin_list(target, id, view->list_i,
0, snap_into_view, &update)){ 0, snap_into_view, &update)){
gui_standard_list(target, id, view->scroll_region, gui_standard_list(target, id, view->current_scroll, view->scroll_region,
&keys, &view->list_i, &update); &keys, &view->list_i, &update);
} }
@ -4165,18 +4195,28 @@ scroll_button_input(GUI_Target *target, GUI_Session *session, Input_Summary *use
return(result); return(result);
} }
internal b32 struct Input_Process_Result{
GUI_Scroll_Vars vars;
i32_Rect region;
b32 is_animating;
};
internal Input_Process_Result
do_input_file_view(System_Functions *system, Exchange *exchange, do_input_file_view(System_Functions *system, Exchange *exchange,
View *view, i32_Rect rect, b32 is_active, View *view, i32_Rect rect, b32 is_active,
Input_Summary *user_input){ Input_Summary *user_input,
b32 is_animating = 0; GUI_Scroll_Vars vars, i32_Rect region){
Input_Process_Result result = {0};
b32 is_file_scroll = 0; b32 is_file_scroll = 0;
GUI_Session gui_session = {0}; GUI_Session gui_session = {0};
GUI_Header *h = 0; GUI_Header *h = 0;
GUI_Target *target = &view->gui_target; GUI_Target *target = &view->gui_target;
GUI_Interpret_Result interpret_result = {0}; GUI_Interpret_Result interpret_result = {0};
result.vars = vars;
result.region = region;
gui_session_init(&gui_session, target, rect, view->font_height); gui_session_init(&gui_session, target, rect, view->font_height);
target->active = gui_id_zero(); target->active = gui_id_zero();
@ -4184,8 +4224,13 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
for (h = (GUI_Header*)target->push.base; for (h = (GUI_Header*)target->push.base;
h->type; h->type;
h = NextHeader(h)){ h = NextHeader(h)){
interpret_result = gui_interpret(target, &gui_session, h); interpret_result = gui_interpret(target, &gui_session, h,
result.vars, result.region);
if (interpret_result.has_region){
result.region = interpret_result.region;
}
switch (h->type){ switch (h->type){
case guicom_file_option: case guicom_file_option:
case guicom_fixed_option: case guicom_fixed_option:
@ -4196,12 +4241,12 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
if (interpret_result.auto_activate){ if (interpret_result.auto_activate){
target->auto_hot = gui_id_zero(); target->auto_hot = gui_id_zero();
target->active = b->id; target->active = b->id;
is_animating = 1; result.is_animating = 1;
} }
else if (interpret_result.auto_hot){ else if (interpret_result.auto_hot){
if (!gui_id_eq(target->auto_hot, b->id)){ if (!gui_id_eq(target->auto_hot, b->id)){
target->auto_hot = b->id; target->auto_hot = b->id;
is_animating = 1; result.is_animating = 1;
} }
} }
}break; }break;
@ -4218,15 +4263,15 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
f32 new_max_y = view_compute_max_target_y(view); f32 new_max_y = view_compute_max_target_y(view);
view->file_region = gui_session.rect; view->file_region = gui_session.rect;
view->gui_target.scroll_updated.min_y = new_min_y; result.vars.min_y = new_min_y;
view->gui_target.scroll_updated.max_y = new_max_y; result.vars.max_y = new_max_y;
if (view->reinit_scrolling){ if (view->reinit_scrolling){
view_reinit_scrolling(view); view_reinit_scrolling(view);
is_animating = 1; result.is_animating = 1;
} }
if (file_step(view, gui_session.rect, user_input, is_active)){ if (file_step(view, gui_session.rect, user_input, is_active)){
is_animating = 1; result.is_animating = 1;
} }
is_file_scroll = 1; is_file_scroll = 1;
}break; }break;
@ -4239,7 +4284,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &is_animating); click_button_input(target, &gui_session, user_input, b, &result.is_animating);
}break; }break;
case guicom_fixed_option: case guicom_fixed_option:
@ -4247,7 +4292,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
{ {
GUI_Interactive *b = (GUI_Interactive*)h; GUI_Interactive *b = (GUI_Interactive*)h;
click_button_input(target, &gui_session, user_input, b, &is_animating); click_button_input(target, &gui_session, user_input, b, &result.is_animating);
{ {
Key_Event_Data key; Key_Event_Data key;
@ -4267,7 +4312,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
key = get_single_key(keys, i); key = get_single_key(keys, i);
if (char_to_upper(key.character) == char_to_upper(activation_key)){ if (char_to_upper(key.character) == char_to_upper(activation_key)){
target->active = b->id; target->active = b->id;
is_animating = 1; result.is_animating = 1;
break; break;
} }
} }
@ -4276,7 +4321,12 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_scrollable: case guicom_scrollable:
{ {
view->scroll_region = target->region_updated; #if 0
// TODO(allen): Think about this... should we be setting anything in the view?
// Seems like an issue. Should instead return this and have the user set it
// right?
view->scroll_region = result.region;
#endif
}break; }break;
case guicom_scrollable_slider: case guicom_scrollable_slider:
@ -4290,7 +4340,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
target->hover = id; target->hover = id;
if (user_input->mouse.press_l){ if (user_input->mouse.press_l){
target->mouse_hot = id; target->mouse_hot = id;
is_animating = 1; result.is_animating = 1;
} }
} }
else if (gui_id_eq(target->hover, id)){ else if (gui_id_eq(target->hover, id)){
@ -4302,12 +4352,11 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
gui_session.scroll_bottom); gui_session.scroll_bottom);
if (v < 0) v = 0; if (v < 0) v = 0;
if (v > 1.f) v = 1.f; if (v > 1.f) v = 1.f;
target->scroll_updated.target_y = result.vars.target_y =
lerp(target->scroll_updated.min_y, v, lerp(result.vars.min_y, v, result.vars.max_y);
target->scroll_updated.max_y);
gui_activate_scrolling(target); gui_activate_scrolling(target);
is_animating = 1; result.is_animating = 1;
} }
} }
// NOTE(allen): NO BREAK HERE!! // NOTE(allen): NO BREAK HERE!!
@ -4315,16 +4364,16 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
case guicom_scrollable_invisible: case guicom_scrollable_invisible:
{ {
if (user_input->mouse.wheel != 0){ if (user_input->mouse.wheel != 0){
target->scroll_updated.target_y += user_input->mouse.wheel*target->delta; result.vars.target_y += user_input->mouse.wheel*target->delta;
if (target->scroll_updated.target_y < target->scroll_updated.min_y){ if (result.vars.target_y < result.vars.min_y){
target->scroll_updated.target_y = target->scroll_updated.min_y; result.vars.target_y = result.vars.min_y;
} }
if (target->scroll_updated.target_y > target->scroll_updated.max_y){ if (result.vars.target_y > result.vars.max_y){
target->scroll_updated.target_y = target->scroll_updated.max_y; result.vars.target_y = result.vars.max_y;
} }
gui_activate_scrolling(target); gui_activate_scrolling(target);
is_animating = 1; result.is_animating = 1;
} }
}break; }break;
@ -4332,10 +4381,10 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
{ {
GUI_id id = gui_id_scrollbar_top(); GUI_id id = gui_id_scrollbar_top();
if (scroll_button_input(target, &gui_session, user_input, id, &is_animating)){ if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){
target->scroll_updated.target_y -= target->delta * 0.25f; result.vars.target_y -= target->delta * 0.25f;
if (target->scroll_updated.target_y < target->scroll_updated.min_y){ if (result.vars.target_y < result.vars.min_y){
target->scroll_updated.target_y = target->scroll_updated.min_y; result.vars.target_y = result.vars.min_y;
} }
} }
}break; }break;
@ -4344,10 +4393,10 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
{ {
GUI_id id = gui_id_scrollbar_bottom(); GUI_id id = gui_id_scrollbar_bottom();
if (scroll_button_input(target, &gui_session, user_input, id, &is_animating)){ if (scroll_button_input(target, &gui_session, user_input, id, &result.is_animating)){
target->scroll_updated.target_y += target->delta * 0.25f; result.vars.target_y += target->delta * 0.25f;
if (target->scroll_updated.target_y > target->scroll_updated.max_y){ if (result.vars.target_y > result.vars.max_y){
target->scroll_updated.target_y = target->scroll_updated.max_y; result.vars.target_y = result.vars.max_y;
} }
} }
}break; }break;
@ -4358,8 +4407,8 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
f32 new_min_y = gui_session.suggested_min_y; f32 new_min_y = gui_session.suggested_min_y;
f32 new_max_y = gui_session.suggested_max_y; f32 new_max_y = gui_session.suggested_max_y;
view->gui_target.scroll_updated.min_y = new_min_y; result.vars.min_y = new_min_y;
view->gui_target.scroll_updated.max_y = new_max_y; result.vars.max_y = new_max_y;
} }
}break; }break;
} }
@ -4369,12 +4418,12 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
if (!user_input->mouse.l){ if (!user_input->mouse.l){
if (!gui_id_is_null(target->mouse_hot)){ if (!gui_id_is_null(target->mouse_hot)){
target->mouse_hot = gui_id_zero(); target->mouse_hot = gui_id_zero();
is_animating = 1; result.is_animating = 1;
} }
} }
{ {
GUI_Scroll_Vars scroll_vars = view->gui_target.scroll_updated; GUI_Scroll_Vars scroll_vars = result.vars;
b32 is_new_target = 0; b32 is_new_target = 0;
if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = 1; if (scroll_vars.target_x != scroll_vars.prev_target_x) is_new_target = 1;
if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = 1; if (scroll_vars.target_y != scroll_vars.prev_target_y) is_new_target = 1;
@ -4382,15 +4431,15 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
if (view->models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y, if (view->models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y,
&scroll_vars.scroll_x, &scroll_vars.scroll_y, &scroll_vars.scroll_x, &scroll_vars.scroll_y,
(view->id) + 1, is_new_target)){ (view->id) + 1, is_new_target)){
is_animating = 1; result.is_animating = 1;
} }
scroll_vars.prev_target_x = scroll_vars.target_x; scroll_vars.prev_target_x = scroll_vars.target_x;
scroll_vars.prev_target_y = scroll_vars.target_y; scroll_vars.prev_target_y = scroll_vars.target_y;
view->gui_target.scroll_updated = scroll_vars; result.vars = scroll_vars;
} }
{ {
Key_Summary *keys = &user_input->keys; Key_Summary *keys = &user_input->keys;
b32 did_esc = 0; b32 did_esc = 0;
@ -4411,7 +4460,7 @@ do_input_file_view(System_Functions *system, Exchange *exchange,
} }
} }
return(is_animating); return(result);
} }
internal i32 internal i32
@ -4458,7 +4507,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
render_cursor = buffer_get_start_cursor(&file->state.buffer, wraps, scroll_y, render_cursor = buffer_get_start_cursor(&file->state.buffer, wraps, scroll_y,
!view->file_data.unwrapped_lines, (f32)max_x, advance_data, (f32)line_height); !view->file_data.unwrapped_lines, (f32)max_x, advance_data, (f32)line_height);
view->file_data.scroll_i = render_cursor.pos; view->recent->scroll_i = render_cursor.pos;
buffer_get_render_data(&file->state.buffer, items, max, &count, buffer_get_render_data(&file->state.buffer, items, max, &count,
(f32)rect.x0, (f32)rect.y0, (f32)rect.x0, (f32)rect.y0,
@ -4480,7 +4529,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
at_cursor_color = style->main.at_highlight_color; at_cursor_color = style->main.at_highlight_color;
} }
else{ else{
cursor_begin = view->file_data.cursor.pos; cursor_begin = view->recent->cursor.pos;
cursor_end = cursor_begin + 1; cursor_end = cursor_begin + 1;
cursor_color = style->main.cursor_color; cursor_color = style->main.cursor_color;
at_cursor_color = style->main.at_cursor_color; at_cursor_color = style->main.at_cursor_color;
@ -4567,7 +4616,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); char_color = color_blend(char_color, fade_amount, fade_color);
if (ind == view->file_data.mark && prev_ind != ind){ if (ind == view->recent->mark && prev_ind != ind){
draw_rectangle_outline(target, char_rect, mark_color); draw_rectangle_outline(target, char_rect, mark_color);
} }
if (item->glyphid != 0){ if (item->glyphid != 0){
@ -4685,9 +4734,9 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
char line_number_space[30]; char line_number_space[30];
String line_number = make_fixed_width_string(line_number_space); String line_number = make_fixed_width_string(line_number_space);
append(&line_number, " L#"); append(&line_number, " L#");
append_int_to_str(view->file_data.cursor.line, &line_number); append_int_to_str(view->recent->cursor.line, &line_number);
append(&line_number, " C#"); append(&line_number, " C#");
append_int_to_str(view->file_data.cursor.character, &line_number); append_int_to_str(view->recent->cursor.character, &line_number);
intbar_draw_string(target, &bar, line_number, base_color); intbar_draw_string(target, &bar, line_number, base_color);
@ -4914,7 +4963,10 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
for (h = (GUI_Header*)gui_target->push.base; for (h = (GUI_Header*)gui_target->push.base;
h->type; h->type;
h = NextHeader(h)){ h = NextHeader(h)){
interpret_result = gui_interpret(gui_target, &gui_session, h); interpret_result = gui_interpret(gui_target, &gui_session, h,
*view->current_scroll,
view->scroll_region);
if (interpret_result.has_info){ if (interpret_result.has_info){
if (gui_session.clip_y > clip_rect.y0){ if (gui_session.clip_y > clip_rect.y0){
clip_rect.y0 = gui_session.clip_y; clip_rect.y0 = gui_session.clip_y;
@ -5086,7 +5138,7 @@ do_render_file_view(System_Functions *system, Exchange *exchange,
}break; }break;
case guicom_begin_scrollable_section: case guicom_begin_scrollable_section:
clip_rect.x1 = Min(gui_target->region_updated.x1, clip_rect.x1); clip_rect.x1 = Min(gui_session.scroll_region.x1, clip_rect.x1);
draw_push_clip(target, clip_rect); draw_push_clip(target, clip_rect);
break; break;
@ -5331,7 +5383,7 @@ inline void
view_change_size(General_Memory *general, View *view){ view_change_size(General_Memory *general, View *view){
if (view->file_data.file){ if (view->file_data.file){
view_measure_wraps(general, view); view_measure_wraps(general, view);
view->file_data.cursor = view_compute_cursor_from_pos(view, view->file_data.cursor.pos); view->recent->cursor = view_compute_cursor_from_pos(view, view->recent->cursor.pos);
} }
} }

View File

@ -156,8 +156,8 @@ struct GUI_Target{
i32 list_view_min; i32 list_view_min;
i32 list_view_max; i32 list_view_max;
GUI_id scroll_id;
f32 delta; f32 delta;
u32 scroll_id;
b32 has_keys; b32 has_keys;
b32 animating; b32 animating;
b32 did_file; b32 did_file;
@ -675,9 +675,9 @@ 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: // 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. // Getting the updated scroll vars, and telling the user when scrolling actions occur.
internal b32 internal b32
gui_get_scroll_vars(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars *vars_out, i32_Rect *region_out){ gui_get_scroll_vars(GUI_Target *target, GUI_id scroll_context_id, GUI_Scroll_Vars *vars_out, i32_Rect *region_out){
b32 result = 0; b32 result = 0;
if (target->scroll_id == scroll_id){ if (gui_id_eq(scroll_context_id, target->scroll_id)){
*vars_out = target->scroll_updated; *vars_out = target->scroll_updated;
*region_out = target->region_updated; *region_out = target->region_updated;
@ -695,23 +695,19 @@ gui_get_scroll_vars(GUI_Target *target, u32 scroll_id, GUI_Scroll_Vars *vars_out
return(result); return(result);
} }
internal GUI_Scroll_Vars
gui_current_scroll_vars(GUI_Target *target){
GUI_Scroll_Vars vars = target->scroll_updated;
return(vars);
}
internal void internal void
gui_post_scroll_vars(GUI_Target *target, GUI_Scroll_Vars *vars_in){ 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)){ if (!gui_scroll_eq(vars_in, &target->scroll_updated) ||
!rect_equal(region_in, target->region_updated)){
target->scroll_updated = *vars_in; target->scroll_updated = *vars_in;
target->region_updated = region_in;
target->animating = 1; target->animating = 1;
target->active = gui_id_scrollbar(); target->active = gui_id_scrollbar();
} }
} }
internal void internal void
gui_begin_scrollable(GUI_Target *target, u32 scroll_id, gui_begin_scrollable(GUI_Target *target, GUI_id scroll_context_id,
GUI_Scroll_Vars scroll_vars, f32 delta, b32 show_bar){ GUI_Scroll_Vars scroll_vars, f32 delta, b32 show_bar){
GUI_Header *h; GUI_Header *h;
@ -722,7 +718,7 @@ gui_begin_scrollable(GUI_Target *target, u32 scroll_id,
target->scroll_original = scroll_vars; target->scroll_original = scroll_vars;
target->scroll_updated = scroll_vars; target->scroll_updated = scroll_vars;
target->scroll_id = scroll_id; target->scroll_id = scroll_context_id;
if (show_bar){ if (show_bar){
gui_push_simple_command(target, guicom_scrollable_bar); gui_push_simple_command(target, guicom_scrollable_bar);
@ -969,10 +965,14 @@ struct GUI_Interpret_Result{
b32 auto_hot; b32 auto_hot;
b32 auto_activate; b32 auto_activate;
i32 screen_orientation; i32 screen_orientation;
b32 has_region;
i32_Rect region;
}; };
internal GUI_Interpret_Result internal GUI_Interpret_Result
gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h,
GUI_Scroll_Vars vars, i32_Rect region){
GUI_Interpret_Result result = {0}; GUI_Interpret_Result result = {0};
GUI_Section *section = 0; GUI_Section *section = 0;
GUI_Section *new_section = 0; GUI_Section *new_section = 0;
@ -987,7 +987,7 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
i32 end_v = -1; i32 end_v = -1;
f32 lerp_space_scroll_v = 0; f32 lerp_space_scroll_v = 0;
i32 scroll_v = (i32)target->scroll_original.scroll_y; i32 scroll_v = (i32)target->scroll_original.scroll_y;
i32 target_v = (i32)target->scroll_updated.target_y; i32 target_v = (i32)vars.target_y;
Assert(session->t < ArrayCount(session->sections)); Assert(session->t < ArrayCount(session->sections));
section = session->sections + session->t; section = session->sections + session->t;
@ -1140,7 +1140,8 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
scrollable_rect.x1 = session->full_rect.x1; scrollable_rect.x1 = session->full_rect.x1;
scrollable_rect.y0 = y; scrollable_rect.y0 = y;
scrollable_rect.y1 = session->full_rect.y1; scrollable_rect.y1 = session->full_rect.y1;
target->region_updated = scrollable_rect; result.has_region = 1;
result.region = scrollable_rect;
session->scroll_region = scrollable_rect; session->scroll_region = scrollable_rect;
} }
break; break;
@ -1161,7 +1162,8 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
scrollable_rect.x1 = rect.x0; scrollable_rect.x1 = rect.x0;
scrollable_rect.y0 = y; scrollable_rect.y0 = y;
scrollable_rect.y1 = session->full_rect.y1; scrollable_rect.y1 = session->full_rect.y1;
target->region_updated = scrollable_rect; result.has_region = 1;
result.region = scrollable_rect;
session->scroll_region = scrollable_rect; session->scroll_region = scrollable_rect;
} }
scroll_v = 0; scroll_v = 0;
@ -1229,7 +1231,6 @@ gui_interpret(GUI_Target *target, GUI_Session *session, GUI_Header *h){
if (do_layout){ if (do_layout){
if (session->list.in_list && is_list_item){ if (session->list.in_list && is_list_item){
i32 list_i = session->list.index - 1; i32 list_i = session->list.index - 1;
i32_Rect region = target->region_updated;
if (rect.y0 - target_v >= region.y0 && if (rect.y0 - target_v >= region.y0 &&
rect.y1 - target_v <= region.y1){ rect.y1 - target_v <= region.y1){
@ -1292,21 +1293,19 @@ gui_compute_view_jump(i32_Rect scroll_region, i32_Rect position){
return(jump); return(jump);
} }
internal void internal GUI_Scroll_Vars
gui_do_jump(GUI_Target *target, GUI_View_Jump jump){ gui_do_jump(GUI_Target *target, GUI_View_Jump jump, GUI_Scroll_Vars vars){
GUI_Scroll_Vars vars = gui_current_scroll_vars(target);
if (vars.target_y < jump.view_min){ if (vars.target_y < jump.view_min){
vars.target_y = jump.view_min; vars.target_y = jump.view_min;
gui_post_scroll_vars(target, &vars);
} }
else if (vars.target_y > jump.view_max){ else if (vars.target_y > jump.view_max){
vars.target_y = jump.view_max; vars.target_y = jump.view_max;
gui_post_scroll_vars(target, &vars);
} }
return(vars);
} }
internal void internal void
gui_standard_list(GUI_Target *target, GUI_id id, i32_Rect scroll_region, gui_standard_list(GUI_Target *target, GUI_id id, GUI_Scroll_Vars *vars, i32_Rect scroll_region,
Key_Summary *keys, i32 *list_i, GUI_Item_Update *update){ Key_Summary *keys, i32 *list_i, GUI_Item_Update *update){
if (update->has_adjustment){ if (update->has_adjustment){
@ -1318,7 +1317,7 @@ gui_standard_list(GUI_Target *target, GUI_id id, i32_Rect scroll_region,
gui_compute_view_jump(scroll_region, update->index_position); gui_compute_view_jump(scroll_region, update->index_position);
jump.view_min += 45.f; jump.view_min += 45.f;
jump.view_max -= 45.f; jump.view_max -= 45.f;
gui_do_jump(target, jump); *vars = gui_do_jump(target, jump, *vars);
} }
b32 indirectly_activate = 0; b32 indirectly_activate = 0;