Store syntax colors as 32-bit uints.

This commit is contained in:
Bartosz Taudul 2022-09-11 00:44:26 +02:00
parent f8cf7ff45a
commit c27bcc524c
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
3 changed files with 17 additions and 26 deletions

View File

@ -27,30 +27,17 @@ void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0
void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty ); void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty );
static constexpr const ImVec4 SyntaxColors[] = { static constexpr const uint32_t SyntaxColors[] = {
{ 0.7f, 0.7f, 0.7f, 1 }, // default 0xFFB2B2B2, // default
{ 0.45f, 0.68f, 0.32f, 1 }, // comment 0xFF51AD72, // comment
{ 0.72f, 0.37f, 0.12f, 1 }, // preprocessor 0xFF1E5EB7, // preprocessor
{ 0.64f, 0.64f, 1, 1 }, // string 0xFFFFA3A3, // string
{ 0.64f, 0.82f, 1, 1 }, // char literal 0xFFFFD1A3, // char literal
{ 1, 0.91f, 0.53f, 1 }, // keyword 0xFF87E8FF, // keyword
{ 0.81f, 0.6f, 0.91f, 1 }, // number 0xFFE899CE, // number
{ 0.9f, 0.9f, 0.9f, 1 }, // punctuation 0xFFE5E5E5, // punctuation
{ 0.78f, 0.46f, 0.75f, 1 }, // type 0xFFBF75C6, // type
{ 0.21f, 0.69f, 0.89f, 1 }, // special 0xFFE2AF35, // special
};
static constexpr const ImVec4 SyntaxColorsDimmed[] = {
{ 0.7f, 0.7f, 0.7f, 0.6f }, // default
{ 0.45f, 0.68f, 0.32f, 0.6f }, // comment
{ 0.72f, 0.37f, 0.12f, 0.6f }, // preprocessor
{ 0.64f, 0.64f, 1, 0.6f }, // string
{ 0.64f, 0.82f, 1, 0.6f }, // char literal
{ 1, 0.91f, 0.53f, 0.6f }, // keyword
{ 0.81f, 0.6f, 0.91f, 0.6f }, // number
{ 0.9f, 0.9f, 0.9f, 0.6f }, // punctuation
{ 0.78f, 0.46f, 0.75f, 0.6f }, // type
{ 0.21f, 0.69f, 0.89f, 0.6f }, // special
}; };

View File

@ -209,7 +209,9 @@ static void PrintSourceFragment( const SourceContents& src, uint32_t srcline, in
ImGui::TextUnformatted( ptr, it->begin ); ImGui::TextUnformatted( ptr, it->begin );
ImGui::SameLine( 0, 0 ); ImGui::SameLine( 0, 0 );
} }
TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end ); auto color = SyntaxColors[(int)it->color];
if( i != srcline-1 ) color = ( color & 0xFFFFFF ) | 0x99000000;
TextColoredUnformatted( color, it->begin, it->end );
ImGui::SameLine( 0, 0 ); ImGui::SameLine( 0, 0 );
ptr = it->end; ptr = it->end;
++it; ++it;

View File

@ -1247,7 +1247,9 @@ void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before
ImGui::TextUnformatted( ptr, it->begin ); ImGui::TextUnformatted( ptr, it->begin );
ImGui::SameLine( 0, 0 ); ImGui::SameLine( 0, 0 );
} }
TextColoredUnformatted( i == srcline-1 ? SyntaxColors[(int)it->color] : SyntaxColorsDimmed[(int)it->color], it->begin, it->end ); auto color = SyntaxColors[(int)it->color];
if( i != srcline-1 ) color = ( color & 0xFFFFFF ) | 0x99000000;
TextColoredUnformatted( color, it->begin, it->end );
ImGui::SameLine( 0, 0 ); ImGui::SameLine( 0, 0 );
ptr = it->end; ptr = it->end;
++it; ++it;