Browse Source

Nullability fixes for Avalonia.Diagnostics

pull/10256/head
Julien Lebosquain 3 years ago
parent
commit
c99e1743ba
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 34
      src/Avalonia.Controls/Primitives/OverlayPopupHost.cs
  2. 2
      src/Avalonia.Controls/TopLevel.cs
  3. 3
      src/Avalonia.Diagnostics/Diagnostics/KeyGestureExtesions.cs

34
src/Avalonia.Controls/Primitives/OverlayPopupHost.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Avalonia.Reactive;
using Avalonia.Controls.Primitives.PopupPositioning;
using Avalonia.Interactivity;
using Avalonia.Media;
@ -18,8 +17,8 @@ namespace Avalonia.Controls.Primitives
PopupRoot.TransformProperty.AddOwner<OverlayPopupHost>();
private readonly OverlayLayer _overlayLayer;
private PopupPositionerParameters _positionerParameters = new PopupPositionerParameters();
private ManagedPopupPositioner _positioner;
private readonly ManagedPopupPositioner _positioner;
private PopupPositionerParameters _positionerParameters;
private Point _lastRequestedPosition;
private bool _shown;
@ -29,13 +28,16 @@ namespace Avalonia.Controls.Primitives
_positioner = new ManagedPopupPositioner(this);
}
/// <inheritdoc />
public void SetChild(Control? control)
{
Content = control;
}
/// <inheritdoc />
public Visual? HostedVisualTreeRoot => null;
/// <inheritdoc />
public Transform? Transform
{
get => GetValue(TransformProperty);
@ -48,23 +50,27 @@ namespace Avalonia.Controls.Primitives
set { /* Not currently supported in overlay popups */ }
}
/// <inheritdoc />
protected internal override Interactive? InteractiveParent => (Interactive?)VisualParent;
/// <inheritdoc />
public void Dispose() => Hide();
/// <inheritdoc />
public void Show()
{
_overlayLayer.Children.Add(this);
_shown = true;
}
/// <inheritdoc />
public void Hide()
{
_overlayLayer.Children.Remove(this);
_shown = false;
}
/// <inheritdoc />
public void ConfigurePosition(Visual target, PlacementMode placement, Point offset,
PopupAnchor anchor = PopupAnchor.None, PopupGravity gravity = PopupGravity.None,
PopupPositionerConstraintAdjustment constraintAdjustment = PopupPositionerConstraintAdjustment.All,
@ -75,6 +81,7 @@ namespace Avalonia.Controls.Primitives
UpdatePosition();
}
/// <inheritdoc />
protected override Size ArrangeOverride(Size finalSize)
{
if (_positionerParameters.Size != finalSize)
@ -123,17 +130,18 @@ namespace Avalonia.Controls.Primitives
public static IPopupHost CreatePopupHost(Visual target, IAvaloniaDependencyResolver? dependencyResolver)
{
var platform = TopLevel.GetTopLevel(target)?.PlatformImpl?.CreatePopup();
if (platform != null)
return new PopupRoot((TopLevel)target.GetVisualRoot()!, platform, dependencyResolver);
var overlayLayer = OverlayLayer.GetOverlayLayer(target);
if (overlayLayer == null)
throw new InvalidOperationException(
"Unable to create IPopupImpl and no overlay layer is found for the target control");
if (TopLevel.GetTopLevel(target) is { } topLevel && topLevel.PlatformImpl?.CreatePopup() is { } popupImpl)
{
return new PopupRoot(topLevel, popupImpl, dependencyResolver);
}
if (OverlayLayer.GetOverlayLayer(target) is { } overlayLayer)
{
return new OverlayPopupHost(overlayLayer);
}
return new OverlayPopupHost(overlayLayer);
throw new InvalidOperationException(
"Unable to create IPopupImpl and no overlay layer is found for the target control");
}
}
}

2
src/Avalonia.Controls/TopLevel.cs

@ -402,7 +402,7 @@ namespace Avalonia.Controls
/// <returns>The TopLevel</returns>
public static TopLevel? GetTopLevel(Visual? visual)
{
return visual == null ? null : visual.VisualRoot as TopLevel;
return visual?.VisualRoot as TopLevel;
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

3
src/Avalonia.Diagnostics/Diagnostics/KeyGestureExtesions.cs

@ -3,10 +3,9 @@ using Avalonia.Input.Raw;
namespace Avalonia.Diagnostics
{
static class KeyGestureExtesions
internal static class KeyGestureExtesions
{
public static bool Matches(this KeyGesture gesture, RawKeyEventArgs keyEvent) =>
keyEvent != null &&
(KeyModifiers)(keyEvent.Modifiers & RawInputModifiers.KeyboardMask) == gesture.KeyModifiers &&
ResolveNumPadOperationKey(keyEvent.Key) == ResolveNumPadOperationKey(gesture.Key);

Loading…
Cancel
Save