Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/Core/src/Platform/Windows/TextBlockExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;
using System.Xml.Linq;
using System.Xml.Resolvers;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using WThickness = Microsoft.UI.Xaml.Thickness;
Expand Down Expand Up @@ -70,6 +71,7 @@ public static void UpdateLineHeight(this TextBlock platformControl, ILabel label
if (label.LineHeight >= 0)
{
platformControl.LineHeight = label.LineHeight * platformControl.FontSize;
platformControl.LineStackingStrategy = LineStackingStrategy.BlockLineHeight;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to set some default style here: https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Windows/Styles/Resources.xaml. The idea being that performance of the application would be better because the XAML would be set once and not for each and every label that sets some line height.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Storage;
using Microsoft.UI.Xaml;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a UI test containing

		<!-- Exercise line heights less than 1. --> 
		<Label BackgroundColor="Green" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Red" LineHeight="0.8" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Green" LineHeight="0.2" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Red" LineHeight="0.4" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Green" LineHeight="1.0" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Red" LineHeight="1.2" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Green" LineHeight="1.4" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Red" LineHeight="1.6" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Green" LineHeight="2.0" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
		<Label BackgroundColor="Red" LineHeight="4.6" FontSize="20" Text="ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ"/>
	</VerticalStackLayout>

from the comment #24520 (comment)

using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
using Xunit;
Expand Down Expand Up @@ -101,5 +102,50 @@ Color GetNativeTextColor(LabelHandler labelHandler)

UI.Xaml.TextAlignment GetNativeHorizontalTextAlignment(LabelHandler labelHandler) =>
GetPlatformLabel(labelHandler).TextAlignment;

double GetNativeLineHeight(LabelHandler labelHandler) =>
GetPlatformLabel(labelHandler).LineHeight;

double GetNativeCharacterSpacing(LabelHandler labelHandler) =>
GetPlatformLabel(labelHandler).CharacterSpacing;

[Fact]
public async Task LineHeightSetsLineStackingStrategyToBlockLineHeight()
{
var label = new LabelStub
{
Text = "Test text with line height",
LineHeight = 0.8 // LineHeight less than 1
};

var (lineHeight, lineStackingStrategy) = await GetValueAsync(label, handler =>
{
var platformLabel = GetPlatformLabel(handler);
return (platformLabel.LineHeight, platformLabel.LineStackingStrategy);
});

// When LineHeight is set, LineStackingStrategy should be BlockLineHeight
Assert.Equal(LineStackingStrategy.BlockLineHeight, lineStackingStrategy);
Assert.True(lineHeight > 0, "LineHeight should be greater than 0 when set");
}

[Fact]
public async Task NoLineHeightDefaultLineStackingStrategy()
{
var label = new LabelStub
{
Text = "Test text without line height"
// LineHeight not set (default is -1)
};

var lineStackingStrategy = await GetValueAsync(label, handler =>
{
var platformLabel = GetPlatformLabel(handler);
return platformLabel.LineStackingStrategy;
});

// When LineHeight is not set, LineStackingStrategy should remain default (MaxHeight)
Assert.Equal(LineStackingStrategy.MaxHeight, lineStackingStrategy);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ await ValidateUnrelatedPropertyUnaffected(
() => label.TextDecorations = newDecorations);
}

#if !WINDOWS

[Fact]
[Category(TestCategory.TextFormatting)]
public async Task LineHeightAppliedWhenTextAdded()
Expand Down Expand Up @@ -296,7 +294,6 @@ public async Task LineHeightInitializesCorrectly()
Assert.Equal(xplatLineHeight, values.ViewValue);
Assert.Equal(expectedValue, values.PlatformViewValue);
}
#endif

[Fact(DisplayName = "Html Text Initializes Correctly")]
public async Task HtmlTextInitializesCorrectly()
Expand Down