fix chat line wrapping

This commit is contained in:
qndel 2021-09-12 11:28:56 +02:00 committed by Anders Jenbo
commit 1f61b683a6

View file

@ -171,6 +171,7 @@ uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect,
else if (HasAnyOf(flags, UiFlags::AlignRight))
characterPosition.x += rect.size.width - lineWidth;
int rightMargin = rect.position.x + rect.size.width;
int bottomMargin = rect.size.height != 0 ? rect.position.y + rect.size.height : out.h();
if (lineHeight == -1)
@ -195,7 +196,7 @@ uint32_t DrawString(const Surface &out, string_view text, const Rectangle &rect,
uint32_t i = 0;
for (; i < text.length(); i++) {
uint8_t frame = text[i] & 0xFF;
if (text[i] == '\n') {
if (text[i] == '\n' || characterPosition.x > rightMargin) {
if (characterPosition.y + lineHeight >= bottomMargin)
break;
characterPosition.y += lineHeight;