now only writing buffer render items if they fall in the clip range of the view.
This commit is contained in:
parent
1e8bea250e
commit
33407c2258
|
@ -4898,6 +4898,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
Style *style = main_style(models);
|
||||
i32 line_height = view->line_height;
|
||||
|
||||
f32 clip_w = view_width(view);
|
||||
f32 max_x = view_file_display_width(view);
|
||||
i32 max_y = rect.y1 - rect.y0 + line_height;
|
||||
|
||||
|
@ -4946,8 +4947,8 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
view->edit_pos->scroll_i = render_cursor.pos;
|
||||
|
||||
buffer_get_render_data(&file->state.buffer, items, max, &count,
|
||||
(f32)rect.x0, (f32)rect.y0, max_x, (f32)max_y,
|
||||
scroll_x, scroll_y,
|
||||
(f32)rect.x0, (f32)rect.y0, clip_w,
|
||||
scroll_x, scroll_y, max_x, (f32)max_y,
|
||||
render_cursor, !view->file_data.unwrapped_lines,
|
||||
advance_data, (f32)line_height);
|
||||
}
|
||||
|
|
1
TODO.txt
1
TODO.txt
|
@ -142,6 +142,7 @@
|
|||
; [] more built in options for auto indenting
|
||||
;
|
||||
; [X] eliminate the need for the lexer state's spare array.
|
||||
; [X] fix buffer render item capacity issue
|
||||
|
||||
; Arbitrary wrap positions
|
||||
; [X] allow for arbitrary wrap positions independent of view width
|
||||
|
|
|
@ -788,34 +788,35 @@ typedef struct Render_Item_Write{
|
|||
f32 x, y;
|
||||
f32 *adv;
|
||||
f32 font_height;
|
||||
f32 x_min;
|
||||
f32 x_max;
|
||||
} Render_Item_Write;
|
||||
|
||||
inline_4tech f32
|
||||
write_render_item(Buffer_Render_Item *item,
|
||||
i32 index, u16 glyphid, u16 flags,
|
||||
f32 x, f32 y, f32 *adv, f32 h){
|
||||
f32 ch_width = measure_character(adv, (char)glyphid);
|
||||
item->index = index;
|
||||
item->glyphid = glyphid;
|
||||
item->flags = flags;
|
||||
item->x0 = x;
|
||||
item->y0 = y;
|
||||
item->x1 = x + ch_width;
|
||||
item->y1 = y + h;
|
||||
return(ch_width);
|
||||
inline_4tech Render_Item_Write
|
||||
write_render_item(Render_Item_Write write, i32 index, u16 glyphid, u16 flags){
|
||||
f32 ch_width = measure_character(write.adv, (char)glyphid);
|
||||
|
||||
if (write.x <= write.x_max && write.x + ch_width >= write.x_min){
|
||||
write.item->index = index;
|
||||
write.item->glyphid = glyphid;
|
||||
write.item->flags = flags;
|
||||
write.item->x0 = write.x;
|
||||
write.item->y0 = write.y;
|
||||
write.item->x1 = write.x + ch_width;
|
||||
write.item->y1 = write.y + write.font_height;
|
||||
|
||||
++write.item;
|
||||
}
|
||||
|
||||
inline_4tech f32
|
||||
write_render_item(Render_Item_Write write, i32 index, u16 glyphid, u16 flags){
|
||||
f32 w = write_render_item(write.item, index, glyphid, flags,
|
||||
write.x, write.y, write.adv, write.font_height);
|
||||
return(w);
|
||||
write.x += ch_width;
|
||||
|
||||
return(write);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max, i32 *count,
|
||||
f32 port_x, f32 port_y, f32 width, f32 height,
|
||||
f32 scroll_x, f32 scroll_y,
|
||||
f32 port_x, f32 port_y, f32 clip_w,
|
||||
f32 scroll_x, f32 scroll_y, f32 width, f32 height,
|
||||
Full_Cursor start_cursor,
|
||||
i32 wrapped, f32 *adv, f32 font_height){
|
||||
|
||||
|
@ -841,11 +842,9 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
write.y = shift_y;
|
||||
write.adv = adv;
|
||||
write.font_height = font_height;
|
||||
write.x_min = port_x;
|
||||
write.x_max = port_x + clip_w;
|
||||
|
||||
// TODO(allen): What's the plan for when there is not enough space to store
|
||||
// more render items? It seems like we should be able to use the view_x
|
||||
// to skip items that are not in view right? That way I think it would
|
||||
// just always fit in the buffer.
|
||||
if (adv){
|
||||
for (loop = buffer_stringify_loop(buffer, start_cursor.pos, size);
|
||||
buffer_stringify_good(&loop) && write.item < item_end;
|
||||
|
@ -869,8 +868,7 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
switch (ch){
|
||||
case '\n':
|
||||
if (write.item < item_end){
|
||||
write_render_item(write, i, ' ', 0);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, ' ', 0);
|
||||
write.x = shift_x;
|
||||
write.y += font_height;
|
||||
}
|
||||
|
@ -878,34 +876,29 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
|
||||
case '\r':
|
||||
if (write.item < item_end){
|
||||
write.x += write_render_item(write, i, '\\', BRFlag_Special_Character);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, '\\', BRFlag_Special_Character);
|
||||
|
||||
if (write.item < item_end){
|
||||
write.x += write_render_item(write, i, 'r', BRFlag_Special_Character);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, 'r', BRFlag_Special_Character);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
if (write.item < item_end){
|
||||
write_render_item(write, i, ' ', 0);
|
||||
++write.item;
|
||||
write.x += ch_width;
|
||||
i32 new_x = write.x + ch_width;
|
||||
write = write_render_item(write, i, ' ', 0);
|
||||
write.x = new_x;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (write.item < item_end){
|
||||
if (ch >= ' ' && ch <= '~'){
|
||||
write_render_item(write, i, ch, 0);
|
||||
++write.item;
|
||||
write.x += ch_width;
|
||||
write = write_render_item(write, i, ch, 0);
|
||||
}
|
||||
else{
|
||||
write.x += write_render_item(write, i, '\\', BRFlag_Special_Character);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, '\\', BRFlag_Special_Character);
|
||||
|
||||
char C = '0' + (ch / 0x10);
|
||||
if ((ch / 0x10) > 0x9){
|
||||
|
@ -913,8 +906,7 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
}
|
||||
|
||||
if (write.item < item_end){
|
||||
write.x += write_render_item(write, i, C, BRFlag_Special_Character);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, C, BRFlag_Special_Character);
|
||||
}
|
||||
|
||||
ch = (ch % 0x10);
|
||||
|
@ -924,8 +916,7 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
}
|
||||
|
||||
if (write.item < item_end){
|
||||
write.x += write_render_item(write, i, C, BRFlag_Special_Character);
|
||||
++write.item;
|
||||
write = write_render_item(write, i, C, BRFlag_Special_Character);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -942,7 +933,6 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
if (write.y <= height + shift_y || write.item == items){
|
||||
if (write.item < item_end){
|
||||
write_render_item(write, size, ' ', 0);
|
||||
++write.item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -952,7 +942,6 @@ buffer_get_render_data(Buffer_Type *buffer, Buffer_Render_Item *items, i32 max,
|
|||
|
||||
if (write.item < item_end){
|
||||
write_render_item(write, size, 0, 0);
|
||||
++write.item;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue