mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-27 21:01:37 +00:00
DrawCentredParagraph: fix line centring breaking at unequal lengths
This commit is contained in:
parent
39b0aeb2dc
commit
adb9bedfa1
1 changed files with 6 additions and 17 deletions
|
|
@ -369,29 +369,18 @@ inline void DrawCentredParagraph(const ImFont* font, float fontSize, float maxWi
|
||||||
auto paragraphSize = MeasureCentredParagraph(font, fontSize, lineMargin, lines);
|
auto paragraphSize = MeasureCentredParagraph(font, fontSize, lineMargin, lines);
|
||||||
auto offsetY = 0.0f;
|
auto offsetY = 0.0f;
|
||||||
|
|
||||||
auto hasList = std::strstr(text, "- ");
|
|
||||||
auto isList = false;
|
|
||||||
auto listOffsetX = 0.0f;
|
|
||||||
|
|
||||||
for (int i = 0; i < lines.size(); i++)
|
for (int i = 0; i < lines.size(); i++)
|
||||||
{
|
{
|
||||||
auto& str = lines[i];
|
auto& str = lines[i];
|
||||||
auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, str.c_str());
|
auto textSize = font->CalcTextSizeA(fontSize, FLT_MAX, 0, str.c_str());
|
||||||
|
|
||||||
if (hasList)
|
auto textX = str.starts_with("- ")
|
||||||
{
|
? centre.x - paragraphSize.x / 2
|
||||||
if (!isList && str.starts_with("- ") && lines.size() > i + 1 && lines[i + 1].starts_with("- "))
|
: centre.x - textSize.x / 2;
|
||||||
{
|
|
||||||
isList = true;
|
|
||||||
listOffsetX = centre.x - textSize.x / 2;
|
|
||||||
}
|
|
||||||
else if (isList && !str.starts_with("- "))
|
|
||||||
{
|
|
||||||
isList = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
drawMethod(str.c_str(), ImVec2(/* X */ isList ? listOffsetX : centre.x - textSize.x / 2, /* Y */ centre.y - paragraphSize.y / 2 + offsetY));
|
auto textY = centre.y - paragraphSize.y / 2 + offsetY;
|
||||||
|
|
||||||
|
drawMethod(str.c_str(), { textX, textY });
|
||||||
|
|
||||||
offsetY += textSize.y + Scale(lineMargin);
|
offsetY += textSize.y + Scale(lineMargin);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue