Skip to content

Commit b23c3b8

Browse files
Add .TextJustify()
1 parent 66ac82a commit b23c3b8

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/CommunityToolkit.Maui.Markup.SourceGenerators/SourceGenerators/TextAlignmentExtensionsGenerator.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ namespace CommunityToolkit.Maui.Markup
109109
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
110110
{{textAlignmentClassMetadata.ClassAcessModifier}} static partial class TextAlignmentExtensions_{{textAlignmentClassMetadata.ClassName}}
111111
{
112+
/// <summary>
113+
/// <see cref="ITextAlignment.HorizontalTextAlignment"/> = <see cref="TextAlignment.Justify"/>
114+
/// </summary>
115+
/// <param name="textAlignmentControl"></param>
116+
/// <returns><typeparamref name="TAssignable"/> with added <see cref="TextAlignment.Justify"/></returns>
117+
public static TAssignable TextJustify{{genericTypeParameters}}(this TAssignable textAlignmentControl)
118+
where TAssignable : {{textAlignmentClassMetadata.Namespace}}.{{textAlignmentClassMetadata.ClassName}}{{genericArguments}}{{textAlignmentClassMetadata.GenericConstraints}}
119+
{
120+
ArgumentNullException.ThrowIfNull(textAlignmentControl);
121+
122+
if (textAlignmentControl is not ITextAlignment)
123+
{
124+
throw new ArgumentException($"Element must implement {nameof(ITextAlignment)}", nameof(textAlignmentControl));
125+
}
126+
127+
textAlignmentControl.HorizontalTextAlignment = TextAlignment.Justify;
128+
return textAlignmentControl;
129+
}
130+
112131
/// <summary>
113132
/// <see cref="ITextAlignment.HorizontalTextAlignment"/> = <see cref="TextAlignment.Start"/>
114133
/// </summary>

src/CommunityToolkit.Maui.Markup.UnitTests/LabelExtensionsLeftToRightTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public void TextLeft()
1414
public void TextRight()
1515
=> TestPropertiesSet(l => l.TextRight(), (Label.HorizontalTextAlignmentProperty, TextAlignment.Start, TextAlignment.End));
1616

17+
[Test]
18+
public void TextJustify()
19+
=> TestPropertiesSet(l => l.TextJustify(), (Label.HorizontalTextAlignmentProperty, TextAlignment.Start, TextAlignment.Justify));
20+
1721
[Test]
1822
public void SupportDerivedFromLabel() => Assert.That(new DerivedFromLabel().TextLeft().TextRight(), Is.InstanceOf<DerivedFromLabel>());
1923

src/CommunityToolkit.Maui.Markup.UnitTests/LabelExtensionsRightToLeftTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public void TextLeft()
1414
public void TextRight()
1515
=> TestPropertiesSet(l => l.TextRight(), (Label.HorizontalTextAlignmentProperty, TextAlignment.End, TextAlignment.Start));
1616

17+
[Test]
18+
public void TextJustify()
19+
=> TestPropertiesSet(l => l.TextJustify(), (Label.HorizontalTextAlignmentProperty, TextAlignment.Start, TextAlignment.Justify));
20+
1721
[Test]
1822
public void SupportDerivedFromLabel() => Assert.That(new DerivedFromLabel().TextLeft().TextRight(), Is.InstanceOf<DerivedFromLabel>());
1923

0 commit comments

Comments
 (0)