AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.13k stars 2.26k forks source link

RotateTransform does not accept 90 deg #9748

Open kuiperzone opened 1 year ago

kuiperzone commented 1 year ago

Describe the bug Am using to RotateTransform to render vertical text, i.e. a TextBlock rotated by 90 degrees.

However, RotateTransform does not accept 90 degrees, the Angle range appears limited to [-89.99, +89.99]. I suspect this is a division by 0 or tan(90)=INF error.

To Reproduce

Here is my XML. Note it is working with Angle = 89.9, but does not render if set to 90.

    <LayoutTransformControl Grid.Column="0" Grid.Row="3">
        <LayoutTransformControl.LayoutTransform>
            <RotateTransform Angle="89.9" />
        </LayoutTransformControl.LayoutTransform>
        <TextBlock
            Name="AxisY1CaptionBlock" HorizontalAlignment="Center" FontSize="10" Margin="0 0 3 0"
            Text="Y1 Axis" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
        </TextBlock>
    </LayoutTransformControl>

This is what it looks like with Angle of 89.9. See left axis, which is fraction of degree out of alignment. Note, setting Angle to 90 causes axis label not to be displayed.

image

Expected behavior I would suggest that acceptable range be [-360, +360], such that a value of 180 renders upside down.

Screenshots Above

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

kuiperzone commented 1 year ago

I can confirm that this is still an issue in 0.11 preview 4.

Strangely, the maximum angle it will accept has dropped slightly to 89.7. Anything above this, and the content is hidden.

This should be an easy one. At the very least, if for display purposes 89.7 == 90, then allow it to accept either +90 or -90.

kuiperzone commented 1 year ago

And to add, there's use cases for having text at +/- 90 degrees.

kuiperzone commented 1 year ago

Actually, not sure this is a bug at all, although the behaviour isn't entirely clear.

The variation below seems to work fine. Compare with above -- see the addition of "VerticalAlignment" in LayoutTransformControl. With this, the text displays fine..

    <!-- Y1 AXIS -->
    <LayoutTransformControl Grid.Column="0" Grid.Row="2"
        Name="LayoutY1"
        Margin="0 0 3 0"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
    >
        <LayoutTransformControl.LayoutTransform>
            <RotateTransform Angle="-90" />
        </LayoutTransformControl.LayoutTransform>
        <TextBlock Name="AxisY1CaptionBlock"
            Text="Y1 Axis"
            TextWrapping="NoWrap"
        />
    </LayoutTransformControl>
emmauss commented 1 year ago

Using the snippet provided in the issue message, setting an angle of 90 works fine on 11.0.0.4-preview. Could you create a full project repro and post it?

kuiperzone commented 1 year ago

Yes, will do over the next few days. Thanks for looking into it.

kuiperzone commented 1 year ago

Hi,

It seems there is a problem, though behaviour is not easily deterministic and in most scenarios things work normally. For example, while I can repeat the problem in my own UserControl based project, when trying to create a minimal example of the problem, the problem seems to vanish.

HOWEVER, I have managed to create a minimal sample which exhibits some kind of problem, though I've had to hack around a little to get it to display.

See the screenshot built against 0.11 preview 4. Here, there should be another TextBlock visible on the left where highlighted. See the MainWindow.axaml file (not Plotter.axaml).

image

ATTACHED ZIP FILE

KuiperZone.TerraPlot.Demo.zip

Bizarrely, doing any of the following will cause the TextBlock to be displayed:

  1. Changing the transform angle from -90 to -89.

  2. Deleting the superfleous (does nothing) "Plotter" UserControl from MainWindow.axaml. For some strange reason, this needs to be there in order for the problem to be visible.

  3. Moving VerticalAlignment statement from TextBlock to LayoutTransformControl.

kuiperzone commented 1 year ago

IMPORTANT TO ADD: I'm testing on Linux, Fedora 37

ITDancer13 commented 1 year ago

Two things to add:

  1. It's the same behavior on macOS 13.2
  2. Using the visual inspector showed that the text is rendered but at wrong location. I used your minimal sample and disabled ClipToBounds on LayoutTransformControl and the text "Y1 MAIN" re-appeared at a strange position
Bildschirm­foto 2023-02-11 um 07 36 16

I also realized that the calculated matrix is not 100% correct (should be 0,-1,1,0,0,0)

Bildschirm­foto 2023-02-11 um 07 48 26

But also applying the correct matrix using MatrixTransform didn't change the result:

`

` I try to find out more. But there might be two issues: 1. LayoutTransform should be investigated to return correct matrix (without slight rounding issues for at least 90 180 270) 2. Rendering of correct Matrix draws at wrong location