Align text as usual if the scrollbar is invisible

Previously, while `scrollbar` was set to true, the text was always
vertically aligned to the top, no matter what its `text_valign` was, by
the scrolling logic. However, this was done even when the text's caption
was so short that no scrollbar was required in the first place (and not
rendered). Falling back to the specified `text_valign` value in that case
instead seems like the expected behavior.

On a few occasions in the GUI, the text was supposed to be aligned to
the top in either case, but still set `text_valign` to a different value
(for whatever reason), which didn't have any effect previously. But
now since it does, the values have to be corrected to specify what is
actually desired.
This commit is contained in:
Vantha 2026-03-03 17:03:29 +01:00
parent 15cabcf8fc
commit 8a2a450686
4 changed files with 12 additions and 12 deletions

View file

@ -131,7 +131,7 @@
scrollbar_style="ModernScrollBar"
textcolor="white"
text_align="left"
text_valign="center"
text_valign="top"
sprite="ModernDarkBox"
sprite_overlay="ModernDarkBoxGoldBorder"
/>

View file

@ -9,6 +9,6 @@
scroll_bottom="true"
textcolor="white"
text_align="left"
text_valign="center"
text_valign="top"
/>
</styles>

View file

@ -135,7 +135,7 @@
scroll_bottom="true"
textcolor="white"
text_align="left"
text_valign="center"
text_valign="top"
sprite="ModernDarkBox"
sprite_overlay="ModernDarkBoxGoldBorder"
/>

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -71,9 +71,6 @@ void CText::SetupText()
m_GeneratedTexts[0] = CGUIText(m_pGUI, m_Caption, m_Font, width, m_BufferZone, m_TextAlign, this);
if (!m_ScrollBar)
CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]);
// Setup scrollbar
if (m_ScrollBar)
{
@ -99,6 +96,9 @@ void CText::SetupText()
if (m_ScrollTop)
GetScrollBar(0).SetPos(0.0f);
}
if (!m_ScrollBar || !std::ranges::any_of(m_ScrollBars, &IGUIScrollBar::IsVisible))
CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]);
}
void CText::ResetStates()
@ -204,15 +204,15 @@ void CText::Draw(CCanvas2D& canvas)
const CGUIColor& color = m_Enabled ? m_TextColor : m_TextColorDisabled;
if (m_ScrollBar)
if (m_ScrollBar && std::ranges::any_of(m_ScrollBars, &IGUIScrollBar::IsVisible))
{
DrawText(canvas, 0, color, m_CachedActualSize.TopLeft() - CVector2D(0.f, scroll), cliparea);
// Draw scrollbars on top of the content
IGUIScrollBarOwner::Draw(canvas);
}
else
DrawText(canvas, 0, color, m_TextPos, cliparea);
// Draw scrollbars on top of the content
if (m_ScrollBar)
IGUIScrollBarOwner::Draw(canvas);
// Draw the overlays last
m_pGUI.DrawSprite(m_SpriteOverlay, canvas, m_CachedActualSize, m_VisibleArea);
}