Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Documents/Inline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void SetTextDecorations(Control control, TextDecorationCollection?
control.SetValue(TextDecorationsProperty, value);
}

internal abstract void BuildTextRun(IList<TextRun> textRuns);
internal abstract void BuildTextRun(IList<TextRun> textRuns, Size blockSize);

internal abstract void AppendText(StringBuilder stringBuilder);

Expand Down
9 changes: 6 additions & 3 deletions src/Avalonia.Controls/Documents/InlineUIContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class InlineUIContainer : Inline
public static readonly StyledProperty<Control> ChildProperty =
AvaloniaProperty.Register<InlineUIContainer, Control>(nameof(Child));

private double _measuredWidth = double.NaN;
Comment thread
miloush marked this conversation as resolved.

/// <summary>
/// Initializes a new instance of InlineUIContainer element.
/// </summary>
Expand Down Expand Up @@ -51,11 +53,12 @@ public Control Child
set => SetValue(ChildProperty, value);
}

internal override void BuildTextRun(IList<TextRun> textRuns)
internal override void BuildTextRun(IList<TextRun> textRuns, Size blockSize)
{
if(!Child.IsMeasureValid)
if (_measuredWidth != blockSize.Width || !Child.IsMeasureValid)
{
Child.Measure(Size.Infinity);
Child.Measure(new Size(blockSize.Width, double.PositiveInfinity));
_measuredWidth = blockSize.Width;
}

textRuns.Add(new EmbeddedControlRun(Child, CreateTextRunProperties()));
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Controls/Documents/LineBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LineBreak()
{
}

internal override void BuildTextRun(IList<TextRun> textRuns)
internal override void BuildTextRun(IList<TextRun> textRuns, Size blockSize)
{
var text = Environment.NewLine;

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Documents/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public string? Text {
set => SetValue(TextProperty, value);
}

internal override void BuildTextRun(IList<TextRun> textRuns)
internal override void BuildTextRun(IList<TextRun> textRuns, Size blockSize)
{
var text = Text ?? "";

Expand All @@ -59,7 +59,7 @@ internal override void BuildTextRun(IList<TextRun> textRuns)
return;
}

var textRunProperties = CreateTextRunProperties();
var textRunProperties = CreateTextRunProperties();

var textCharacters = new TextCharacters(text, textRunProperties);

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/Documents/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public InlineCollection Inlines
set => SetValue(InlinesProperty, value);
}

internal override void BuildTextRun(IList<TextRun> textRuns)
internal override void BuildTextRun(IList<TextRun> textRuns, Size blockSize)
{
foreach (var inline in Inlines)
{
inline.BuildTextRun(textRuns);
inline.BuildTextRun(textRuns, blockSize);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ protected override Size MeasureOverride(Size availableSize)
_textLayout = null;
_constraint = deflatedSize;

//Force arrange so text will be properly alligned.
//Force arrange so text will be properly aligned.
InvalidateArrange();
}

Expand All @@ -742,7 +742,7 @@ protected override Size MeasureOverride(Size availableSize)

foreach (var inline in inlines!)
{
inline.BuildTextRun(textRuns);
inline.BuildTextRun(textRuns, deflatedSize);
}

_textRuns = textRuns;
Expand Down
27 changes: 26 additions & 1 deletion tests/Avalonia.Controls.UnitTests/TextBlockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void Changing_Inlines_Should_Reset_InlineUIContainer_VisualParent_On_Meas
}

[Fact]
public void InlineUIContainer_Child_Schould_Be_Arranged()
public void InlineUIContainer_Child_Should_Be_Arranged()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
Expand Down Expand Up @@ -382,6 +382,31 @@ public void InlineUIContainer_Child_Schould_Be_Arranged()
}
}

[Fact]
public void InlineUIContainer_Child_Should_Be_Constrained()
{
using (UnitTestApplication.Start(TestServices.StyledWindow))
{
var target = new TextBlock();

GeometryDrawing drawing = new GeometryDrawing();
drawing.Geometry = new RectangleGeometry(new Rect(0, 0, 500, 500));
DrawingImage image = new DrawingImage(drawing);

Image imageControl = new Image { Source = image };
InlineUIContainer container = new InlineUIContainer(imageControl);

target.Inlines.Add(new Run("The child should not be limited by position on line."));
target.Inlines.Add(container);

target.Measure(new Size(100, 100));
target.Arrange(new Rect(target.DesiredSize));

Assert.True(imageControl.IsMeasureValid);
Assert.Equal(100, imageControl.Bounds.Width);
}
}

[Fact]
public void Setting_Text_Should_Reset_Inlines()
{
Expand Down
Loading