Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap lines after - #250

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading