Browse Source

Added support for RTL view in NativeControlHost.cs (#14804)

* Added support for RTL view in NativeControlHost.cs

* Changed RTL test to use TransformToAABB instead
pull/14843/head
Lighto 2 years ago
committed by GitHub
parent
commit
52338400b9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      src/Avalonia.Controls/NativeControlHost.cs

20
src/Avalonia.Controls/NativeControlHost.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using Avalonia.Controls.Platform;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Threading;
using Avalonia.VisualTree;
@ -18,6 +19,11 @@ namespace Avalonia.Controls
private bool _queuedForMoveResize;
private readonly List<Visual> _propertyChangedSubscriptions = new();
static NativeControlHost()
{
FlowDirectionProperty.Changed.AddClassHandler<NativeControlHost>(OnFlowDirectionChanged);
}
/// <inheritdoc />
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
@ -33,6 +39,12 @@ namespace Avalonia.Controls
UpdateHost();
}
private static void OnFlowDirectionChanged(NativeControlHost nativeControlHost,
AvaloniaPropertyChangedEventArgs propertyChangedEventArgs)
{
nativeControlHost.TryUpdateNativeControlPosition();
}
private void PropertyChangedHandler(object? sender, AvaloniaPropertyChangedEventArgs e)
{
@ -118,10 +130,12 @@ namespace Avalonia.Controls
Debug.Assert(_currentRoot is not null);
var bounds = Bounds;
var position = this.TranslatePoint(default, _currentRoot);
if (position == null)
// Native window is not rendered by Avalonia
var transformToVisual = this.TransformToVisual(_currentRoot);
if (transformToVisual == null)
return null;
return new Rect(position.Value, bounds.Size);
var position = new Rect(default, bounds.Size).TransformToAABB(transformToVisual.Value).Position;
return new Rect(position, bounds.Size);
}
private void EnqueueForMoveResize()

Loading…
Cancel
Save