diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextSizing.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextSizing.cs new file mode 100644 index 0000000000..2c0830e87d --- /dev/null +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextSizing.cs @@ -0,0 +1,33 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Framework.Graphics.Sprites; + +namespace osu.Framework.Tests.Visual.Sprites +{ + public class TestSceneSpriteTextSizing : FrameworkTestScene + { + [Test] + public void TestNewSizeImmediatelyAvailableAfterTextChange() + { + SpriteText text = null!; + float initialSize = 0; + + AddStep("add initial text and get size", () => + { + Child = text = new SpriteText { Text = "First" }; + initialSize = text.DrawWidth; + }); + + float updatedSize = 0; + AddStep("set new text and grab size", () => + { + text.Text = "Second"; + updatedSize = text.DrawWidth; + }); + + AddAssert("updated size is not equal to the initial size", () => updatedSize, () => Is.Not.EqualTo(initialSize)); + } + } +} diff --git a/osu.Framework/Graphics/Sprites/SpriteText.cs b/osu.Framework/Graphics/Sprites/SpriteText.cs index 88e4bf2bd6..4c7d9d442f 100644 --- a/osu.Framework/Graphics/Sprites/SpriteText.cs +++ b/osu.Framework/Graphics/Sprites/SpriteText.cs @@ -557,7 +557,7 @@ private void invalidate(bool characters = false, bool textBuilder = false) parentScreenSpaceCache.Invalidate(); localScreenSpaceCache.Invalidate(); - Invalidate(Invalidation.DrawNode); + Invalidate(Invalidation.RequiredParentSizeToFit); } #endregion