maui
maui copied to clipboard
Button Horizontal and Vertical TextAlignment
Description
I would love button supports HorizontalTextAlignment (and Vertical) as Label does.
Public API Changes
<Button HorizontalTextAlignment="Start" Text="timey wimey thing" />
Intended Use-Case
I had need the handler in android and i made it:
protected override void ConnectHandler(MaterialButton platformView)
{
base.ConnectHandler(platformView);
OnTextAlignmentPropertyChanged();
}
public override void UpdateValue(string property)
{
base.UpdateValue(property);
if (property == ButtonControl.HorizontalTextAlignmentProperty.PropertyName || property == ButtonControl.VerticalTextAlignmentProperty.PropertyName)
OnTextAlignmentPropertyChanged();
}
private void OnTextAlignmentPropertyChanged()
{
if (VirtualView is ButtonControl buttonControl)
{
GravityFlag horizontalFlag = buttonControl.HorizontalTextAlignment switch
{
TextAlignment.Start => GravityFlag.Left,
TextAlignment.Center => GravityFlag.CenterHorizontal,
TextAlignment.End => GravityFlag.Right,
_ => GravityFlag.Center
};
GravityFlag verticalFlag = buttonControl.VerticalTextAlignment switch
{
TextAlignment.Start => GravityFlag.Top,
TextAlignment.Center => GravityFlag.CenterVertical,
TextAlignment.End => GravityFlag.Bottom,
_ => GravityFlag.Center
};
PlatformView.Gravity = horizontalFlag | verticalFlag;
}
}
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
I leave here link for -Android handler sample: https://github.com/marcoablanco/RxUI.MauiToolkit/blob/develop/RxUI.MauiToolkit/Platforms/Android/Handlers/RxButtonHandler.cs Windows handler sample: https://github.com/marcoablanco/RxUI.MauiToolkit/blob/develop/RxUI.MauiToolkit/Platforms/Windows/Handlers/RxButtonHandler.cs and iOS: https://github.com/marcoablanco/RxUI.MauiToolkit/blob/develop/RxUI.MauiToolkit/Platforms/iOS/Handlers/RxButtonHandler.cs
But I haven't tried it on iOS, I don't know if it works yet.
Telerik have implemented it in their button. I'm trying to think some traitors here prevent small important things like this from going through to help alternate toolkits to grow.
I put all code of @marcoablanco in one single file
@marcoablanco I also fixed your iOS implementation, it works now. I used PlatformView.TitleLabel.TextAlignment instead of the other property to make it work. On iOS you can align separately both the multiline text block itself in the button, and the multiline text in that text block.
I got extremely frustrated with this missing capability as well. I'm not even able to align the Image and the Text vertically either.
Same here, having a multi-line text in a button, I can't get the text to be center aligned, instead it its left aligned :-(