Browse Source

Merge pull request #9590 from robloo/default-members

Standardize Default Members
pull/9694/head
Max Katz 4 years ago
committed by GitHub
parent
commit
3ab5159960
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      samples/ControlCatalog/Pages/ImagePage.xaml.cs
  2. 9
      src/Avalonia.Base/CornerRadius.cs
  3. 11
      src/Avalonia.Base/Media/BoxShadow.cs
  4. 4
      src/Avalonia.Base/Media/BoxShadows.cs
  5. 2
      src/Avalonia.Base/Media/FormattedText.cs
  6. 4
      src/Avalonia.Base/Media/Geometry.cs
  7. 2
      src/Avalonia.Base/Media/GeometryDrawing.cs
  8. 2
      src/Avalonia.Base/Media/GlyphRunDrawing.cs
  9. 2
      src/Avalonia.Base/Media/ImageDrawing.cs
  10. 4
      src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
  11. 4
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  12. 15
      src/Avalonia.Base/PixelRect.cs
  13. 21
      src/Avalonia.Base/Rect.cs
  14. 2
      src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs
  15. 2
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionDrawListVisual.cs
  16. 8
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs
  17. 8
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual.cs
  18. 4
      src/Avalonia.Base/Rendering/DeferredRenderer.cs
  19. 5
      src/Avalonia.Base/Rendering/DirtyRects.cs
  20. 4
      src/Avalonia.Base/Rendering/ImmediateRenderer.cs
  21. 2
      src/Avalonia.Base/Rendering/SceneGraph/BitmapBlendModeNode.cs
  22. 2
      src/Avalonia.Base/Rendering/SceneGraph/ClipNode.cs
  23. 2
      src/Avalonia.Base/Rendering/SceneGraph/GeometryClipNode.cs
  24. 4
      src/Avalonia.Base/Rendering/SceneGraph/OpacityMaskNode.cs
  25. 2
      src/Avalonia.Base/Rendering/SceneGraph/OpacityNode.cs
  26. 6
      src/Avalonia.Base/Rendering/SceneGraph/SceneBuilder.cs
  27. 8
      src/Avalonia.Base/Size.cs
  28. 17
      src/Avalonia.Base/Thickness.cs
  29. 4
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  30. 4
      src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs
  31. 2
      src/Avalonia.Controls.DataGrid/Primitives/DataGridCellsPresenter.cs
  32. 2
      src/Avalonia.Controls.DataGrid/Primitives/DataGridColumnHeadersPresenter.cs
  33. 2
      src/Avalonia.Controls.DataGrid/Primitives/DataGridDetailsPresenter.cs
  34. 4
      src/Avalonia.Controls/Flyouts/FlyoutBase.cs
  35. 10
      src/Avalonia.Controls/LayoutTransformControl.cs
  36. 2
      src/Avalonia.Controls/NativeControlHost.cs
  37. 6
      src/Avalonia.Controls/Presenters/ItemsPresenter.cs
  38. 2
      src/Avalonia.Controls/Primitives/PopupPositioning/ManagedPopupPositioner.cs
  39. 4
      src/Avalonia.Controls/Repeater/ViewportManager.cs
  40. 2
      src/Avalonia.Controls/Shapes/Shape.cs
  41. 2
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  42. 2
      src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs
  43. 4
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  44. 2
      src/Skia/Avalonia.Skia/GeometryImpl.cs
  45. 2
      src/Skia/Avalonia.Skia/StreamGeometryImpl.cs
  46. 2
      tests/Avalonia.Base.UnitTests/RectTests.cs
  47. 4
      tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs
  48. 4
      tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs
  49. 4
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs
  50. 2
      tests/Avalonia.Controls.UnitTests/Shapes/RectangleTests.cs

2
samples/ControlCatalog/Pages/ImagePage.xaml.cs

@ -70,7 +70,7 @@ namespace ControlCatalog.Pages
3 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, 0), cropSize), 3 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, 0), cropSize),
4 => new PixelRect(new PixelPoint(0, bitmapHeight - cropSize.Height), cropSize), 4 => new PixelRect(new PixelPoint(0, bitmapHeight - cropSize.Height), cropSize),
5 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, bitmapHeight - cropSize.Height), cropSize), 5 => new PixelRect(new PixelPoint(bitmapWidth - cropSize.Width, bitmapHeight - cropSize.Height), cropSize),
_ => PixelRect.Empty _ => default
}; };
} }

9
src/Avalonia.Base/CornerRadius.cs

