Skip to content

Commit

Permalink
Merge pull request #1220 from default0/tfc-autosize
Browse files Browse the repository at this point in the history
Allow TextFlowContainer to AutoSize on the X axis
  • Loading branch information
peppy authored Dec 7, 2017
2 parents a8d8654 + 2677057 commit ba2a9c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion osu.Framework/Graphics/Containers/FillFlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected override IEnumerable<Vector2> ComputeLayoutPositions()
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))
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical || ForceNewRow(c)))
{
current.X = 0;
current.Y += rowHeight;
Expand Down Expand Up @@ -234,6 +234,13 @@ protected override IEnumerable<Vector2> ComputeLayoutPositions()

return result;
}

/// <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
3 changes: 2 additions & 1 deletion osu.Framework/Graphics/Containers/TextFlowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ private void computeLayout()
}
}

protected override bool ForceNewRow(Drawable child) => child is NewLineContainer;

internal class NewLineContainer : Container
{
public readonly bool IndicatesNewParagraph;

public NewLineContainer(bool newParagraph)
{
RelativeSizeAxes = Axes.X;
IndicatesNewParagraph = newParagraph;
}
}
Expand Down

0 comments on commit ba2a9c2

Please sign in to comment.