maui icon indicating copy to clipboard operation
maui copied to clipboard

Button Horizontal and Vertical TextAlignment

Open marcoablanco opened this issue 2 years ago • 2 comments

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;
		}
	}

marcoablanco avatar Oct 03 '22 15:10 marcoablanco

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.

ghost avatar Oct 04 '22 18:10 ghost

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.

marcoablanco avatar Oct 14 '22 10:10 marcoablanco

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.

softlion avatar Apr 17 '24 14:04 softlion

I got extremely frustrated with this missing capability as well. I'm not even able to align the Image and the Text vertically either.

dotMorten avatar Jun 25 '24 20:06 dotMorten

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 :-(

erdmenchen avatar Jun 26 '24 09:06 erdmenchen