Skip to content
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

Implement Padding in ILabel Handlers #421

Merged
merged 6 commits into from
Mar 5, 2021
Merged

Implement Padding in ILabel Handlers #421

merged 6 commits into from
Mar 5, 2021

Conversation

hartez
Copy link
Contributor

@hartez hartez commented Mar 4, 2021

Implements #369

  • Adds Thickness Padding { get; } to the ILabel interface
  • Adds Padding property map to LabelHandler
  • Adds Padding mapping methods to LabelHandler for Android and iOS
  • Adds extension methods to apply Padding on Android/iOS
  • Adds UILabel subclass MauiLabel (to support Padding, since UILabel doesn't by default)
  • Adds DeviceTests for initial Padding values on iOS and Android

@@ -33,6 +33,7 @@ void SetupMauiLayout()
verticalStack.Add(new Label { Text = "This should be BIG text!", FontSize = 24 });
verticalStack.Add(new Label { Text = "This should be BOLD text!", FontAttributes = FontAttributes.Bold });
verticalStack.Add(new Label { Text = "This should be a CUSTOM font!", FontFamily = "Dokdo" });
verticalStack.Add(new Label { Text = "This should have padding", Padding = new Thickness(40), BackgroundColor = Color.LightBlue });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds an example of the property to the sample project.

@@ -2,5 +2,6 @@ namespace Microsoft.Maui
{
public interface ILabel : IView, IText, IFont
{
Thickness Padding { get; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds the property to the interface.

{
handler.TypedNativeView?.UpdatePadding(label);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a mapping method to the Android aspect of the handler.

@@ -11,5 +11,6 @@ public partial class LabelHandler : AbstractViewHandler<ILabel, object>
public static void MapFontFamily(LabelHandler handler, ILabel label) { }
public static void MapFontSize(LabelHandler handler, ILabel label) { }
public static void MapFontAttributes(LabelHandler handler, ILabel label) { }
public static void MapPadding(LabelHandler handler, ILabel label) { }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a mapping method to the Standard aspect of the handler; the Standard aspect is just a placeholder and is never actually called.

@@ -9,6 +9,7 @@ public partial class LabelHandler
[nameof(ILabel.FontFamily)] = MapFontFamily,
[nameof(ILabel.FontSize)] = MapFontSize,
[nameof(ILabel.FontAttributes)] = MapFontAttributes,
[nameof(ILabel.Padding)] = MapPadding,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add the mapping to the PropertyMapper for the handler.

{
handler.TypedNativeView?.UpdatePadding(label);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a mapping method to the iOS aspect of the handler.

(int)context.ToPixels(label.Padding.Top),
(int)context.ToPixels(label.Padding.Right),
(int)context.ToPixels(label.Padding.Bottom));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add an extension method to handle the actual update for the native Android control. This logic is ported directly from the Forms Label renderer for Android.

public static void UpdatePadding(this object nothing, ILabel label)
{

}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The placeholder extension method for Standard; this is never actually called.

(float)label.Padding.Bottom,
(float)label.Padding.Right);

}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add an extension method to handle the actual update for the native iOS control. This logic is ported directly from the Forms Label renderer for iOS.

width: size.Width + TextInsets.Left + TextInsets.Right,
height: size.Height + TextInsets.Top + TextInsets.Bottom);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this particular property, we needed to extend the UILabel class with some custom logic because Padding doesn't exist natively. This class was ported from the Forms iOS platform project.

Assert.Equal(expectedRight, right);
Assert.Equal(expectedBottom, bottom);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds an on-device test to verify that the property is being set on the native Android control. This test will be run on an Android device as part of the CI process.

Assert.Equal(15, insets.Right);
Assert.Equal(20, insets.Bottom);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adds an on-device test to verify that the property is being set on the native iOS control. This test will be run on an iOS device as part of the CI process.

@@ -11,5 +11,7 @@ public partial class LabelStub : StubBase, ILabel
public string FontFamily { get; set; }

public double FontSize { get; set; }

public Thickness Padding { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The stub classes are implementations of the MAUI interfaces used for on-device testing.

@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Jul 10, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants