Stanzilla / WoWUIBugs

World of Warcraft UI Bug Tracker
153 stars 7 forks source link

ScrollingFontTemplate can desynchronize its scrollable extent from the fontstring height #450

Closed Meorawr closed 11 months ago

Meorawr commented 1 year ago

ScrollingFontTemplate doesn't keep the height of the font string container child frame synchronized with the height of the font string text region itself when the frame is either resized or has its font replaced, leading to scenarios where the scrollbox may either have large amounts of blank space surrounding the text or may alternatively clip the text on both ends.

Test case

A test case addon is provided here: Meorawr_ScrollingFontExtentBug.zip

When loaded the addon will create a panel in the centre of the screen with two scrolling font views. The one on the left is the unmodified (default) ScrollingFontTemplate, and the one on the right has a mixin applied which overrides the OnSizeChanged and SetFontObject methods to demonstrate a fix for this issue.

Both font views include debug texture backgrounds - a half-alpha red background is anchored to the FontStringContainer child, and a half-alpha blue background to the FontString itself. When both these child regions overlap you'll get a purple background. The expectation is that you'll mostly only ever see a purple background, indicating both child regions have matching dimensions.

A video demonstrating the issue when resizing can be seen below.

  1. When the test panel is resized such that the text no longer wraps onto two lines, the view on the left doesn't update the height of the container to accommodate the now-smaller fontstring child - as such the red background becomes visible and the scrollable extent end up being too large for the text content, leading to a large blank space before and after the text.
  2. When the text panel is shrunk such that the text wraps to three lines, the view on the left doesn't update the height of the container to accommodate the now-larger fontstring child - as such the blue background becomes visible and the scrollable extent ends up being too small for the text content, leading to clipping of the text.

https://github.com/Stanzilla/WoWUIBugs/assets/287102/97c6f0ae-b0db-49a5-889e-7b27d2ea6a83

Additionally, when toggling font size the same issue can be observed in the video below - when the font size is increased the fontstring height increases, but the container doesn't track that and as such ends up with the same clipping issue seen in the previous video.

https://github.com/Stanzilla/WoWUIBugs/assets/287102/fd0f7740-d322-4ea6-91f1-aaed454201ec

Solution

The OnSizeChanged and SetFontObject methods of ScrollingFontMixin should update the height of the container to match the string height of the fontstring.

diff --git a/Interface/SharedXML/Scroll/ScrollTemplates.lua b/Interface/SharedXML/Scroll/ScrollTemplates.lua
index 9475ec30..134f6121 100644
--- a/Interface/SharedXML/Scroll/ScrollTemplates.lua
+++ b/Interface/SharedXML/Scroll/ScrollTemplates.lua
@@ -261,11 +261,12 @@ function ScrollingFontMixin:OnSizeChanged(width, height)
    local scrollBox = self:GetScrollBox();
    scrollBox:SetWidth(width);

-   local fontStringContainer = self:GetFontStringContainer();
-   fontStringContainer:SetWidth(width);
-
    local fontString = self:GetFontString();
    fontString:SetWidth(width);
+
+   local fontStringContainer = self:GetFontStringContainer();
+   fontStringContainer:SetWidth(width);
+   fontStringContainer:SetHeight(fontString:GetStringHeight());
 end

 function ScrollingFontMixin:GetScrollBox()
@@ -317,6 +318,9 @@ end
 function ScrollingFontMixin:SetFontObject(fontName)
    local fontString = self:GetFontString();
    fontString:SetFontObject(fontName);
+
+   local fontStringContainer = self:GetFontStringContainer();
+   fontStringContainer:SetHeight(fontString:GetStringHeight());

    local scrollBox = self:GetScrollBox();
    local fontHeight = select(2, fontString:GetFont());
Meorawr commented 11 months ago

Fixed in 10.1.7.50442; will probably make its way to Classic for 3.4.3/1.15.0.