Browse Source

Added nullable annotations.

To `ScrollContentPresenter` and `IScrollAnchorProvider`.
pull/4814/head
Steven Kirk 6 years ago
parent
commit
12d8daefaf
  1. 6
      src/Avalonia.Controls/IScrollAnchorProvider.cs
  2. 31
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

6
src/Avalonia.Controls/IScrollAnchorProvider.cs

@ -1,4 +1,6 @@
namespace Avalonia.Controls #nullable enable
namespace Avalonia.Controls
{ {
/// <summary> /// <summary>
/// Specifies a contract for a scrolling control that supports scroll anchoring. /// Specifies a contract for a scrolling control that supports scroll anchoring.
@ -8,7 +10,7 @@
/// <summary> /// <summary>
/// The currently chosen anchor element to use for scroll anchoring. /// The currently chosen anchor element to use for scroll anchoring.
/// </summary> /// </summary>
IControl CurrentAnchor { get; } IControl? CurrentAnchor { get; }
/// <summary> /// <summary>
/// Registers a control as a potential scroll anchor candidate. /// Registers a control as a potential scroll anchor candidate.

31
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -7,6 +7,8 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.VisualTree; using Avalonia.VisualTree;
#nullable enable
namespace Avalonia.Controls.Presenters namespace Avalonia.Controls.Presenters
{ {
/// <summary> /// <summary>
@ -64,11 +66,11 @@ namespace Avalonia.Controls.Presenters
private bool _arranging; private bool _arranging;
private Size _extent; private Size _extent;
private Vector _offset; private Vector _offset;
private IDisposable _logicalScrollSubscription; private IDisposable? _logicalScrollSubscription;
private Size _viewport; private Size _viewport;
private Dictionary<int, Vector> _activeLogicalGestureScrolls; private Dictionary<int, Vector>? _activeLogicalGestureScrolls;
private List<IControl> _anchorCandidates; private List<IControl>? _anchorCandidates;
private (IControl control, Rect bounds) _anchor; private (IControl? control, Rect bounds) _anchor;
/// <summary> /// <summary>
/// Initializes static members of the <see cref="ScrollContentPresenter"/> class. /// Initializes static members of the <see cref="ScrollContentPresenter"/> class.
@ -90,8 +92,6 @@ namespace Avalonia.Controls.Presenters
this.GetObservable(ChildProperty).Subscribe(UpdateScrollableSubscription); this.GetObservable(ChildProperty).Subscribe(UpdateScrollableSubscription);
} }
internal event EventHandler<VectorEventArgs> PreArrange;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the content can be scrolled horizontally. /// Gets or sets a value indicating whether the content can be scrolled horizontally.
/// </summary> /// </summary>
@ -138,7 +138,7 @@ namespace Avalonia.Controls.Presenters
} }
/// <inheritdoc/> /// <inheritdoc/>
IControl IScrollAnchorProvider.CurrentAnchor => _anchor.control; IControl? IScrollAnchorProvider.CurrentAnchor => _anchor.control;
/// <summary> /// <summary>
/// Attempts to bring a portion of the target visual into view by scrolling the content. /// Attempts to bring a portion of the target visual into view by scrolling the content.
@ -247,11 +247,6 @@ namespace Avalonia.Controls.Presenters
/// <inheritdoc/> /// <inheritdoc/>
protected override Size ArrangeOverride(Size finalSize) protected override Size ArrangeOverride(Size finalSize)
{ {
PreArrange?.Invoke(this, new VectorEventArgs
{
Vector = new Vector(finalSize.Width, finalSize.Height),
});
if (_logicalScrollSubscription != null || Child == null) if (_logicalScrollSubscription != null || Child == null)
{ {
return base.ArrangeOverride(finalSize); return base.ArrangeOverride(finalSize);
@ -350,7 +345,7 @@ namespace Avalonia.Controls.Presenters
{ {
var logicalUnits = delta.Y / LogicalScrollItemSize; var logicalUnits = delta.Y / LogicalScrollItemSize;
delta = delta.WithY(delta.Y - logicalUnits * LogicalScrollItemSize); delta = delta.WithY(delta.Y - logicalUnits * LogicalScrollItemSize);
dy = logicalUnits * scrollable.ScrollSize.Height; dy = logicalUnits * scrollable!.ScrollSize.Height;
} }
else else
dy = delta.Y; dy = delta.Y;
@ -368,7 +363,7 @@ namespace Avalonia.Controls.Presenters
{ {
var logicalUnits = delta.X / LogicalScrollItemSize; var logicalUnits = delta.X / LogicalScrollItemSize;
delta = delta.WithX(delta.X - logicalUnits * LogicalScrollItemSize); delta = delta.WithX(delta.X - logicalUnits * LogicalScrollItemSize);
dx = logicalUnits * scrollable.ScrollSize.Width; dx = logicalUnits * scrollable!.ScrollSize.Width;
} }
else else
dx = delta.X; dx = delta.X;
@ -405,7 +400,7 @@ namespace Avalonia.Controls.Presenters
if (Extent.Height > Viewport.Height) if (Extent.Height > Viewport.Height)
{ {
double height = isLogical ? scrollable.ScrollSize.Height : 50; double height = isLogical ? scrollable!.ScrollSize.Height : 50;
y += -e.Delta.Y * height; y += -e.Delta.Y * height;
y = Math.Max(y, 0); y = Math.Max(y, 0);
y = Math.Min(y, Extent.Height - Viewport.Height); y = Math.Min(y, Extent.Height - Viewport.Height);
@ -413,7 +408,7 @@ namespace Avalonia.Controls.Presenters
if (Extent.Width > Viewport.Width) if (Extent.Width > Viewport.Width)
{ {
double width = isLogical ? scrollable.ScrollSize.Width : 50; double width = isLogical ? scrollable!.ScrollSize.Width : 50;
x += -e.Delta.X * width; x += -e.Delta.X * width;
x = Math.Max(x, 0); x = Math.Max(x, 0);
x = Math.Min(x, Extent.Width - Viewport.Width); x = Math.Min(x, Extent.Width - Viewport.Width);
@ -441,7 +436,7 @@ namespace Avalonia.Controls.Presenters
private void ChildChanged(AvaloniaPropertyChangedEventArgs e) private void ChildChanged(AvaloniaPropertyChangedEventArgs e)
{ {
UpdateScrollableSubscription((IControl)e.NewValue); UpdateScrollableSubscription((IControl?)e.NewValue);
if (e.OldValue != null) if (e.OldValue != null)
{ {
@ -449,7 +444,7 @@ namespace Avalonia.Controls.Presenters
} }
} }
private void UpdateScrollableSubscription(IControl child) private void UpdateScrollableSubscription(IControl? child)
{ {
var scrollable = child as ILogicalScrollable; var scrollable = child as ILogicalScrollable;

Loading…
Cancel
Save