Add ImGui::SameLine() capable wrapped text printing function.

Adapted from imgui_markdown.
This commit is contained in:
Bartosz Taudul
2025-05-19 02:26:40 +02:00
parent bc7f365793
commit d5f732e768
2 changed files with 21 additions and 0 deletions

View File

@@ -127,4 +127,24 @@ void PrintSource( const std::vector<Tokenizer::Line>& lines )
}
}
void PrintTextWrapped( const char* text, const char* end )
{
if( !end ) end = text + strlen( text );
auto scale = ImGui::GetIO().FontGlobalScale;
auto left = ImGui::GetContentRegionAvail().x;
auto endLine = ImGui::GetFont()->CalcWordWrapPositionA( scale, text, end, left );
ImGui::TextUnformatted( text, endLine );
left = ImGui::GetContentRegionAvail().x;
while( endLine < end )
{
text = endLine;
if( *text == ' ' ) text++;
endLine = ImGui::GetFont()->CalcWordWrapPositionA( scale, text, end, left );
if( text == endLine ) endLine++;
ImGui::TextUnformatted( text, endLine );
}
}
}

View File

@@ -32,6 +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 );
void PrintTextWrapped( const char* text, const char* end = nullptr );
static constexpr const uint32_t SyntaxColors[] = {