Browse Source

Standardize Default members in Size

pull/9590/head
robloo 4 years ago
parent
commit
932d52dcf3
  1. 2
      src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
  2. 2
      src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs
  3. 2
      src/Avalonia.Base/Rendering/DeferredRenderer.cs
  4. 2
      src/Avalonia.Base/Rendering/ImmediateRenderer.cs
  5. 8
      src/Avalonia.Base/Size.cs
  6. 4
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  7. 2
      src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs
  8. 2
      src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs
  9. 2
      src/Avalonia.Controls/Flyouts/FlyoutBase.cs
  10. 10
      src/Avalonia.Controls/LayoutTransformControl.cs
  11. 6
      src/Avalonia.Controls/Presenters/ItemsPresenter.cs
  12. 2
      src/Avalonia.Controls/Shapes/Shape.cs
  13. 2
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

2
src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs

@ -78,7 +78,7 @@ namespace Avalonia.Media.Imaging
get
{
if (Source is not IBitmap bmp)
return Size.Empty;
return default;
if (SourceRect.IsDefault)
return Source.Size;
return SourceRect.Size.ToSizeWithDpi(bmp.Dpi);

2
src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs

@ -163,7 +163,7 @@ internal class CompositorDrawingContextProxy : IDrawingContextImpl, IDrawingCont
public CompositionDrawList? VisualBrushDrawList { get; set; }
public Size GetRenderTargetSize(IVisualBrush brush)
{
return VisualBrushDrawList?.Size ?? Size.Empty;
return VisualBrushDrawList?.Size ?? default;
}
public void RenderVisualBrush(IDrawingContextImpl context, IVisualBrush brush)

2
src/Avalonia.Base/Rendering/DeferredRenderer.cs

@ -277,7 +277,7 @@ namespace Avalonia.Rendering
/// <inheritdoc/>
Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)
{
return TryGetChildScene(_currentDraw)?.Size ?? Size.Empty;
return TryGetChildScene(_currentDraw)?.Size ?? default;
}
/// <inheritdoc/>

2
src/Avalonia.Base/Rendering/ImmediateRenderer.cs

@ -189,7 +189,7 @@ namespace Avalonia.Rendering
Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)
{
(brush.Visual as IVisualBrushInitialize)?.EnsureInitialized();
return brush.Visual?.Bounds.Size ?? Size.Empty;
return brush.Visual?.Bounds.Size ?? default;
}
/// <inheritdoc/>

8
src/Avalonia.Base/Size.cs

@ -28,8 +28,9 @@ namespace Avalonia
public static readonly Size Infinity = new Size(double.PositiveInfinity, double.PositiveInfinity);
/// <summary>
/// A size representing zero
/// A size representing zero.
/// </summary>
[Obsolete("Use the default keyword instead.")]
public static readonly Size Empty = new Size(0, 0);
/// <summary>
@ -309,9 +310,6 @@ namespace Avalonia
/// <summary>
/// Gets a value indicating whether the Width and Height values are zero.
/// </summary>
public bool IsDefault
{
get { return (_width == 0) && (_height == 0); }
}
public bool IsDefault => (_width == 0) && (_height == 0);
}
}

4
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -1124,7 +1124,7 @@ namespace Avalonia.Controls
EnsureColumnHeadersVisibility();
if (!newValueCols)
{
_columnHeadersPresenter.Measure(Size.Empty);
_columnHeadersPresenter.Measure(default(Size));
}
else
{
@ -1165,7 +1165,7 @@ namespace Avalonia.Controls
_topLeftCornerHeader.IsVisible = newValueRows && newValueCols;
if (_topLeftCornerHeader.IsVisible)
{
_topLeftCornerHeader.Measure(Size.Empty);
_topLeftCornerHeader.Measure(default(Size));
}
}

2
src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs

@ -305,7 +305,7 @@ namespace Avalonia.Controls.Primitives
}
if (!OwningGrid.AreColumnHeadersVisible)
{
return Size.Empty;
return default;
}
double height = OwningGrid.ColumnHeaderHeight;
bool autoSizeHeight;

2
src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs

