Underline links.

This commit is contained in:
Bartosz Taudul
2026-01-24 14:23:15 +01:00
parent 7c54c824ab
commit cdec805cc9
3 changed files with 14 additions and 10 deletions

View File

@@ -128,7 +128,7 @@ void PrintSource( const std::vector<Tokenizer::Line>& lines )
}
}
bool PrintTextWrapped( const char* text, const char* end, bool strikethrough )
bool PrintTextWrapped( const char* text, const char* end, bool strikethrough, bool underline )
{
bool hovered = false;
if( !end ) end = text + strlen( text );
@@ -152,15 +152,17 @@ bool PrintTextWrapped( const char* text, const char* end, bool strikethrough )
}
auto endLine = ImGui::GetFont()->CalcWordWrapPosition( fontSize, text, end, left );
if( strikethrough )
if( strikethrough || underline )
{
auto y = ImGui::GetCursorScreenPos().y + fontSize05;
auto y1 = ImGui::GetCursorScreenPos().y + fontSize05;
auto y2 = ImGui::GetCursorScreenPos().y + fontSize;
auto x0 = ImGui::GetCursorScreenPos().x - scale;
ImGui::TextUnformatted( text, endLine );
ImGui::SameLine( 0, 0 );
auto x1 = ImGui::GetCursorScreenPos().x + scale;
ImGui::NewLine();
ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y ), ImVec2( x1, y ), color, scale );
if( strikethrough ) ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y1 ), ImVec2( x1, y1 ), color, scale );
if( underline ) ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y2 ), ImVec2( x1, y2 ), color, scale );
}
else
{
@@ -175,15 +177,17 @@ bool PrintTextWrapped( const char* text, const char* end, bool strikethrough )
if( *text == ' ' ) text++;
endLine = ImGui::GetFont()->CalcWordWrapPosition( fontSize, text, end, left );
if( text == endLine ) endLine++;
if( strikethrough )
if( strikethrough || underline )
{
auto y = ImGui::GetCursorScreenPos().y + fontSize05;
auto y1 = ImGui::GetCursorScreenPos().y + fontSize05;
auto y2 = ImGui::GetCursorScreenPos().y + fontSize;
auto x0 = ImGui::GetCursorScreenPos().x - scale;
ImGui::TextUnformatted( text, endLine );
ImGui::SameLine( 0, 0 );
auto x1 = ImGui::GetCursorScreenPos().x + scale;
ImGui::NewLine();
ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y ), ImVec2( x1, y ), color, scale );
if( strikethrough ) ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y1 ), ImVec2( x1, y1 ), color, scale );
if( underline ) ImGui::GetWindowDrawList()->AddLine( ImVec2( x0, y2 ), ImVec2( x1, y2 ), color, scale );
}
else
{

View File

@@ -32,7 +32,7 @@ void DrawZigZag( ImDrawList* draw, const ImVec2& wpos, double start, double end,
void DrawStripedRect( ImDrawList* draw, const ImVec2& wpos, double x0, double y0, double x1, double y1, double sw, uint32_t color, bool fix_stripes_in_screen_space, bool inverted );
void DrawHistogramMinMaxLabel( ImDrawList* draw, int64_t tmin, int64_t tmax, ImVec2 wpos, float w, float ty );
void PrintSource( const std::vector<Tokenizer::Line>& lines );
bool PrintTextWrapped( const char* text, const char* end, bool strikethrough );
bool PrintTextWrapped( const char* text, const char* end, bool strikethrough, bool underline );
static constexpr const uint32_t SyntaxColors[] = {

View File

@@ -348,7 +348,7 @@ private:
if( !end ) end = text + strlen( text );
auto pos = (const char*)memmem( text, end - text, "\xe2\x80\xaf", 3 );
if( !pos ) return PrintTextWrapped( text, end, strikethrough );
if( !pos ) return PrintTextWrapped( text, end, strikethrough, !link.empty() );
// Replace narrow no-break space with no-break space
std::string buf( text, end );
@@ -361,7 +361,7 @@ private:
text = buf.c_str();
end = text + buf.size();
return PrintTextWrapped( text, end, strikethrough );
return PrintTextWrapped( text, end, strikethrough, !link.empty() );
}
int bold = 0;