Skip to content

Commit 7df03d4

Browse files
authored
Merge pull request #6556 from bdach/we-back-in-the-text-flow-mine
Fix text flow container layout changing after one frame in some cases
2 parents 9096ea8 + 03d0a3b commit 7df03d4

File tree

4 files changed

+310
-145
lines changed

4 files changed

+310
-145
lines changed

osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using osu.Framework.Graphics.Shapes;
1111
using osu.Framework.Graphics.Sprites;
1212
using osu.Framework.Testing;
13+
using osu.Framework.Threading;
1314
using osuTK;
1415
using osuTK.Graphics;
1516

@@ -142,6 +143,26 @@ public void TestSizing()
142143
topLevelContainer.RelativeSizeAxes = textContainer.RelativeSizeAxes = Axes.None;
143144
topLevelContainer.AutoSizeAxes = textContainer.AutoSizeAxes = Axes.Both;
144145
});
146+
AddStep("set autosize width with right anchored text", () =>
147+
{
148+
topLevelContainer.RelativeSizeAxes = textContainer.RelativeSizeAxes = Axes.None;
149+
topLevelContainer.AutoSizeAxes = textContainer.AutoSizeAxes = Axes.Both;
150+
textContainer.TextAnchor = Anchor.TopRight;
151+
});
152+
}
153+
154+
[Test]
155+
public void TestSetTextRepeatedly()
156+
{
157+
ScheduledDelegate repeat = null!;
158+
AddStep("set text repeatedly", () => repeat = Scheduler.AddDelayed(() =>
159+
{
160+
textContainer.Clear();
161+
textContainer.AddParagraph("first paragraph lorem ipsum dolor sit amet and whatever else is needed to break a line");
162+
textContainer.AddParagraph(string.Empty);
163+
textContainer.AddParagraph("second paragraph lorem ipsum dolor sit amet and whatever else is needed to break a line");
164+
}, 50, true));
165+
AddStep("cancel", () => repeat.Cancel());
145166
}
146167

147168
private void assertSpriteTextCount(int count)

osu.Framework/Graphics/Containers/FillFlowContainer.cs

+1-8
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static Axes toAxes(FillDirection direction)
183183
float rowWidth = rowBeginOffset + current.X + (1 - spacingFactor(c).X) * size.X;
184184

185185
//We've exceeded our allowed width, move to a new row
186-
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical || ForceNewRow(c)))
186+
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical))
187187
{
188188
current.X = 0;
189189
current.Y += rowHeight;
@@ -293,13 +293,6 @@ static Axes toAxes(FillDirection direction)
293293
ArrayPool<int>.Shared.Return(rowIndices);
294294
}
295295
}
296-
297-
/// <summary>
298-
/// Returns true if the given child should be placed on a new row, false otherwise. This will be called automatically for each child in this FillFlowContainers FlowingChildren-List.
299-
/// </summary>
300-
/// <param name="child">The child to check.</param>
301-
/// <returns>True if the given child should be placed on a new row, false otherwise.</returns>
302-
protected virtual bool ForceNewRow(Drawable child) => false;
303296
}
304297

305298
/// <summary>

osu.Framework/Graphics/Containers/FlowContainer.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,10 @@ public Vector2 MaximumSize
6969

7070
protected override bool RequiresChildrenUpdate => base.RequiresChildrenUpdate || !layout.IsValid;
7171

72-
internal event Action OnLayoutInvalidated;
73-
7472
/// <summary>
7573
/// Invoked when layout should be invalidated.
7674
/// </summary>
77-
protected virtual void InvalidateLayout()
78-
{
79-
layout.Invalidate();
80-
OnLayoutInvalidated?.Invoke();
81-
}
75+
protected internal void InvalidateLayout() => layout.Invalidate();
8276

8377
private readonly Dictionary<Drawable, float> layoutChildren = new Dictionary<Drawable, float>();
8478

0 commit comments

Comments
 (0)