@ -112,7 +112,7 @@ namespace Avalonia.Controls.Primitives
{
if (OwningGrid == null || Children.Count == 0)
{
return Size.Empty;
return default;
}
double desiredWidth = OwningGrid.AreRowDetailsFrozen ?

2
src/Avalonia.Controls/Flyouts/FlyoutBase.cs

@ -435,7 +435,7 @@ namespace Avalonia.Controls.Primitives
{
Size sz;
// Popup.Child can't be null here, it was set in ShowAtCore.
if (Popup.Child!.DesiredSize == Size.Empty)
if (Popup.Child!.DesiredSize.IsDefault)
{
// Popup may not have been shown yet. Measure content
sz = LayoutHelper.MeasureChild(Popup.Child, Size.Infinity, new Thickness());

10
src/Avalonia.Controls/LayoutTransformControl.cs

@ -91,7 +91,7 @@ namespace Avalonia.Controls
arrangedsize = TransformRoot.Bounds.Size;
// This is the first opportunity under Silverlight to find out the Child's true DesiredSize
if (IsSizeSmaller(finalSizeTransformed, arrangedsize) && (Size.Empty == _childActualSize))
if (IsSizeSmaller(finalSizeTransformed, arrangedsize) && _childActualSize.IsDefault)
{
//// Unfortunately, all the work so far is invalid because the wrong DesiredSize was used
//// Make a note of the actual DesiredSize
@ -102,7 +102,7 @@ namespace Avalonia.Controls
else
{
// Clear the "need to measure/arrange again" flag
_childActualSize = Size.Empty;
_childActualSize = default;
}
// Return result to perform the transformation
@ -122,7 +122,7 @@ namespace Avalonia.Controls
}
Size measureSize;
if (_childActualSize == Size.Empty)
if (_childActualSize.IsDefault)
{
// Determine the largest size after the transformation
measureSize = ComputeLargestTransformedSize(availableSize);
@ -206,7 +206,7 @@ namespace Avalonia.Controls
/// <summary>
/// Actual DesiredSize of Child element (the value it returned from its MeasureOverride method).
/// </summary>
private Size _childActualSize = Size.Empty;
private Size _childActualSize = default;
/// <summary>
/// RenderTransform/MatrixTransform applied to TransformRoot.
@ -281,7 +281,7 @@ namespace Avalonia.Controls
private Size ComputeLargestTransformedSize(Size arrangeBounds)
{
// Computed largest transformed size
Size computedSize = Size.Empty;
Size computedSize = default;
// Detect infinite bounds and constrain the scenario
bool infiniteWidth = double.IsInfinity(arrangeBounds.Width);

6
src/Avalonia.Controls/Presenters/ItemsPresenter.cs

@ -77,7 +77,7 @@ namespace Avalonia.Controls.Presenters
}
/// <inheritdoc/>
Size IScrollable.Extent => Virtualizer?.Extent ?? Size.Empty;
Size IScrollable.Extent => Virtualizer?.Extent ?? default;
/// <inheritdoc/>
Vector IScrollable.Offset
@ -136,12 +136,12 @@ namespace Avalonia.Controls.Presenters
/// <inheritdoc/>
protected override Size MeasureOverride(Size availableSize)
{
return Virtualizer?.MeasureOverride(availableSize) ?? Size.Empty;
return Virtualizer?.MeasureOverride(availableSize) ?? default;
}
protected override Size ArrangeOverride(Size finalSize)
{
return Virtualizer?.ArrangeOverride(finalSize) ?? Size.Empty;
return Virtualizer?.ArrangeOverride(finalSize) ?? default;
}
/// <inheritdoc/>

2
src/Avalonia.Controls/Shapes/Shape.cs

@ -292,7 +292,7 @@ namespace Avalonia.Controls.Shapes
return finalSize;
}
return Size.Empty;
return default;
}
internal static (Size size, Matrix transform) CalculateSizeAndTransform(Size availableSize, Rect shapeBounds, Stretch Stretch)

2
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

@ -569,7 +569,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var target = CreateTarget(itemCount: 10);
var items = (IList<string>)target.Items;
target.ApplyTemplate();
target.Measure(Size.Empty);
target.Measure(default(Size));
target.Arrange(default);
// Check for issue #591: this should not throw.

Loading…
Cancel
Save