Skip to content

Commit

Permalink
Wrap lines after -
Browse files Browse the repository at this point in the history
  • Loading branch information
aBlueShadow authored Sep 16, 2024
1 parent c78418a commit 9d20994
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/graphics/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Font::PreparedFontString Font::prepare(std::string_view s, int pixel_size, float
position.x += glyph.advance * size_scale;
if ((flags & FlagLineWrap) && position.x > area_size.x)
{
//Try to wrap the line by going back to the last space character and replace that with a newline.
//Try to wrap the line by going back to the last space character and replace that with a newline. If a '-' is found first, keep it and just add a newline.
for(int n=static_cast<int>(result.data.size())-2; (n > 0) && (result.data[n].char_code != 0); n--)
{
if (result.data[n].char_code == ' ')
Expand All @@ -80,6 +80,16 @@ Font::PreparedFontString Font::prepare(std::string_view s, int pixel_size, float
position.y += line_spacing;
break;
}
if (result.data[n].char_code == '-')
{
index = result.data[n + 1].string_offset;
result.data.resize(n + 1);
result.data.push_back(result.data.back());
result.data.back().char_code = 0;
position.x = 0.0f;
position.y += line_spacing;
break;
}
}

if (result.lastLineCharacterCount() > 1)
Expand Down

0 comments on commit 9d20994

Please sign in to comment.