Token coloring in immediate mode

master
Allen Webster 2019-09-28 16:45:50 -07:00
parent c254ca750f
commit 9ad2de95c2
2 changed files with 56 additions and 40 deletions

View File

@ -327,6 +327,42 @@ GET_VIEW_BUFFER_REGION_SIG(default_view_buffer_region){
return(sub_region); return(sub_region);
} }
internal int_color
get_token_color(Token token){
int_color result = Stag_Default;
if (HasFlag(token.flags, TokenBaseFlag_PreprocessorBody)){
result = Stag_Preproc;
}
else{
switch (token.kind){
case TokenBaseKind_Keyword:
{
// TODO(allen): beta: Stag_Bool_Constant
result = Stag_Keyword;
}break;
case TokenBaseKind_Comment:
{
result = Stag_Comment;
}break;
case TokenBaseKind_LiteralString:
{
result = Stag_Str_Constant;
// TODO(allen): beta: Stag_Char_Constant
// TODO(allen): beta: Stag_Include
}break;
case TokenBaseKind_LiteralInteger:
{
result = Stag_Int_Constant;
}break;
case TokenBaseKind_LiteralFloat:
{
result = Stag_Float_Constant;
}break;
}
}
return(result);
}
internal void internal void
default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id, Rect_f32 view_inner_rect){ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View_ID view_id, Rect_f32 view_inner_rect){
Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll); Buffer_ID buffer = view_get_buffer(app, view_id, AccessAll);
@ -352,6 +388,26 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Scratch_Block scratch(app); Scratch_Block scratch(app);
// NOTE(allen): Token colorizing
Token_Array token_array = get_token_array_from_buffer(app, buffer);
if (token_array.tokens != 0){
i64 first_index = token_index_from_pos(&token_array, visible_range.first);
Token_Iterator_Array it = token_iterator_index(buffer, &token_array, first_index);
for (;;){
Token *token = token_it_read(&it);
if (token->pos >= visible_range.one_past_last){
break;
}
int_color color = get_token_color(*token);
paint_text_color(app, text_layout_id, Ii64(token->pos, token->pos + token->size), color);
if (!token_it_inc_non_whitespace(&it)){
break;
}
}
}
// NOTE(allen): Scan for TODOs and NOTEs // NOTE(allen): Scan for TODOs and NOTEs
{ {
Temp_Memory temp = begin_temp(scratch); Temp_Memory temp = begin_temp(scratch);

View File

@ -464,46 +464,6 @@ finalize_color(Color_Table color_table, int_color color){
return(color_argb); return(color_argb);
} }
internal u32
get_token_color(Color_Table color_table, Token token){
u32 result = 0;
if (HasFlag(token.flags, TokenBaseFlag_PreprocessorBody)){
result = color_table.vals[Stag_Preproc];
}
else{
switch (token.kind){
case TokenBaseKind_Keyword:
{
// TODO(allen): beta: Stag_Bool_Constant
result = color_table.vals[Stag_Keyword];
}break;
case TokenBaseKind_Comment:
{
result = color_table.vals[Stag_Comment];
}break;
case TokenBaseKind_LiteralString:
{
result = color_table.vals[Stag_Str_Constant];
// TODO(allen): beta: Stag_Char_Constant
// TODO(allen): beta: Stag_Include
}break;
case TokenBaseKind_LiteralInteger:
{
result = color_table.vals[Stag_Int_Constant];
}break;
case TokenBaseKind_LiteralFloat:
{
result = color_table.vals[Stag_Float_Constant];
}break;
default:
{
result = color_table.vals[Stag_Default];
}break;
}
}
return(result);
}
internal void internal void
view_quit_ui(System_Functions *system, Models *models, View *view){ view_quit_ui(System_Functions *system, Models *models, View *view){
Assert(view != 0); Assert(view != 0);