From 8a2a4506866c25c2935225950f154a901c536f1e Mon Sep 17 00:00:00 2001 From: Vantha Date: Tue, 3 Mar 2026 17:03:29 +0100 Subject: [PATCH] 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. --- .../data/mods/mod/gui/common/modern/styles.xml | 2 +- binaries/data/mods/mod/gui/modmod/styles.xml | 2 +- .../data/mods/public/gui/common/styles.xml | 2 +- source/gui/ObjectTypes/CText.cpp | 18 +++++++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/binaries/data/mods/mod/gui/common/modern/styles.xml b/binaries/data/mods/mod/gui/common/modern/styles.xml index 4f8e896fff..0aacbfca75 100644 --- a/binaries/data/mods/mod/gui/common/modern/styles.xml +++ b/binaries/data/mods/mod/gui/common/modern/styles.xml @@ -131,7 +131,7 @@ scrollbar_style="ModernScrollBar" textcolor="white" text_align="left" - text_valign="center" + text_valign="top" sprite="ModernDarkBox" sprite_overlay="ModernDarkBoxGoldBorder" /> diff --git a/binaries/data/mods/mod/gui/modmod/styles.xml b/binaries/data/mods/mod/gui/modmod/styles.xml index d773ff5d68..4d249bcfde 100644 --- a/binaries/data/mods/mod/gui/modmod/styles.xml +++ b/binaries/data/mods/mod/gui/modmod/styles.xml @@ -9,6 +9,6 @@ scroll_bottom="true" textcolor="white" text_align="left" - text_valign="center" + text_valign="top" /> diff --git a/binaries/data/mods/public/gui/common/styles.xml b/binaries/data/mods/public/gui/common/styles.xml index 8230b69019..49b6177df7 100644 --- a/binaries/data/mods/public/gui/common/styles.xml +++ b/binaries/data/mods/public/gui/common/styles.xml @@ -135,7 +135,7 @@ scroll_bottom="true" textcolor="white" text_align="left" - text_valign="center" + text_valign="top" sprite="ModernDarkBox" sprite_overlay="ModernDarkBoxGoldBorder" /> diff --git a/source/gui/ObjectTypes/CText.cpp b/source/gui/ObjectTypes/CText.cpp index 44ef49f85a..0a6834c49d 100644 --- a/source/gui/ObjectTypes/CText.cpp +++ b/source/gui/ObjectTypes/CText.cpp @@ -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); }