Skip to content

MVP for Multi-Line Textbox #6564

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
35 changes: 35 additions & 0 deletions osu.Framework.Tests/Visual/UserInterface/TestSceneTextArea.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;

namespace osu.Framework.Tests.Visual.UserInterface
{
public partial class TestSceneTextArea : ManualInputManagerTestScene
{
[BackgroundDependencyLoader]
private void load()
{
Add(new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(30),
Child = new TextArea
{
RelativeSizeAxes = Axes.None,
Width = 300,
Height = 200,
Text =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
+ "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
+ "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"
}
});
}
}
}
10 changes: 9 additions & 1 deletion 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))
if (direction != FillDirection.Horizontal && (Precision.DefinitelyBigger(rowWidth, max.X) || direction == FillDirection.Vertical || ForceNewRow(c)))
{
current.X = 0;
current.Y += rowHeight;
Expand Down Expand Up @@ -286,13 +286,21 @@ static Axes toAxes(FillDirection direction)

yield return layoutPosition;
}

OnLayoutComputed(children, layoutPositions, rowIndices);
}
finally
{
ArrayPool<Vector2>.Shared.Return(layoutPositions);
ArrayPool<int>.Shared.Return(rowIndices);
}
}

protected virtual void OnLayoutComputed(Drawable[] children, Vector2[] layoutPositions, int[] rowIndices)
{
}

protected virtual bool ForceNewRow(Drawable drawable) => false;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Sprites/SpriteText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public MarginPadding Padding
/// <summary>
/// The characters in local space.
/// </summary>
private List<TextBuilderGlyph> characters
internal List<TextBuilderGlyph> Characters
{
get
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/Sprites/SpriteText_DrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void Draw(IRenderer renderer)
/// </summary>
private void updateScreenSpaceCharacters()
{
int partCount = Source.characters.Count;
int partCount = Source.Characters.Count;

if (parts == null)
parts = new List<ScreenSpaceCharacterPart>(partCount);
Expand All @@ -98,7 +98,7 @@ private void updateScreenSpaceCharacters()

Vector2 inflationAmount = DrawInfo.MatrixInverse.ExtractScale().Xy;

foreach (var character in Source.characters)
foreach (var character in Source.Characters)
{
parts.Add(new ScreenSpaceCharacterPart
{
Expand Down
Loading
Loading