From 9d2099457af4e17a5d4d721c34ef8477c587eb6b Mon Sep 17 00:00:00 2001 From: aBlueShadow Date: Mon, 16 Sep 2024 09:23:29 +0200 Subject: [PATCH] Wrap lines after - --- src/graphics/font.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/graphics/font.cpp b/src/graphics/font.cpp index ac8148c3..607d69da 100644 --- a/src/graphics/font.cpp +++ b/src/graphics/font.cpp @@ -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(result.data.size())-2; (n > 0) && (result.data[n].char_code != 0); n--) { if (result.data[n].char_code == ' ') @@ -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)