text renderer: colors layout fix + improved tests

1. Fixes DrawStringwithColors kerning fit handling and newline handling.
2. Splits tests into one file per function call, making it easier to compare diffs and add new tests.
    Also adds `--update_expected` argument to update the expected files with actual results.
This commit is contained in:
Gleb Mazovetskiy
2025-03-03 02:47:28 +09:00
parent 4f151c7e24
commit 5a14cc57f3
18 changed files with 332 additions and 122 deletions
+5 -4
View File
@@ -6,6 +6,7 @@
#include "plrmsg.h"
#include <algorithm>
#include <array>
#include <cstdint>
#include <fmt/format.h>
@@ -123,11 +124,11 @@ void DrawPlrMsg(const Surface &out)
DrawHalfTransparentRectTo(out, x - 3, y, width + 6, message.lineHeight * chatlines);
std::vector<DrawStringFormatArg> args {
{ std::string_view(text.data(), message.prefixLength), UiFlags::ColorWhitegold },
{ std::string_view(text.data() + message.prefixLength, text.size() - message.prefixLength), message.style }
std::array<DrawStringFormatArg, 2> args {
DrawStringFormatArg { std::string_view(text.data(), message.prefixLength), UiFlags::ColorWhitegold },
DrawStringFormatArg { std::string_view(text.data() + message.prefixLength, text.size() - message.prefixLength), message.style }
};
DrawStringWithColors(out, "{:s}{:s}", args, { { x, y }, { width, 0 } },
DrawStringWithColors(out, "{:s}{:s}", args.data(), args.size(), { { x, y }, { width, 0 } },
{ .flags = UiFlags::None, .lineHeight = message.lineHeight });
}
}