@ -61,9 +61,13 @@ namespace Avalonia
public double BottomLeft { get; } public double BottomLeft { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether all corner radii are set to 0. /// Gets a value indicating whether the instance has default values (all corner radii are set to 0).
/// </summary> /// </summary>
public bool IsEmpty => TopLeft.Equals(0) && IsUniform; public bool IsDefault => TopLeft == 0 && TopRight == 0 && BottomLeft == 0 && BottomRight == 0;
/// <inheritdoc cref="IsDefault"/>
[Obsolete("Use IsDefault instead.")]
public bool IsEmpty => IsDefault;
/// <summary> /// <summary>
/// Gets a value indicating whether all corner radii are equal. /// Gets a value indicating whether all corner radii are equal.
@ -79,7 +83,6 @@ namespace Avalonia
{ {
// ReSharper disable CompareOfFloatsByEqualityOperator // ReSharper disable CompareOfFloatsByEqualityOperator
return TopLeft == other.TopLeft && return TopLeft == other.TopLeft &&
TopRight == other.TopRight && TopRight == other.TopRight &&
BottomRight == other.BottomRight && BottomRight == other.BottomRight &&
BottomLeft == other.BottomLeft; BottomLeft == other.BottomLeft;

11
src/Avalonia.Base/Media/BoxShadow.cs

@ -45,7 +45,14 @@ namespace Avalonia.Media
} }
} }
public bool IsEmpty => OffsetX == 0 && OffsetY == 0 && Blur == 0 && Spread == 0; /// <summary>
/// Gets a value indicating whether the instance has default values.
/// </summary>
public bool IsDefault => OffsetX == 0 && OffsetY == 0 && Blur == 0 && Spread == 0;
/// <inheritdoc cref="IsDefault"/>
[Obsolete("Use IsDefault instead.")]
public bool IsEmpty => IsDefault;
private readonly static char[] s_Separator = new char[] { ' ', '\t' }; private readonly static char[] s_Separator = new char[] { ' ', '\t' };
@ -82,7 +89,7 @@ namespace Avalonia.Media
{ {
var sb = StringBuilderCache.Acquire(); var sb = StringBuilderCache.Acquire();
if (IsEmpty) if (IsDefault)
{ {
return "none"; return "none";
} }

4
src/Avalonia.Base/Media/BoxShadows.cs

@ -21,7 +21,7 @@ namespace Avalonia.Media
{ {
_first = shadow; _first = shadow;
_list = null; _list = null;
Count = _first.IsEmpty ? 0 : 1; Count = _first.IsDefault ? 0 : 1;
} }
public BoxShadows(BoxShadow first, BoxShadow[] rest) public BoxShadows(BoxShadow first, BoxShadow[] rest)
@ -120,7 +120,7 @@ namespace Avalonia.Media
get get
{ {
foreach(var boxShadow in this) foreach(var boxShadow in this)
if (!boxShadow.IsEmpty && boxShadow.IsInset) if (!boxShadow.IsDefault && boxShadow.IsInset)
return true; return true;
return false; return false;
} }

2
src/Avalonia.Base/Media/FormattedText.cs

@ -1379,7 +1379,7 @@ namespace Avalonia.Media
} }
} }
if (accumulatedBounds?.PlatformImpl == null || accumulatedBounds.PlatformImpl.Bounds.IsEmpty) if (accumulatedBounds?.PlatformImpl == null || accumulatedBounds.PlatformImpl.Bounds.IsDefault)
{ {
return null; return null;
} }

4
src/Avalonia.Base/Media/Geometry.cs

@ -30,7 +30,7 @@ namespace Avalonia.Media
/// <summary> /// <summary>
/// Gets the geometry's bounding rectangle. /// Gets the geometry's bounding rectangle.
/// </summary> /// </summary>
public Rect Bounds => PlatformImpl?.Bounds ?? Rect.Empty; public Rect Bounds => PlatformImpl?.Bounds ?? default;
/// <summary> /// <summary>
/// Gets the platform-specific implementation of the geometry. /// Gets the platform-specific implementation of the geometry.
@ -84,7 +84,7 @@ namespace Avalonia.Media
/// </summary> /// </summary>
/// <param name="pen">The stroke thickness.</param> /// <param name="pen">The stroke thickness.</param>
/// <returns>The bounding rectangle.</returns> /// <returns>The bounding rectangle.</returns>
public Rect GetRenderBounds(IPen pen) => PlatformImpl?.GetRenderBounds(pen) ?? Rect.Empty; public Rect GetRenderBounds(IPen pen) => PlatformImpl?.GetRenderBounds(pen) ?? default;
/// <summary> /// <summary>
/// Indicates whether the geometry's fill contains the specified point. /// Indicates whether the geometry's fill contains the specified point.

2
src/Avalonia.Base/Media/GeometryDrawing.cs

