Cleaning up layout types

This commit is contained in:
Allen Webster 2019-11-03 16:03:23 -08:00
parent c2f22de3ad
commit 5b9a29e215
6 changed files with 75 additions and 81 deletions

View File

@ -2938,15 +2938,16 @@ text_layout_character_on_screen(Application_Links *app, Text_Layout_ID layout_id
for (Layout_Item_Block *block = line.first;
block != 0;
block = block->next){
i64 count = block->item_count;
Layout_Item *item_ptr = block->items;
i64 count = block->count;
for (i32 i = 0; i < count; i += 1, item_ptr += 1){
if (HasFlag(item_ptr->flags, LayoutItemFlag_Ghost_Character)){
continue;
}
i64 index = item_ptr->index;
if (index == pos){
if (!HasFlag(item_ptr->flags, LayoutItemFlag_Ghost_Character)){
result = rect_union(result, item_ptr->rect);
}
}
else if (index > pos){
break;
}

View File

@ -872,7 +872,7 @@ buffer_layout_nearest_pos_to_xy(Layout_Item_List list, Vec2_f32 p){
for (Layout_Item_Block *block = list.first;
block != 0;
block = block->next){
i64 count = block->count;
i64 count = block->item_count;
Layout_Item *item = block->items;
for (i32 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
@ -910,7 +910,7 @@ buffer_layout_nearest_pos_to_xy(Layout_Item_List list, Vec2_f32 p){
for (Layout_Item_Block *block = list.first;
block != 0;
block = block->next){
i64 count = block->count;
i64 count = block->item_count;
Layout_Item *item = block->items;
for (i32 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
@ -939,7 +939,7 @@ buffer_layout_nearest_pos_to_xy(Layout_Item_List list, Vec2_f32 p){
for (Layout_Item_Block *block = list.first;
block != 0;
block = block->next){
i64 count = block->count;
i64 count = block->item_count;
Layout_Item *item = block->items;
for (i32 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
@ -971,48 +971,6 @@ buffer_layout_nearest_pos_to_xy(Layout_Item_List list, Vec2_f32 p){
return(closest_match);
}
internal i64
buffer_layout_get_pos_at_character(Layout_Item_List list, i64 character){
i64 result = 0;
if (character <= 0){
result = list.manifested_index_range.min;
}
else if (character >= list.character_count){
result = list.manifested_index_range.max;
}
else{
i64 counter = 0;
for (Layout_Item_Block *node = list.first;
node != 0;
node = node->next){
i64 next_counter = counter + node->character_count;
if (character < next_counter){
i64 count = node->count;
i64 relative_character = character - counter;
i64 relative_character_counter = 0;
i64 prev_index = -1;
Layout_Item *item = node->items;
for (i64 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
continue;
}
if (prev_index != item->index){
prev_index = item->index;
if (relative_character_counter == relative_character){
result = prev_index;
break;
}
relative_character_counter += 1;
}
}
break;
}
counter = next_counter;
}
}
return(result);
}
internal Layout_Item*
buffer_layout_get_first_with_index(Layout_Item_List list, i64 index){
Layout_Item *result = 0;
@ -1020,7 +978,7 @@ buffer_layout_get_first_with_index(Layout_Item_List list, i64 index){
for (Layout_Item_Block *block = list.first;
block != 0;
block = block->next){
i64 count = block->count;
i64 count = block->item_count;
Layout_Item *item = block->items;
for (i32 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
@ -1054,6 +1012,48 @@ buffer_layout_box_of_pos(Layout_Item_List list, i64 index){
return(result);
}
internal i64
buffer_layout_get_pos_at_character(Layout_Item_List list, i64 character){
i64 result = 0;
if (character <= 0){
result = list.manifested_index_range.min;
}
else if (character >= list.character_count){
result = list.manifested_index_range.max;
}
else{
i64 counter = 0;
i64 next_counter = 0;
for (Layout_Item_Block *node = list.first;
node != 0;
node = node->next, counter = next_counter){
next_counter = counter + node->character_count;
if (character >= next_counter){
continue;
}
i64 count = node->item_count;
i64 relative_character = character - counter;
i64 relative_character_counter = 0;
Layout_Item *item = node->items;
for (i64 i = 0; i < count; i += 1, item += 1){
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
continue;
}
if (relative_character_counter == relative_character){
result = item->index;
break;
}
relative_character_counter += 1;
}
break;
}
}
return(result);
}
internal i64
buffer_layout_character_from_pos(Layout_Item_List list, i64 index){
i64 result = 0;
@ -1069,7 +1069,7 @@ buffer_layout_character_from_pos(Layout_Item_List list, i64 index){
node != 0;
node = node->next){
Layout_Item *item = node->items;
i64 count = node->count;
i64 count = node->item_count;
for (i64 i = 0; i < count; i += 1, item += 1){
if (item->index >= index){
goto double_break;

View File

@ -107,7 +107,7 @@ text_layout_render(Thread_Context *tctx, Models *models, Text_Layout *layout){
block != 0;
block = block->next){
Layout_Item *item = block->items;
i64 count = block->count;
i64 count = block->item_count;
FColor *item_colors = layout->item_colors;
for (i32 i = 0; i < count; i += 1, item += 1){
if (item->codepoint != 0){

View File

@ -409,6 +409,11 @@ generic_parse_scope(Code_Index_File *index, Generic_Parse_State *state, i64 inde
continue;
}
if (token->kind == TokenBaseKind_ParentheticalClose){
generic_parse_inc(state);
continue;
}
{
Code_Index_Nest *nest = generic_parse_statement(index, state, indentation);
nest->parent = result;
@ -487,12 +492,6 @@ generic_parse_paren(Code_Index_File *index, Generic_Parse_State *state, i64 inde
break;
}
if (token->kind == TokenBaseKind_Preprocessor){
Code_Index_Nest *nest = generic_parse_preprocessor(index, state, indentation);
code_index_push_nest(&index->nest_list, nest);
continue;
}
if (token->kind == TokenBaseKind_ScopeOpen){
Code_Index_Nest *nest = generic_parse_scope(index, state, indentation);
nest->parent = result;
@ -575,8 +574,7 @@ default_comment_index(Application_Links *app, Arena *arena, Code_Index_File *ind
}
function void
generic_parse_init(Application_Links *app, Arena *arena, String_Const_u8 contents, Token_Array *tokens,
Generic_Parse_State *state){
generic_parse_init(Application_Links *app, Arena *arena, String_Const_u8 contents, Token_Array *tokens, Generic_Parse_State *state){
generic_parse_init(app, arena, contents, tokens, default_comment_index, state);
}

View File

@ -30,8 +30,8 @@ layout_write(Arena *arena, Layout_Item_List *list, i64 index, u32 codepoint, Lay
Layout_Item_Block *block = list->first;
if (block != 0){
if (block->items + block->count == item){
block->count += 1;
if (block->items + block->item_count == item){
block->item_count += 1;
}
else{
block = 0;
@ -44,17 +44,16 @@ layout_write(Arena *arena, Layout_Item_List *list, i64 index, u32 codepoint, Lay
sll_queue_push(list->first, list->last, block);
list->node_count += 1;
block->items = item;
block->count = 1;
block->item_count = 1;
}
list->total_count += 1;
list->item_count += 1;
if (index < list->manifested_index_range.min){
list->manifested_index_range.min = index;
}
if (index > list->manifested_index_range.max){
list->manifested_index_range.min = min(list->manifested_index_range.min, index);
list->manifested_index_range.max = max(list->manifested_index_range.max, index);
if (!HasFlag(flags, LayoutItemFlag_Ghost_Character)){
block->character_count += 1;
list->character_count += 1;
list->manifested_index_range.max = index;
}
item->index = index;
@ -186,17 +185,15 @@ lr_tb_write_byte_with_advance(LefRig_TopBot_Layout_Vars *vars, f32 advance, Aren
f32 text_y = vars->text_y;
Layout_Item_Flag flags = LayoutItemFlag_Special_Character;
layout_write(arena, list, index, '\\', flags,
Rf32(p, V2f32(next_x, text_y)));
layout_write(arena, list, index, '\\', flags, Rf32(p, V2f32(next_x, text_y)));
p.x = next_x;
flags = LayoutItemFlag_Ghost_Character;
next_x += metrics->byte_sub_advances[1];
layout_write(arena, list, index, integer_symbols[hi], flags,
Rf32(p, V2f32(next_x, text_y)));
layout_write(arena, list, index, integer_symbols[hi], flags, Rf32(p, V2f32(next_x, text_y)));
p.x = next_x;
next_x += metrics->byte_sub_advances[2];
layout_write(arena, list, index, integer_symbols[lo], flags,
Rf32(p, V2f32(next_x, text_y)));
layout_write(arena, list, index, integer_symbols[lo], flags, Rf32(p, V2f32(next_x, text_y)));
vars->p.x = final_next_x;
}

View File

@ -618,25 +618,23 @@ struct Layout_Item{
struct Layout_Item_Block{
Layout_Item_Block *next;
Layout_Item *items;
i64 count;
i64 item_count;
i64 character_count;
};
struct Layout_Item_List{
Layout_Item_Block *first;
Layout_Item_Block *last;
i64 item_count;
i64 character_count;
i32 node_count;
i32 total_count;
f32 height;
f32 bottom_padding;
i64 character_count;
Range_i64 input_index_range;
Range_i64 manifested_index_range;
};
typedef Layout_Item_List Layout_Function(Application_Links *app, Arena *arena,
Buffer_ID buffer, Range_i64 range,
Face_ID face, f32 width);
typedef Layout_Item_List Layout_Function(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 range, Face_ID face, f32 width);
typedef i64 Command_Map_ID;