Cleaning up layout types
This commit is contained in:
parent
c2f22de3ad
commit
5b9a29e215
|
@ -2938,14 +2938,15 @@ text_layout_character_on_screen(Application_Links *app, Text_Layout_ID layout_id
|
||||||
for (Layout_Item_Block *block = line.first;
|
for (Layout_Item_Block *block = line.first;
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
|
i64 count = block->item_count;
|
||||||
Layout_Item *item_ptr = block->items;
|
Layout_Item *item_ptr = block->items;
|
||||||
i64 count = block->count;
|
|
||||||
for (i32 i = 0; i < count; i += 1, item_ptr += 1){
|
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;
|
i64 index = item_ptr->index;
|
||||||
if (index == pos){
|
if (index == pos){
|
||||||
if (!HasFlag(item_ptr->flags, LayoutItemFlag_Ghost_Character)){
|
|
||||||
result = rect_union(result, item_ptr->rect);
|
result = rect_union(result, item_ptr->rect);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (index > pos){
|
else if (index > pos){
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -872,7 +872,7 @@ buffer_layout_nearest_pos_to_xy(Layout_Item_List list, Vec2_f32 p){
|
||||||
for (Layout_Item_Block *block = list.first;
|
for (Layout_Item_Block *block = list.first;
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
i64 count = block->count;
|
i64 count = block->item_count;
|
||||||
Layout_Item *item = block->items;
|
Layout_Item *item = block->items;
|
||||||
for (i32 i = 0; i < count; i += 1, item += 1){
|
for (i32 i = 0; i < count; i += 1, item += 1){
|
||||||
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
|
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;
|
for (Layout_Item_Block *block = list.first;
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
i64 count = block->count;
|
i64 count = block->item_count;
|
||||||
Layout_Item *item = block->items;
|
Layout_Item *item = block->items;
|
||||||
for (i32 i = 0; i < count; i += 1, item += 1){
|
for (i32 i = 0; i < count; i += 1, item += 1){
|
||||||
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
|
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;
|
for (Layout_Item_Block *block = list.first;
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
i64 count = block->count;
|
i64 count = block->item_count;
|
||||||
Layout_Item *item = block->items;
|
Layout_Item *item = block->items;
|
||||||
for (i32 i = 0; i < count; i += 1, item += 1){
|
for (i32 i = 0; i < count; i += 1, item += 1){
|
||||||
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
|
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);
|
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*
|
internal Layout_Item*
|
||||||
buffer_layout_get_first_with_index(Layout_Item_List list, i64 index){
|
buffer_layout_get_first_with_index(Layout_Item_List list, i64 index){
|
||||||
Layout_Item *result = 0;
|
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;
|
for (Layout_Item_Block *block = list.first;
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
i64 count = block->count;
|
i64 count = block->item_count;
|
||||||
Layout_Item *item = block->items;
|
Layout_Item *item = block->items;
|
||||||
for (i32 i = 0; i < count; i += 1, item += 1){
|
for (i32 i = 0; i < count; i += 1, item += 1){
|
||||||
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
|
if (HasFlag(item->flags, LayoutItemFlag_Ghost_Character)){
|
||||||
|
@ -1054,6 +1012,48 @@ buffer_layout_box_of_pos(Layout_Item_List list, i64 index){
|
||||||
return(result);
|
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
|
internal i64
|
||||||
buffer_layout_character_from_pos(Layout_Item_List list, i64 index){
|
buffer_layout_character_from_pos(Layout_Item_List list, i64 index){
|
||||||
i64 result = 0;
|
i64 result = 0;
|
||||||
|
@ -1069,7 +1069,7 @@ buffer_layout_character_from_pos(Layout_Item_List list, i64 index){
|
||||||
node != 0;
|
node != 0;
|
||||||
node = node->next){
|
node = node->next){
|
||||||
Layout_Item *item = node->items;
|
Layout_Item *item = node->items;
|
||||||
i64 count = node->count;
|
i64 count = node->item_count;
|
||||||
for (i64 i = 0; i < count; i += 1, item += 1){
|
for (i64 i = 0; i < count; i += 1, item += 1){
|
||||||
if (item->index >= index){
|
if (item->index >= index){
|
||||||
goto double_break;
|
goto double_break;
|
||||||
|
|
|
@ -107,7 +107,7 @@ text_layout_render(Thread_Context *tctx, Models *models, Text_Layout *layout){
|
||||||
block != 0;
|
block != 0;
|
||||||
block = block->next){
|
block = block->next){
|
||||||
Layout_Item *item = block->items;
|
Layout_Item *item = block->items;
|
||||||
i64 count = block->count;
|
i64 count = block->item_count;
|
||||||
FColor *item_colors = layout->item_colors;
|
FColor *item_colors = layout->item_colors;
|
||||||
for (i32 i = 0; i < count; i += 1, item += 1){
|
for (i32 i = 0; i < count; i += 1, item += 1){
|
||||||
if (item->codepoint != 0){
|
if (item->codepoint != 0){
|
||||||
|
|
|
@ -409,6 +409,11 @@ generic_parse_scope(Code_Index_File *index, Generic_Parse_State *state, i64 inde
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (token->kind == TokenBaseKind_ParentheticalClose){
|
||||||
|
generic_parse_inc(state);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Code_Index_Nest *nest = generic_parse_statement(index, state, indentation);
|
Code_Index_Nest *nest = generic_parse_statement(index, state, indentation);
|
||||||
nest->parent = result;
|
nest->parent = result;
|
||||||
|
@ -487,12 +492,6 @@ generic_parse_paren(Code_Index_File *index, Generic_Parse_State *state, i64 inde
|
||||||
break;
|
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){
|
if (token->kind == TokenBaseKind_ScopeOpen){
|
||||||
Code_Index_Nest *nest = generic_parse_scope(index, state, indentation);
|
Code_Index_Nest *nest = generic_parse_scope(index, state, indentation);
|
||||||
nest->parent = result;
|
nest->parent = result;
|
||||||
|
@ -575,8 +574,7 @@ default_comment_index(Application_Links *app, Arena *arena, Code_Index_File *ind
|
||||||
}
|
}
|
||||||
|
|
||||||
function void
|
function void
|
||||||
generic_parse_init(Application_Links *app, Arena *arena, String_Const_u8 contents, Token_Array *tokens,
|
generic_parse_init(Application_Links *app, Arena *arena, String_Const_u8 contents, Token_Array *tokens, Generic_Parse_State *state){
|
||||||
Generic_Parse_State *state){
|
|
||||||
generic_parse_init(app, arena, contents, tokens, default_comment_index, state);
|
generic_parse_init(app, arena, contents, tokens, default_comment_index, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ layout_write(Arena *arena, Layout_Item_List *list, i64 index, u32 codepoint, Lay
|
||||||
|
|
||||||
Layout_Item_Block *block = list->first;
|
Layout_Item_Block *block = list->first;
|
||||||
if (block != 0){
|
if (block != 0){
|
||||||
if (block->items + block->count == item){
|
if (block->items + block->item_count == item){
|
||||||
block->count += 1;
|
block->item_count += 1;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
block = 0;
|
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);
|
sll_queue_push(list->first, list->last, block);
|
||||||
list->node_count += 1;
|
list->node_count += 1;
|
||||||
block->items = item;
|
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 = min(list->manifested_index_range.min, index);
|
||||||
list->manifested_index_range.min = index;
|
list->manifested_index_range.max = max(list->manifested_index_range.max, index);
|
||||||
}
|
|
||||||
if (index > list->manifested_index_range.max){
|
if (!HasFlag(flags, LayoutItemFlag_Ghost_Character)){
|
||||||
block->character_count += 1;
|
block->character_count += 1;
|
||||||
list->character_count += 1;
|
list->character_count += 1;
|
||||||
list->manifested_index_range.max = index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item->index = 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;
|
f32 text_y = vars->text_y;
|
||||||
|
|
||||||
Layout_Item_Flag flags = LayoutItemFlag_Special_Character;
|
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;
|
p.x = next_x;
|
||||||
|
|
||||||
|
flags = LayoutItemFlag_Ghost_Character;
|
||||||
next_x += metrics->byte_sub_advances[1];
|
next_x += metrics->byte_sub_advances[1];
|
||||||
layout_write(arena, list, index, integer_symbols[hi], flags,
|
layout_write(arena, list, index, integer_symbols[hi], flags, Rf32(p, V2f32(next_x, text_y)));
|
||||||
Rf32(p, V2f32(next_x, text_y)));
|
|
||||||
p.x = next_x;
|
p.x = next_x;
|
||||||
next_x += metrics->byte_sub_advances[2];
|
next_x += metrics->byte_sub_advances[2];
|
||||||
layout_write(arena, list, index, integer_symbols[lo], flags,
|
layout_write(arena, list, index, integer_symbols[lo], flags, Rf32(p, V2f32(next_x, text_y)));
|
||||||
Rf32(p, V2f32(next_x, text_y)));
|
|
||||||
|
|
||||||
vars->p.x = final_next_x;
|
vars->p.x = final_next_x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,25 +618,23 @@ struct Layout_Item{
|
||||||
struct Layout_Item_Block{
|
struct Layout_Item_Block{
|
||||||
Layout_Item_Block *next;
|
Layout_Item_Block *next;
|
||||||
Layout_Item *items;
|
Layout_Item *items;
|
||||||
i64 count;
|
i64 item_count;
|
||||||
i64 character_count;
|
i64 character_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Layout_Item_List{
|
struct Layout_Item_List{
|
||||||
Layout_Item_Block *first;
|
Layout_Item_Block *first;
|
||||||
Layout_Item_Block *last;
|
Layout_Item_Block *last;
|
||||||
|
i64 item_count;
|
||||||
|
i64 character_count;
|
||||||
i32 node_count;
|
i32 node_count;
|
||||||
i32 total_count;
|
|
||||||
f32 height;
|
f32 height;
|
||||||
f32 bottom_padding;
|
f32 bottom_padding;
|
||||||
i64 character_count;
|
|
||||||
Range_i64 input_index_range;
|
Range_i64 input_index_range;
|
||||||
Range_i64 manifested_index_range;
|
Range_i64 manifested_index_range;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Layout_Item_List Layout_Function(Application_Links *app, Arena *arena,
|
typedef Layout_Item_List Layout_Function(Application_Links *app, Arena *arena, Buffer_ID buffer, Range_i64 range, Face_ID face, f32 width);
|
||||||
Buffer_ID buffer, Range_i64 range,
|
|
||||||
Face_ID face, f32 width);
|
|
||||||
|
|
||||||
typedef i64 Command_Map_ID;
|
typedef i64 Command_Map_ID;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue