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.19k stars 2.27k forks source link

Apply Panel-Orientation of DRM-Output #14241

Open BinaryCraX opened 10 months ago

BinaryCraX commented 10 months ago

Is your feature request related to a problem? Please describe.

When using DRM-Output, currently Avalonia doesn't seem to respect the panel_orientation property of DRM/KMS which indicates how the panel is mounted inside the casing. Because of this the UI is rendered 270° rotated in my case. (side-note: touch-input aligns with the rendered output)

Describe the solution you'd like

Describe alternatives you've considered

Additional context

kekekeks commented 10 months ago

As a temporary workaround, you can listen for OnAttachedToVisualTree event and apply the transform to the TopLevel. That would make menus to be rotated too.

BinaryCraX commented 10 months ago

Thank you very much for the suggestion. As you suggested (if I have understood it correctly), I tried adding following to my MainView:

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
    base.OnAttachedToVisualTree(e);
    var root = (EmbeddableControlRoot)e.Root;
    root.RenderTransform = new RotateTransform(270);
}

Unfortunately this only affects rendering and therefore the layout is wrong.

For a layout-transform I would need to add a LayoutTransformControl in between the MainView and the TopLevel (which is what I did in the screenshot above), but in this case the Combobox-Dropdown isn't rotated.

If I try to apply both (rotate using LayoutTransformControl and additionally apply RenderTransform to the TopLevel), layout is correct but rendering is wrong because rotation get's applied 2 times to the MainView (270° by the LayoutTransformControl and additional 270° by the RenderTransform).

Perhaps I have misunderstood something?

kekekeks commented 10 months ago

You can change the default template for EmbeddableControlRoot.

BinaryCraX commented 10 months ago

Tried the new suggestion. Added new Resource-Dictionary "EmbeddableControlRootTemplate.axaml" with changed Template:

<ResourceDictionary xmlns="https://github.com/avaloniaui"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <ControlTheme x:Key="{x:Type EmbeddableControlRoot}" TargetType="EmbeddableControlRoot">
    <Setter Property="Foreground" Value="{DynamicResource SystemControlForegroundBaseHighBrush}"/>
    <Setter Property="Background" Value="{DynamicResource SystemRegionBrush}"/>
    <Setter Property="TopLevel.SystemBarColor" Value="{DynamicResource SystemControlBackgroundAltHighBrush}"/>
    <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}"/>
    <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
    <Setter Property="Template">
      <ControlTemplate>
        <LayoutTransformControl>
          <LayoutTransformControl.LayoutTransform>
            <RotateTransform Angle="270" />
          </LayoutTransformControl.LayoutTransform>

          <Panel>
            <Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
            <Border Background="{TemplateBinding Background}">
              <VisualLayerManager>
                  <ContentPresenter Name="PART_ContentPresenter"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    Content="{TemplateBinding Content}"
                                    Margin="{TemplateBinding Padding}"/>
              </VisualLayerManager>
            </Border>
          </Panel>

        </LayoutTransformControl>
      </ControlTemplate>
    </Setter>
  </ControlTheme>

</ResourceDictionary>

And changed App.axaml to include it:

  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceInclude Source='/EmbeddableControlRootTemplate.axaml'/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>

It seems to be the right track, but still not completly correct: Orientation of drop-down of ComboBox is now correct. However position of the drop-down is wrong. It seems to confuse X and Y axis.

With 270° RotateTransform, the further the ComboBox is moved to the right, the further up the drop-down list is positioned. (Click to see pictures) left: ![grafik](https://github.com/AvaloniaUI/Avalonia/assets/5560801/d1eaac2e-9119-4b58-8482-cb11ce41ba6c) middle: ![grafik](https://github.com/AvaloniaUI/Avalonia/assets/5560801/bc076eda-634d-4d73-93e8-f1a4ed302963) right: ![grafik](https://github.com/AvaloniaUI/Avalonia/assets/5560801/1d1c852f-d33c-4b5a-9b34-0b46b44ad06f)
BinaryCraX commented 5 months ago

Scroll-Gesture-Recognition is also not working properly (X/Y flipped) with the latest workaround-approach (LayoutTransformControl directly inside of EmbeddableControlRoot).

I tried to find the right place inside the code of Avalonia to be fix the problem at the root. But there are many moving parts and the complexity is high. Can you point me in a direction so that I can try to fix it?

BuriKizilkaya commented 5 months ago

As a temporary workaround, you can listen for OnAttachedToVisualTree event and apply the transform to the TopLevel. That would make menus to be rotated too.

I need also a solution for this issue.

kyuranger commented 3 months ago

Scroll-Gesture-Recognition

I met the same problem in Scroll-Gesture-Recognition. BTW, have you solved this problem or found any other new solution?

BuriKizilkaya commented 3 months ago

I disabled scroll gestures for now.

kyuranger commented 3 months ago

I disabled scroll gestures for now.

But if you do this, won't the scrollviewer be able to slide up and down? In other words, won't the scrollviewer be unusable?

BuriKizilkaya commented 3 months ago

I have a custom scrollbar which is clickable.