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

Button.Content does not use HorizontalContentAlignment properly #7620

Open
robloo opened this issue Dec 8, 2021 · 5 comments
Open

Button.Content does not use HorizontalContentAlignment properly #7620

robloo opened this issue Dec 8, 2021 · 5 comments
Assignees
Labels
difficulty/challenging 🤯 Categorizes an issue for which the difficulty level is reachable with internals understanding kind/bug Something isn't working low-hanging-🍒 Categorizes an issue that might be a quick win with meaningful positive impact. project/layout 🧱 Categorizes an issue or PR as relevant to layouting and containers (Measure/Arrange, Collections,..)

Comments

@robloo
Copy link
Contributor

robloo commented Dec 8, 2021

Current behavior

Certain Button Content is not centered. This is even specified in XAML with HorizontalContentAlignment just to be sure but the default is also Center. This appears to be related to the StackPanel which is known to have many issues.

Note: StackPanel needs a port from upstream WinUI ASAP like Grid.

image

                <Button
                    x:Name="NextButton2"
                    MinWidth="100"
                    HorizontalContentAlignment="Center">
                    <StackPanel
                        VerticalAlignment="Stretch"
                        HorizontalAlignment="Stretch"
                        Orientation="Horizontal">
                        <TextBlock
                            x:Name="NextButton2TextBlock"
                            Text="Next"
                            TextAlignment="Left"
                            VerticalAlignment="Center"
                            Margin="0,0,3,0" />
                    </StackPanel>
                </Button>
                <Button
                    x:Name="NextButton3"
                    MinWidth="100"
                    Content="Next"
                    HorizontalContentAlignment="Center">
                </Button>

Expected behavior

All content should be centered by default.

How to reproduce it (as minimally and precisely as possible)

Repro App:

TestApp.zip

Workaround

Perhaps try a different container/panel such as Grid

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia

NuGet package version(s)

4.0.9

Affected platforms

Android

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@robloo robloo added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Dec 8, 2021
@jeromelaban jeromelaban changed the title StackPanel Content not Centered Within Button Button.Content does not use HorizontalContentAlignment properly Dec 8, 2021
@jeromelaban
Copy link
Member

The issue is not with StackPanel, but rather how button manages its own children. You can replace the StackPanel with a Grid and you'll see the same result.

@jeromelaban jeromelaban added project/layout 🧱 Categorizes an issue or PR as relevant to layouting and containers (Measure/Arrange, Collections,..) and removed triage/untriaged Indicates an issue requires triaging or verification labels Dec 8, 2021
@jeromelaban
Copy link
Member

@carldebilly do you know what happens here ?

@carldebilly
Copy link
Member

carldebilly commented Dec 15, 2021

Playground: https://playground.platform.uno/#161c3915

Looks related to the way the "arrange" is build in Uno. My intuition would be it should take into consideration the desiredSize and readjust according to the actual result from ArrangeOverride(). This mechanism is pretty different in Uno and could explain the behavior observed in this issue.

To investigate...

@carldebilly carldebilly added difficulty/challenging 🤯 Categorizes an issue for which the difficulty level is reachable with internals understanding and removed difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Dec 15, 2021
@robloo
Copy link
Contributor Author

robloo commented Dec 15, 2021

In the playground, first sample, I can delete the HorizontalAlignment="Stretch" from <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch"> and make it work. This shows two things:

  1. Measure/arrange is behaving differently on WASM from Android. I would normally expect these layout-related code paths to be shared and generic for all platforms.
  2. StackPanel is not sizing to the child TextBox. This is a bug with StackPanel as I do think it always sizes to children in UWP.

Bottom line: Wasm appears to behave differently from Android.

@MartinZikmund MartinZikmund changed the title Button.Content does not use HorizontalContentAlignment properly Button.Content does not use HorizontalContentAlignment properly Jul 19, 2023
@MartinZikmund MartinZikmund added the low-hanging-🍒 Categorizes an issue that might be a quick win with meaningful positive impact. label Jul 19, 2023
@Youssef1313
Copy link
Member

If this is Android/iOS only, then I would suspect it's because of ContentPresenter bypass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/challenging 🤯 Categorizes an issue for which the difficulty level is reachable with internals understanding kind/bug Something isn't working low-hanging-🍒 Categorizes an issue that might be a quick win with meaningful positive impact. project/layout 🧱 Categorizes an issue or PR as relevant to layouting and containers (Measure/Arrange, Collections,..)
Projects
None yet
Development

No branches or pull requests

5 participants