Skip to content

Fix daily challenge marker text spacing #32909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2025

Conversation

bdach
Copy link
Collaborator

@bdach bdach commented Apr 22, 2025

Closes #32908.

Have you ever been in a situation wherein you find out you fixed a bug that you didn't know existed, but that makes another bug appear because it was relying on the other bug? This is where I'm at right now.

But, to start from the top.

TextFlowContainer.Text (the setter) is a convenience property that you use to set the text in one go. Internally it uses AddText().

AddText()'s xmldoc says:

The \n character will create a new paragraph, not just a line break.
If you need \n to be a line break, use <see cref="AddParagraph{TSpriteText}(LocalisableString, Action{TSpriteText})"/> instead.

That's right. This portion of xmldoc was straight up false and silently broken before ppy/osu-framework#6556. If you want to check that out yourself, apply the following patch to framework:

diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
index 464f47c2c..e1ad521a7 100644
--- a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
+++ b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
@@ -180,6 +180,22 @@ public void TestAlignmentIsCorrectWhenLineBreaksAtLastWordOfParagraph(Anchor tex
             });
         }
 
+        [Test]
+        public void TestSetTextWithNewLine()
+        {
+            AddStep("set text", () => textContainer.Text = "this text\nhas a newline");
+            AddStep("clear and add text", () =>
+            {
+                textContainer.Clear();
+                textContainer.AddText("this text\nhas a newline");
+            });
+            AddStep("clear and add paragraph", () =>
+            {
+                textContainer.Clear();
+                textContainer.AddParagraph("this text\nhas a newline");
+            });
+        }
+
         private void assertSpriteTextCount(int count)
             => AddAssert($"text flow has {count} sprite texts", () => textContainer.ChildrenOfType<SpriteText>().Count() == count);
 

On master, there will be a difference between the first two steps, and the third. On 2025.321.0, there will be none.

My working theory as to why this was always busted is that the corresponding code that was there before just straight up ran too late. The height of the container is being changed after the flow has laid itself out, without adjusting subsequent children in any way.

There is potentially a discussion to be had as to whether the emergent behaviour of TextFlowContainer.Text with respect to \n character is correct, but I'm just going to start with this diff and see what the reaction is.

Closes ppy#32908.

Have you ever been in a situation wherein you find out you fixed a bug
that you didn't know existed, but that makes *another* bug appear
because it was relying on the other bug? This is where I'm at right now.

But, to start from the top.

`TextFlowContainer.Text` (the setter) is a convenience property that you
use to set the text in one go. Internally it uses `AddText()`:

	https://github.com/ppy/osu-framework/blob/681900ffb70adfeede4e3fa32a69da66252691ee/osu.Framework/Graphics/Containers/TextFlowContainer.cs#L81-L94

`AddText()`'s xmldoc says:

	The \n character will create a new paragraph, not just a line break.
	If you need \n to be a line break, use <see cref="AddParagraph{TSpriteText}(LocalisableString, Action{TSpriteText})"/> instead.

	https://github.com/ppy/osu-framework/blob/681900ffb70adfeede4e3fa32a69da66252691ee/osu.Framework/Graphics/Containers/TextFlowContainer.cs#L226-L239

That's right. This portion of xmldoc was *straight up false* and
*silently broken* before ppy/osu-framework#6556.
If you want to check that out yourself, apply the following patch to
framework:

diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
index 464f47c2c..e1ad521a7 100644
--- a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
+++ b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs
@@ -180,6 +180,22 @@ public void TestAlignmentIsCorrectWhenLineBreaksAtLastWordOfParagraph(Anchor tex
             });
         }

+        [Test]
+        public void TestSetTextWithNewLine()
+        {
+            AddStep("set text", () => textContainer.Text = "this text\nhas a newline");
+            AddStep("clear and add text", () =>
+            {
+                textContainer.Clear();
+                textContainer.AddText("this text\nhas a newline");
+            });
+            AddStep("clear and add paragraph", () =>
+            {
+                textContainer.Clear();
+                textContainer.AddParagraph("this text\nhas a newline");
+            });
+        }
+
         private void assertSpriteTextCount(int count)
             => AddAssert($"text flow has {count} sprite texts", () => textContainer.ChildrenOfType<SpriteText>().Count() == count);

On `master`, there will be a difference between the first two steps, and
the third. On 2025.321.0, *there will be none*.

My working theory as to why this was always busted is that the
corresponding code that was there before in

	https://github.com/bdach/osu-framework/blob/c31a48178889ca2f9b4d257d2d64915eee90338a/osu.Framework/Graphics/Containers/TextFlowContainer.cs#L454-L458

just straight up ran too late. *The height of the container is being
changed after the flow has laid itself out, without adjusting subsequent
children in any way.*

There is potentially a discussion to be had as to whether the emergent
behaviour of `TextFlowContainer.Text` with respect to `\n` character is
correct, but I'm just going to start with this diff and see what the
reaction is.
@peppy
Copy link
Member

peppy commented Apr 23, 2025

I don't get the xmldoc so maybe this says the underlying behaviour should change. Why would \n ever become a paragraph? Is there a reason we want this?

Might as well fix the fps counter in this PR while we're here.

@bdach
Copy link
Collaborator Author

bdach commented Apr 23, 2025

Why would \n ever become a paragraph? Is there a reason we want this?

Beats me. All of that behaviour predates me. Blame points to ppy/osu-framework#791.

I'm fine with changing behaviour but the question would be to what. Should newlines just break a line without considering paragraphs? In what circumstances? Should two newlines indicate a new paragraph? Heck knows.

@peppy
Copy link
Member

peppy commented Apr 23, 2025

I'd expect newline to always be a newline. Especially in the case of AddText? To add a new paragraph, I'd expect to use AddParagraph.

Trying to rationalise the implemented behaviour, maybe it was trying to do best-effort paragraph translation for .Text=proseContent?


to be clear, i'd prefer these issues are fixed with osu-side code changes first, we can figure framework changes later if we can agree on something.

@peppy peppy added the next release Pull requests which are almost there. We'll aim to get them in the next release, but no guarantees! label Apr 23, 2025
@bdach
Copy link
Collaborator Author

bdach commented Apr 23, 2025

Might as well fix the fps counter in this PR while we're here.

Attempted fix in 3f98dd9. It's a bit different because of how the fps display is written (does four .AddParagraph() calls in Update() so I don't really want to touch it too much)

@peppy peppy merged commit 0adda23 into ppy:master Apr 23, 2025
8 of 10 checks passed
@bdach bdach deleted the fix-daily-challenge-marker branch April 23, 2025 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:overlay-user-profile next release Pull requests which are almost there. We'll aim to get them in the next release, but no guarantees! size/S type:cosmetic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Daily Challenge counter on profile has incorrect spacing
2 participants