From fee948b9c5702567eff551a6cf708d40cad3eade Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sun, 16 Jul 2023 08:06:44 +0900 Subject: [PATCH] Fix character panel label for CJK We fixed clipping in text rendering between 1.4 and 1.5. This surfaced a bug in the char panel label height. --- Source/panels/charpanel.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/panels/charpanel.cpp b/Source/panels/charpanel.cpp index 85bc44f56..79d5216bf 100644 --- a/Source/panels/charpanel.cpp +++ b/Source/panels/charpanel.cpp @@ -1,6 +1,8 @@ #include "panels/charpanel.hpp" #include + +#include #include #include @@ -236,8 +238,13 @@ void DrawShadowString(const Surface &out, const PanelEntry &entry) labelPosition += Displacement { -entry.labelLength - (IsSmallFontTall() ? 2 : 3), 0 }; } - DrawString(out, text, { labelPosition + Displacement { -2, 2 }, { entry.labelLength, PanelFieldHeight } }, style | UiFlags::ColorBlack, Spacing); - DrawString(out, text, { labelPosition, { entry.labelLength, PanelFieldHeight } }, style | UiFlags::ColorWhite, Spacing); + // If the text is less tall then the field, we center it vertically relative to the field. + // Otherwise, we draw from the top of the field. + const int textHeight = (std::count(wrapped.begin(), wrapped.end(), '\n') + 1) * GetLineHeight(wrapped, GameFont12); + const int labelHeight = std::max(PanelFieldHeight, textHeight); + + DrawString(out, text, { labelPosition + Displacement { -2, 2 }, { entry.labelLength, labelHeight } }, style | UiFlags::ColorBlack, Spacing); + DrawString(out, text, { labelPosition, { entry.labelLength, labelHeight } }, style | UiFlags::ColorWhite, Spacing); } void DrawStatButtons(const Surface &out)