@ -69,7 +69,7 @@ namespace Avalonia.Media
public override Rect GetBounds() public override Rect GetBounds()
{ {
IPen pen = Pen ?? s_boundsPen; IPen pen = Pen ?? s_boundsPen;
return Geometry?.GetRenderBounds(pen) ?? Rect.Empty; return Geometry?.GetRenderBounds(pen) ?? default;
} }
} }
} }

2
src/Avalonia.Base/Media/GlyphRunDrawing.cs

@ -32,7 +32,7 @@
public override Rect GetBounds() public override Rect GetBounds()
{ {
return GlyphRun != null ? new Rect(GlyphRun.Size) : Rect.Empty; return GlyphRun != null ? new Rect(GlyphRun.Size) : default;
} }
} }
} }

2
src/Avalonia.Base/Media/ImageDrawing.cs

@ -42,7 +42,7 @@ namespace Avalonia.Media
var imageSource = ImageSource; var imageSource = ImageSource;
var rect = Rect; var rect = Rect;
if (imageSource is object && !rect.IsEmpty) if (imageSource is object && !rect.IsDefault)
{ {
context.DrawImage(imageSource, rect); context.DrawImage(imageSource, rect);
} }

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

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

4
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@ -532,7 +532,7 @@ namespace Avalonia.Media.TextFormatting
var startX = Start; var startX = Start;
double currentWidth = 0; double currentWidth = 0;
var currentRect = Rect.Empty; var currentRect = default(Rect);
TextRunBounds lastRunBounds = default; TextRunBounds lastRunBounds = default;
@ -748,7 +748,7 @@ namespace Avalonia.Media.TextFormatting
var startX = WidthIncludingTrailingWhitespace; var startX = WidthIncludingTrailingWhitespace;
double currentWidth = 0; double currentWidth = 0;
var currentRect = Rect.Empty; var currentRect = default(Rect);
for (var index = TextRuns.Count - 1; index >= 0; index--) for (var index = TextRuns.Count - 1; index >= 0; index--)
{ {

15
src/Avalonia.Base/PixelRect.cs

@ -12,6 +12,7 @@ namespace Avalonia
/// <summary> /// <summary>
/// An empty rectangle. /// An empty rectangle.
/// </summary> /// </summary>
[Obsolete("Use the default keyword instead.")]
public static readonly PixelRect Empty = default; public static readonly PixelRect Empty = default;
/// <summary> /// <summary>
@ -133,9 +134,13 @@ namespace Avalonia
public PixelPoint Center => new PixelPoint(X + (Width / 2), Y + (Height / 2)); public PixelPoint Center => new PixelPoint(X + (Width / 2), Y + (Height / 2));
/// <summary> /// <summary>
/// Gets a value that indicates whether the rectangle is empty. /// Gets a value indicating whether the instance has default values (the rectangle is empty).
/// </summary> /// </summary>
public bool IsEmpty => Width == 0 && Height == 0; public bool IsDefault => Width == 0 && Height == 0;
/// <inheritdoc cref="IsDefault"/>
[Obsolete("Use IsDefault instead.")]
public bool IsEmpty => IsDefault;
/// <summary> /// <summary>
/// Checks for equality between two <see cref="PixelRect"/>s. /// Checks for equality between two <see cref="PixelRect"/>s.
@ -257,7 +262,7 @@ namespace Avalonia
} }
else else
{ {
return Empty; return default;
} }
} }
@ -290,11 +295,11 @@ namespace Avalonia
/// <returns>The union.</returns> /// <returns>The union.</returns>
public PixelRect Union(PixelRect rect) public PixelRect Union(PixelRect rect)
{ {
if (IsEmpty) if (IsDefault)
{ {
return rect; return rect;
} }
else if (rect.IsEmpty) else if (rect.IsDefault)
{ {
return this; return this;
} }

21
src/Avalonia.Base/Rect.cs

@ -18,7 +18,8 @@ namespace Avalonia
/// <summary> /// <summary>
/// An empty rectangle. /// An empty rectangle.
/// </summary> /// </summary>
public static readonly Rect Empty = default(Rect); [Obsolete("Use the default keyword instead.")]
public static readonly Rect Empty = default;
/// <summary> /// <summary>
/// The X position. /// The X position.
@ -169,12 +170,16 @@ namespace Avalonia
public Point Center => new Point(_x + (_width / 2), _y + (_height / 2)); public Point Center => new Point(_x + (_width / 2), _y + (_height / 2));
/// <summary> /// <summary>
/// Gets a value that indicates whether the rectangle is empty. /// Gets a value indicating whether the instance has default values (the rectangle is empty).
/// </summary> /// </summary>
// ReSharper disable CompareOfFloatsByEqualityOperator // ReSharper disable CompareOfFloatsByEqualityOperator
public bool IsEmpty => _width == 0 && _height == 0; public bool IsDefault => _width == 0 && _height == 0;
// ReSharper restore CompareOfFloatsByEqualityOperator // ReSharper restore CompareOfFloatsByEqualityOperator
/// <inheritdoc cref="IsDefault"/>
[Obsolete("Use IsDefault instead.")]
public bool IsEmpty => IsDefault;
/// <summary> /// <summary>
/// Checks for equality between two <see cref="Rect"/>s. /// Checks for equality between two <see cref="Rect"/>s.
/// </summary> /// </summary>
@ -390,7 +395,7 @@ namespace Avalonia
} }
else else
{ {
return Empty; return default;
} }
} }
@ -457,13 +462,13 @@ namespace Avalonia
/// </remarks> /// </remarks>
public Rect Normalize() public Rect Normalize()
{ {
Rect rect = this; Rect rect = this;
if(double.IsNaN(rect.Right) || double.IsNaN(rect.Bottom) || if(double.IsNaN(rect.Right) || double.IsNaN(rect.Bottom) ||
double.IsNaN(rect.X) || double.IsNaN(rect.Y) || double.IsNaN(rect.X) || double.IsNaN(rect.Y) ||
double.IsNaN(Height) || double.IsNaN(Width)) double.IsNaN(Height) || double.IsNaN(Width))
{ {
return Rect.Empty; return default;
} }
if (rect.Width < 0) if (rect.Width < 0)
@ -493,11 +498,11 @@ namespace Avalonia
/// <returns>The union.</returns> /// <returns>The union.</returns>
public Rect Union(Rect rect) public Rect Union(Rect rect)
{ {
if (IsEmpty) if (IsDefault)
{ {
return rect; return rect;
} }
else if (rect.IsEmpty) else if (rect.IsDefault)
{ {
return this; return this;
} }

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

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

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

@ -37,7 +37,7 @@ internal class ServerCompositionDrawListVisual : ServerCompositionContainerVisua
{ {
if (_contentBounds == null) if (_contentBounds == null)
{ {
var rect = Rect.Empty; var rect = default(Rect);
if(_renderCommands!=null) if(_renderCommands!=null)
foreach (var cmd in _renderCommands) foreach (var cmd in _renderCommands)
rect = rect.Union(cmd.Item.Bounds); rect = rect.Union(cmd.Item.Bounds);

8
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs

@ -90,7 +90,7 @@ namespace Avalonia.Rendering.Composition.Server
Compositor.UpdateServerTime(); Compositor.UpdateServerTime();
if(_dirtyRect.IsEmpty && !_redrawRequested) if(_dirtyRect.IsDefault && !_redrawRequested)
return; return;
Revision++; Revision++;
@ -119,7 +119,7 @@ namespace Avalonia.Rendering.Composition.Server
_dirtyRect = new Rect(0, 0, layerSize.Width, layerSize.Height); _dirtyRect = new Rect(0, 0, layerSize.Width, layerSize.Height);
} }
if (!_dirtyRect.IsEmpty) if (!_dirtyRect.IsDefault)
{ {
var visualBrushHelper = new CompositorDrawingContextProxy.VisualBrushRenderer(); var visualBrushHelper = new CompositorDrawingContextProxy.VisualBrushRenderer();
using (var context = _layer.CreateDrawingContext(visualBrushHelper)) using (var context = _layer.CreateDrawingContext(visualBrushHelper))
@ -162,7 +162,7 @@ namespace Avalonia.Rendering.Composition.Server
} }
RenderedVisuals = 0; RenderedVisuals = 0;
_dirtyRect = Rect.Empty; _dirtyRect = default;
} }
} }
@ -181,7 +181,7 @@ namespace Avalonia.Rendering.Composition.Server
public void AddDirtyRect(Rect rect) public void AddDirtyRect(Rect rect)
{ {
if(rect.IsEmpty) if(rect.IsDefault)
return; return;
var snapped = SnapToDevicePixels(rect, Scaling); var snapped = SnapToDevicePixels(rect, Scaling);
DebugEvents?.RectInvalidated(rect); DebugEvents?.RectInvalidated(rect);

8
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual.cs

@ -37,7 +37,7 @@ namespace Avalonia.Rendering.Composition.Server
return; return;
currentTransformedClip = currentTransformedClip.Intersect(_combinedTransformedClipBounds); currentTransformedClip = currentTransformedClip.Intersect(_combinedTransformedClipBounds);
if(currentTransformedClip.IsEmpty) if(currentTransformedClip.IsDefault)
return; return;
Root!.RenderedVisuals++; Root!.RenderedVisuals++;
@ -139,7 +139,7 @@ namespace Avalonia.Rendering.Composition.Server
if (ownBounds != _oldOwnContentBounds || positionChanged) if (ownBounds != _oldOwnContentBounds || positionChanged)
{ {
_oldOwnContentBounds = ownBounds; _oldOwnContentBounds = ownBounds;
if (ownBounds.IsEmpty) if (ownBounds.IsDefault)
TransformedOwnContentBounds = default; TransformedOwnContentBounds = default;
else else
TransformedOwnContentBounds = TransformedOwnContentBounds =
@ -163,7 +163,7 @@ namespace Avalonia.Rendering.Composition.Server
EffectiveOpacity = Opacity * (Parent?.EffectiveOpacity ?? 1); EffectiveOpacity = Opacity * (Parent?.EffectiveOpacity ?? 1);
IsVisibleInFrame = _parent?.IsVisibleInFrame != false && Visible && EffectiveOpacity > 0.04 && !_isBackface && IsVisibleInFrame = _parent?.IsVisibleInFrame != false && Visible && EffectiveOpacity > 0.04 && !_isBackface &&
!_combinedTransformedClipBounds.IsEmpty; !_combinedTransformedClipBounds.IsDefault;
if (wasVisible != IsVisibleInFrame || positionChanged) if (wasVisible != IsVisibleInFrame || positionChanged)
{ {
@ -192,7 +192,7 @@ namespace Avalonia.Rendering.Composition.Server
void AddDirtyRect(Rect rc) void AddDirtyRect(Rect rc)
{ {
if(rc == Rect.Empty) if(rc == default)
return; return;
Root?.AddDirtyRect(rc); Root?.AddDirtyRect(rc);
} }

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

@ -309,7 +309,7 @@ namespace Avalonia.Rendering
/// <inheritdoc/> /// <inheritdoc/>
Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush) Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)
{ {
return TryGetChildScene(_currentDraw)?.Size ?? Size.Empty; return TryGetChildScene(_currentDraw)?.Size ?? default;
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -461,7 +461,7 @@ namespace Avalonia.Rendering
{ {
clipBounds = node.ClipBounds.Intersect(clipBounds); clipBounds = node.ClipBounds.Intersect(clipBounds);
if (!clipBounds.IsEmpty && node.Opacity > 0) if (!clipBounds.IsDefault && node.Opacity > 0)
{ {
var isLayerRoot = node.Visual == layer; var isLayerRoot = node.Visual == layer;

5
src/Avalonia.Base/Rendering/DirtyRects.cs

@ -10,6 +10,9 @@ namespace Avalonia.Rendering
{ {
private List<Rect> _rects = new List<Rect>(); private List<Rect> _rects = new List<Rect>();
/// <summary>
/// Gets a value indicating whether the collection of dirty rectangles is empty.
/// </summary>
public bool IsEmpty => _rects.Count == 0; public bool IsEmpty => _rects.Count == 0;
/// <summary> /// <summary>
@ -27,7 +30,7 @@ namespace Avalonia.Rendering
/// </remarks> /// </remarks>
public void Add(Rect rect) public void Add(Rect rect)
{ {
if (!rect.IsEmpty) if (!rect.IsDefault)
{ {
for (var i = 0; i < _rects.Count; ++i) for (var i = 0; i < _rects.Count; ++i)
{ {

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

@ -136,7 +136,7 @@ namespace Avalonia.Rendering
/// <inheritdoc/> /// <inheritdoc/>
public void AddDirty(Visual visual) public void AddDirty(Visual visual)
{ {
if (visual.Bounds != Rect.Empty) if (!visual.Bounds.IsDefault)
{ {
var m = visual.TransformToVisual(_root); var m = visual.TransformToVisual(_root);
@ -201,7 +201,7 @@ namespace Avalonia.Rendering
Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush) Size IVisualBrushRenderer.GetRenderTargetSize(IVisualBrush brush)
{ {
(brush.Visual as IVisualBrushInitialize)?.EnsureInitialized(); (brush.Visual as IVisualBrushInitialize)?.EnsureInitialized();
return brush.Visual?.Bounds.Size ?? Size.Empty; return brush.Visual?.Bounds.Size ?? default;
} }
/// <inheritdoc/> /// <inheritdoc/>

2
src/Avalonia.Base/Rendering/SceneGraph/BitmapBlendModeNode.cs

@ -27,7 +27,7 @@ namespace Avalonia.Rendering.SceneGraph
} }
/// <inheritdoc/> /// <inheritdoc/>
public Rect Bounds => Rect.Empty; public Rect Bounds => default;
/// <summary> /// <summary>
/// Gets the BitmapBlend to be pushed or null if the operation represents a pop. /// Gets the BitmapBlend to be pushed or null if the operation represents a pop.

2
src/Avalonia.Base/Rendering/SceneGraph/ClipNode.cs

@ -40,7 +40,7 @@ namespace Avalonia.Rendering.SceneGraph
} }
/// <inheritdoc/> /// <inheritdoc/>
public Rect Bounds => Rect.Empty; public Rect Bounds => default;
/// <summary> /// <summary>
/// Gets the clip to be pushed or null if the operation represents a pop. /// Gets the clip to be pushed or null if the operation represents a pop.

2
src/Avalonia.Base/Rendering/SceneGraph/GeometryClipNode.cs

@ -28,7 +28,7 @@ namespace Avalonia.Rendering.SceneGraph
} }
/// <inheritdoc/> /// <inheritdoc/>
public Rect Bounds => Rect.Empty; public Rect Bounds => default;
/// <summary> /// <summary>
/// Gets the clip to be pushed or null if the operation represents a pop. /// Gets the clip to be pushed or null if the operation represents a pop.

4
src/Avalonia.Base/Rendering/SceneGraph/OpacityMaskNode.cs

@ -19,7 +19,7 @@ namespace Avalonia.Rendering.SceneGraph
/// <param name="bounds">The bounds of the mask.</param> /// <param name="bounds">The bounds of the mask.</param>
/// <param name="aux">Auxiliary data required to draw the brush.</param> /// <param name="aux">Auxiliary data required to draw the brush.</param>
public OpacityMaskNode(IBrush mask, Rect bounds, IDisposable? aux = null) public OpacityMaskNode(IBrush mask, Rect bounds, IDisposable? aux = null)
: base(Rect.Empty, Matrix.Identity, aux) : base(default, Matrix.Identity, aux)
{ {
Mask = mask.ToImmutable(); Mask = mask.ToImmutable();
MaskBounds = bounds; MaskBounds = bounds;
@ -30,7 +30,7 @@ namespace Avalonia.Rendering.SceneGraph
/// opacity mask pop. /// opacity mask pop.
/// </summary> /// </summary>
public OpacityMaskNode() public OpacityMaskNode()
: base(Rect.Empty, Matrix.Identity, null) : base(default, Matrix.Identity, null)
{ {
} }

2
src/Avalonia.Base/Rendering/SceneGraph/OpacityNode.cs

@ -26,7 +26,7 @@ namespace Avalonia.Rendering.SceneGraph
} }
/// <inheritdoc/> /// <inheritdoc/>
public Rect Bounds => Rect.Empty; public Rect Bounds => default;
/// <summary> /// <summary>
/// Gets the opacity to be pushed or null if the operation represents a pop. /// Gets the opacity to be pushed or null if the operation represents a pop.

6
src/Avalonia.Base/Rendering/SceneGraph/SceneBuilder.cs

@ -331,8 +331,8 @@ namespace Avalonia.Rendering.SceneGraph
scene.Size = newSize; scene.Size = newSize;
Rect horizontalDirtyRect = Rect.Empty; Rect horizontalDirtyRect = default;
Rect verticalDirtyRect = Rect.Empty; Rect verticalDirtyRect = default;
if (newSize.Width > oldSize.Width) if (newSize.Width > oldSize.Width)
{ {
@ -429,7 +429,7 @@ namespace Avalonia.Rendering.SceneGraph
else else
{ {
layer.OpacityMask = null; layer.OpacityMask = null;
layer.OpacityMaskRect = Rect.Empty; layer.OpacityMaskRect = default;
} }
layer.GeometryClip = node.HasAncestorGeometryClip ? layer.GeometryClip = node.HasAncestorGeometryClip ?

8
src/Avalonia.Base/Size.cs

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

17
src/Avalonia.Base/Thickness.cs

@ -97,10 +97,9 @@ namespace Avalonia
/// </summary> /// </summary>
public double Bottom => _bottom; public double Bottom => _bottom;
/// <summary> /// <inheritdoc cref="IsDefault"/>
/// Gets a value indicating whether all sides are set to 0. [Obsolete("Use IsDefault instead.")]
/// </summary> public bool IsEmpty => IsDefault;
public bool IsEmpty => Left.Equals(0) && IsUniform;
/// <summary> /// <summary>
/// Gets a value indicating whether all sides are equal. /// Gets a value indicating whether all sides are equal.
@ -292,15 +291,13 @@ namespace Avalonia
left = this._left; left = this._left;
top = this._top; top = this._top;
right = this._right; right = this._right;
bottom = this._bottom; bottom = this._bottom;
} }
/// <summary> /// <summary>
/// Gets a value indicating whether the left, top, right and bottom thickness values are zero. /// Gets a value indicating whether the instance has default values
/// (the left, top, right and bottom values are zero).
/// </summary> /// </summary>
public bool IsDefault public bool IsDefault => (_left == 0) && (_top == 0) && (_right == 0) && (_bottom == 0);
{
get { return (_left == 0) && (_top == 0) && (_right == 0) && (_bottom == 0); }
}
} }
} }

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

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

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

@ -192,14 +192,14 @@ namespace Avalonia.Controls
void OnLayoutUpdated(object sender, EventArgs e) void OnLayoutUpdated(object sender, EventArgs e)
{ {
if(!editingCheckBox.Bounds.IsEmpty) if(!editingCheckBox.Bounds.IsDefault)
{ {
editingCheckBox.LayoutUpdated -= OnLayoutUpdated; editingCheckBox.LayoutUpdated -= OnLayoutUpdated;
ProcessPointerArgs(); ProcessPointerArgs();
} }
} }
if(editingCheckBox.Bounds.IsEmpty) if(editingCheckBox.Bounds.IsDefault)
{ {
editingCheckBox.LayoutUpdated += OnLayoutUpdated; editingCheckBox.LayoutUpdated += OnLayoutUpdated;
} }

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

@ -161,7 +161,7 @@ namespace Avalonia.Controls.Primitives
{ {
// Clip // Clip
RectangleGeometry rg = new RectangleGeometry(); RectangleGeometry rg = new RectangleGeometry();
rg.Rect = Rect.Empty; rg.Rect = default;
cell.Clip = rg; cell.Clip = rg;
} }
} }

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

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

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

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

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

@ -435,7 +435,7 @@ namespace Avalonia.Controls.Primitives
{ {
Size sz; Size sz;
// Popup.Child can't be null here, it was set in ShowAtCore. // 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 // Popup may not have been shown yet. Measure content
sz = LayoutHelper.MeasureChild(Popup.Child, Size.Infinity, new Thickness()); sz = LayoutHelper.MeasureChild(Popup.Child, Size.Infinity, new Thickness());
@ -457,7 +457,7 @@ namespace Avalonia.Controls.Primitives
PopupPositioning.PopupPositionerConstraintAdjustment.SlideY; PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
} }
var trgtBnds = Target?.Bounds ?? Rect.Empty; var trgtBnds = Target?.Bounds ?? default;
switch (Placement) switch (Placement)
{ {

10
src/Avalonia.Controls/LayoutTransformControl.cs

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

2
src/Avalonia.Controls/NativeControlHost.cs

@ -145,7 +145,7 @@ namespace Avalonia.Controls
if (IsEffectivelyVisible && bounds.HasValue) if (IsEffectivelyVisible && bounds.HasValue)
{ {
if (bounds.Value.IsEmpty) if (bounds.Value.IsDefault)
return false; return false;
_attachment?.ShowInBounds(bounds.Value); _attachment?.ShowInBounds(bounds.Value);
} }

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

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

2
src/Avalonia.Controls/Primitives/PopupPositioning/ManagedPopupPositioner.cs

@ -112,7 +112,7 @@ namespace Avalonia.Controls.Primitives.PopupPositioning
?? screens.FirstOrDefault(s => s.Bounds.Intersects(parentGeometry)) ?? screens.FirstOrDefault(s => s.Bounds.Intersects(parentGeometry))
?? screens.FirstOrDefault(); ?? screens.FirstOrDefault();
if (targetScreen != null && targetScreen.WorkingArea.IsEmpty) if (targetScreen != null && targetScreen.WorkingArea.IsDefault)
{ {
return targetScreen.Bounds; return targetScreen.Bounds;
} }

4
src/Avalonia.Controls/Repeater/ViewportManager.cs

@ -465,7 +465,7 @@ namespace Avalonia.Controls
_pendingViewportShift = default; _pendingViewportShift = default;
_unshiftableShift = default; _unshiftableShift = default;
if (_visibleWindow.IsEmpty) if (_visibleWindow.IsDefault)
{ {
// We got cleared. // We got cleared.
_layoutExtent = default; _layoutExtent = default;
@ -551,7 +551,7 @@ namespace Avalonia.Controls
private void TryInvalidateMeasure() private void TryInvalidateMeasure()
{ {
// Don't invalidate measure if we have an invalid window. // Don't invalidate measure if we have an invalid window.
if (!_visibleWindow.IsEmpty) if (!_visibleWindow.IsDefault)
{ {
// We invalidate measure instead of just invalidating arrange because // We invalidate measure instead of just invalidating arrange because
// we don't invalidate measure in UpdateViewport if the view is changing to // we don't invalidate measure in UpdateViewport if the view is changing to

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

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

2
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@ -215,7 +215,7 @@ namespace Avalonia.Headless
class HeadlessStreamingGeometryStub : HeadlessGeometryStub, IStreamGeometryImpl class HeadlessStreamingGeometryStub : HeadlessGeometryStub, IStreamGeometryImpl
{ {
public HeadlessStreamingGeometryStub() : base(Rect.Empty) public HeadlessStreamingGeometryStub() : base(default)
{ {
} }

2
src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs

@ -18,7 +18,7 @@ namespace Avalonia.Browser
_onFirstRender = onFirstRender; _onFirstRender = onFirstRender;
} }
public Rect Bounds => Rect.Empty; public Rect Bounds => default;
public bool HasRendered => _hasRendered; public bool HasRendered => _hasRendered;

4
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -362,7 +362,7 @@ namespace Avalonia.Skia
foreach (var boxShadow in boxShadows) foreach (var boxShadow in boxShadows)
{ {
if (!boxShadow.IsEmpty && !boxShadow.IsInset) if (!boxShadow.IsDefault && !boxShadow.IsInset)
{ {
using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity)) using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity))
{ {
@ -418,7 +418,7 @@ namespace Avalonia.Skia
foreach (var boxShadow in boxShadows) foreach (var boxShadow in boxShadows)
{ {
if (!boxShadow.IsEmpty && boxShadow.IsInset) if (!boxShadow.IsDefault && boxShadow.IsInset)
{ {
using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity)) using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _currentOpacity))
{ {

2
src/Skia/Avalonia.Skia/GeometryImpl.cs

@ -244,7 +244,7 @@ namespace Avalonia.Skia
public void Invalidate() public void Invalidate()
{ {
CachedStrokePath?.Dispose(); CachedStrokePath?.Dispose();
CachedGeometryRenderBounds = Rect.Empty; CachedGeometryRenderBounds = default;
_cachedStrokeWidth = default(float); _cachedStrokeWidth = default(float);
} }
} }

2
src/Skia/Avalonia.Skia/StreamGeometryImpl.cs

@ -34,7 +34,7 @@ namespace Avalonia.Skia
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class. /// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
/// </summary> /// </summary>
public StreamGeometryImpl() : this(CreateEmptyPath(), Rect.Empty) public StreamGeometryImpl() : this(CreateEmptyPath(), default)
{ {
} }

2
tests/Avalonia.Base.UnitTests/RectTests.cs

@ -52,7 +52,7 @@ namespace Avalonia.Base.UnitTests
double.PositiveInfinity, double.PositiveInfinity) double.PositiveInfinity, double.PositiveInfinity)
.Normalize(); .Normalize();
Assert.Equal(Rect.Empty, result); Assert.Equal(default, result);
} }
} }
} }

4
tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs

@ -403,7 +403,7 @@ namespace Avalonia.Base.UnitTests.Rendering
root.Measure(Size.Infinity); root.Measure(Size.Infinity);
root.Arrange(new Rect(container.DesiredSize)); root.Arrange(new Rect(container.DesiredSize));
root.Renderer.Paint(Rect.Empty); root.Renderer.Paint(default);
var result = root.Renderer.HitTest(new Point(50, 150), root, null).First(); var result = root.Renderer.HitTest(new Point(50, 150), root, null).First();
Assert.Equal(item1, result); Assert.Equal(item1, result);
@ -419,7 +419,7 @@ namespace Avalonia.Base.UnitTests.Rendering
container.InvalidateArrange(); container.InvalidateArrange();
container.Arrange(new Rect(container.DesiredSize)); container.Arrange(new Rect(container.DesiredSize));
root.Renderer.Paint(Rect.Empty); root.Renderer.Paint(default);
result = root.Renderer.HitTest(new Point(50, 150), root, null).First(); result = root.Renderer.HitTest(new Point(50, 150), root, null).First();
Assert.Equal(item2, result); Assert.Equal(item2, result);

4
tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs

@ -13,9 +13,9 @@ namespace Avalonia.Base.UnitTests.Rendering.SceneGraph
[Fact] [Fact]
public void Empty_Bounds_Remain_Empty() public void Empty_Bounds_Remain_Empty()
{ {
var target = new TestDrawOperation(Rect.Empty, Matrix.Identity, null); var target = new TestDrawOperation(default, Matrix.Identity, null);
Assert.Equal(Rect.Empty, target.Bounds); Assert.Equal(default, target.Bounds);
} }
[Theory] [Theory]

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

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

2
tests/Avalonia.Controls.UnitTests/Shapes/RectangleTests.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls.UnitTests.Shapes
target.Measure(new Size(100, 100)); target.Measure(new Size(100, 100));
var geometry = Assert.IsType<RectangleGeometry>(target.RenderedGeometry); var geometry = Assert.IsType<RectangleGeometry>(target.RenderedGeometry);
Assert.Equal(Rect.Empty, geometry.Rect); Assert.Equal(default, geometry.Rect);
} }
[Fact] [Fact]

Loading…
Cancel
Save