From 7b97382f49399bdbfb57a223baee6dd31d323af6 Mon Sep 17 00:00:00 2001 From: DeaTh-G Date: Sun, 19 Jan 2025 01:09:19 +0100 Subject: [PATCH] improve annotated text line spacing --- UnleashedRecomp/ui/imgui_utils.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/UnleashedRecomp/ui/imgui_utils.cpp b/UnleashedRecomp/ui/imgui_utils.cpp index a64eb83f..1dbf3426 100644 --- a/UnleashedRecomp/ui/imgui_utils.cpp +++ b/UnleashedRecomp/ui/imgui_utils.cpp @@ -404,9 +404,16 @@ ImVec2 MeasureCentredParagraph(const ImFont* font, float fontSize, float lineMar /////////////////////////////////////////////////////////////////////// auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, annotationRemovedLine.c_str()); + auto annotationSize = font->CalcTextSizeA(fontSize * 0.6f, FLT_MAX, 0, ""); x = std::max(x, textSize.x); y += textSize.y + Scale(lineMargin); + + // TODO: This will case the text to account for annotation even if there's none included ever. This should not be the case. + if (&str != &lines.back()) + { + y += annotationSize.y; + } } return { x, y }; @@ -460,6 +467,7 @@ void DrawCentredParagraph(const ImFont* font, float fontSize, float maxWidth, co } auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, annotationRemovedLine.c_str()); + auto annotationSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, ""); auto textX = annotationRemovedLine.starts_with("- ") ? centre.x - paragraphSize.x / 2 @@ -468,11 +476,12 @@ void DrawCentredParagraph(const ImFont* font, float fontSize, float maxWidth, co for (const auto& segment : segments) { textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, segment.text.c_str()); + auto textY = centre.y - paragraphSize.y / 2 + offsetY; if (segment.annotated) { - auto annotationSize = font->CalcTextSizeA(fontSize * 0.6f, FLT_MAX, 0, segment.annotation.c_str()); + annotationSize = font->CalcTextSizeA(fontSize * 0.6f, FLT_MAX, 0, segment.annotation.c_str()); float annotationX = textX + (textSize.x - annotationSize.x) / 2.0f; @@ -483,7 +492,8 @@ void DrawCentredParagraph(const ImFont* font, float fontSize, float maxWidth, co textX += textSize.x; } - offsetY += textSize.y + Scale(lineMargin); + // TODO: This will case the text to account for annotation even if there's none included ever. This should not be the case. + offsetY += textSize.y + annotationSize.y + Scale(lineMargin); } }