basic navigation kinda works most of the time
parent
da7a09ca0d
commit
df5535cc87
|
@ -393,15 +393,36 @@ view_compute_cursor(View *view, Buffer_Seek seek){
|
|||
Buffer_Cursor_Seek_Params params;
|
||||
params.buffer = &file->state.buffer;
|
||||
params.seek = seek;
|
||||
params.max_width = view_file_display_width(view);
|
||||
params.width = view_file_display_width(view);
|
||||
params.font_height = (f32)font->height;
|
||||
params.adv = font->advance_data;
|
||||
params.wraps = file->state.wraps;
|
||||
params.virtual_white = 0;
|
||||
params.virtual_white = 1;
|
||||
|
||||
Buffer_Cursor_Seek_State state = {0};
|
||||
Full_Cursor result;
|
||||
buffer_cursor_seek(&state, params, 0, &result);
|
||||
Buffer_Layout_Stop stop;
|
||||
|
||||
f32 edge_tolerance = 50.f;
|
||||
if (edge_tolerance > params.width){
|
||||
edge_tolerance = params.width;
|
||||
}
|
||||
|
||||
f32 line_shift = 0.f;
|
||||
do{
|
||||
f32 this_line_shift = line_shift;
|
||||
if (this_line_shift > params.width - edge_tolerance){
|
||||
this_line_shift = params.width - edge_tolerance;
|
||||
}
|
||||
|
||||
stop = buffer_cursor_seek(&state, params, this_line_shift, &result);
|
||||
switch (stop.status){
|
||||
case BLStatus_NeedWrapLineShift:
|
||||
case BLStatus_NeedLineShift:
|
||||
line_shift = (stop.line_index%4)*9.f;
|
||||
break;
|
||||
}
|
||||
}while(stop.status != BLStatus_Finished);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
@ -4758,17 +4779,12 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
Buffer_Render_State state = {0};
|
||||
Buffer_Layout_Stop stop;
|
||||
|
||||
f32 line_shift = (render_cursor.line%4)*15.f + 30.f;
|
||||
while (line_shift >= 60.f){
|
||||
line_shift -= 60.f;
|
||||
}
|
||||
|
||||
f32 edge_tolerance = 50.f;
|
||||
|
||||
if (edge_tolerance > params.width){
|
||||
edge_tolerance = params.width;
|
||||
}
|
||||
|
||||
f32 line_shift = 0.f;
|
||||
do{
|
||||
f32 this_line_shift = line_shift;
|
||||
if (this_line_shift > params.width - edge_tolerance){
|
||||
|
@ -4779,10 +4795,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
switch (stop.status){
|
||||
case BLStatus_NeedWrapLineShift:
|
||||
case BLStatus_NeedLineShift:
|
||||
line_shift += 15.f;
|
||||
if (line_shift >= 60.f){
|
||||
line_shift -= 60.f;
|
||||
}
|
||||
line_shift = (stop.line_index%4)*9.f;
|
||||
break;
|
||||
}
|
||||
}while(stop.status != BLStatus_Finished);
|
||||
|
|
|
@ -424,8 +424,12 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character)
|
|||
max_character = (next_start-this_start);
|
||||
}
|
||||
|
||||
if (character <= 0) character = 1;
|
||||
if (character > max_character) character = max_character;
|
||||
if (character <= 0){
|
||||
character = 1;
|
||||
}
|
||||
if (character > max_character){
|
||||
character = max_character;
|
||||
}
|
||||
|
||||
result.pos = this_start + character - 1;
|
||||
result.line = line_index+1;
|
||||
|
@ -437,7 +441,7 @@ buffer_partial_from_line_character(Buffer_Type *buffer, i32 line, i32 character)
|
|||
struct Buffer_Cursor_Seek_Params{
|
||||
Buffer_Type *buffer;
|
||||
Buffer_Seek seek;
|
||||
f32 max_width;
|
||||
f32 width;
|
||||
f32 font_height;
|
||||
f32 *adv;
|
||||
f32 *wraps;
|
||||
|
@ -553,10 +557,10 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
|
||||
S.stream.use_termination_character = 1;
|
||||
S.stream.terminator = '\n';
|
||||
if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){
|
||||
if (buffer_stringify_loop(&S.stream, params.buffer, S.cursor.pos, S.size)){
|
||||
do{
|
||||
for (; S.cursor.pos < S.stream.end; ++S.cursor.pos){
|
||||
S.ch = (u8)S.stream.data[S.i];
|
||||
S.ch = (u8)S.stream.data[S.cursor.pos];
|
||||
|
||||
if (S.ch != ' ' && S.ch != '\t'){
|
||||
goto double_break_vwhite;
|
||||
|
@ -564,10 +568,12 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
else{
|
||||
++S.cursor.character;
|
||||
}
|
||||
|
||||
}
|
||||
S.still_looping = buffer_stringify_next(&S.stream);
|
||||
}while(S.still_looping);
|
||||
}
|
||||
InvalidCodePath;
|
||||
double_break_vwhite:;
|
||||
}
|
||||
|
||||
|
@ -605,9 +611,9 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
// Main seek loop
|
||||
S.i = S.cursor.pos;
|
||||
|
||||
S.stream = null_buffer_stream;
|
||||
S.stream.use_termination_character = 1;
|
||||
S.stream.terminator = 0;
|
||||
|
||||
if (buffer_stringify_loop(&S.stream, params.buffer, S.i, S.size)){
|
||||
S.still_looping = 0;
|
||||
do{
|
||||
|
@ -631,7 +637,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
|
|||
{
|
||||
f32 ch_width = params.adv[S.ch];
|
||||
|
||||
if (S.cursor.wrapped_x + ch_width > params.max_width){
|
||||
if (S.cursor.wrapped_x + ch_width > params.width){
|
||||
S.cursor.wrapped_y += params.font_height;
|
||||
S.cursor.wrapped_x = 0;
|
||||
S.prev_cursor = S.cursor;
|
||||
|
|
|
@ -108,6 +108,7 @@ typedef struct Gap_Buffer_Stream{
|
|||
b32 use_termination_character;
|
||||
char terminator;
|
||||
} Gap_Buffer_Stream;
|
||||
static Gap_Buffer_Stream null_buffer_stream = {0};
|
||||
|
||||
internal_4tech b32
|
||||
buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){
|
||||
|
|
Loading…
Reference in New Issue