Skip to content
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

Fix text flow container layout changing after one frame in some cases #6556

Merged
merged 5 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
using osu.Framework.Threading;
using osuTK;
using osuTK.Graphics;

Expand Down Expand Up @@ -142,6 +143,26 @@ public void TestSizing()
topLevelContainer.RelativeSizeAxes = textContainer.RelativeSizeAxes = Axes.None;
topLevelContainer.AutoSizeAxes = textContainer.AutoSizeAxes = Axes.Both;
});
AddStep("set autosize width with right anchored text", () =>
{
topLevelContainer.RelativeSizeAxes = textContainer.RelativeSizeAxes = Axes.None;
topLevelContainer.AutoSizeAxes = textContainer.AutoSizeAxes = Axes.Both;
textContainer.TextAnchor = Anchor.TopRight;
});
}

[Test]
public void TestSetTextRepeatedly()
{
ScheduledDelegate repeat = null!;
AddStep("set text repeatedly", () => repeat = Scheduler.AddDelayed(() =>
{
textContainer.Clear();
textContainer.AddParagraph("first paragraph lorem ipsum dolor sit amet and whatever else is needed to break a line");
textContainer.AddParagraph(string.Empty);
textContainer.AddParagraph("second paragraph lorem ipsum dolor sit amet and whatever else is needed to break a line");
}, 50, true));
AddStep("cancel", () => repeat.Cancel());
}

private void assertSpriteTextCount(int count)
Expand Down
9 changes: 1 addition & 8 deletions osu.Framework/Graphics/Containers/FillFlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static Axes toAxes(FillDirection direction)
float rowWidth = rowBeginOffset + current.X + (1 - spacingFactor(c).X) * size.X;

//We've exceeded our allowed width, move to a new row
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical || ForceNewRow(c)))
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical))
{
current.X = 0;
current.Y += rowHeight;
Expand Down Expand Up @@ -293,13 +293,6 @@ static Axes toAxes(FillDirection direction)
ArrayPool<int>.Shared.Return(rowIndices);
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="child">The child to check.</param>
/// <returns>True if the given child should be placed on a new row, false otherwise.</returns>
protected virtual bool ForceNewRow(Drawable child) => false;
}

/// <summary>
Expand Down
8 changes: 1 addition & 7 deletions osu.Framework/Graphics/Containers/FlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,10 @@ public Vector2 MaximumSize

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

internal event Action OnLayoutInvalidated;

/// <summary>
/// Invoked when layout should be invalidated.
/// </summary>
protected virtual void InvalidateLayout()
{
layout.Invalidate();
OnLayoutInvalidated?.Invoke();
}
protected internal void InvalidateLayout() => layout.Invalidate();

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

Expand Down
Loading
Loading