Browse Source

Merge pull request #10678 from robloo/default-members-2

Remove Default/Empty Members
pull/10689/head
Steven Kirk 4 years ago
committed by GitHub
parent
commit
44c2025a3d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/Avalonia.Base/CornerRadius.cs
  2. 2
      src/Avalonia.Base/Input/GestureRecognizers/VelocityTracker.cs
  3. 11
      src/Avalonia.Base/Media/BoxShadow.cs
  4. 4
      src/Avalonia.Base/Media/BoxShadows.cs
  5. 5
      src/Avalonia.Base/Media/FontFamily.cs
  6. 5
      src/Avalonia.Base/Media/FormattedText.cs
  7. 2
      src/Avalonia.Base/Media/ImageDrawing.cs
  8. 2
      src/Avalonia.Base/Media/Imaging/CroppedBitmap.cs
  9. 19
      src/Avalonia.Base/PixelRect.cs
  10. 8
      src/Avalonia.Base/Point.cs
  11. 34
      src/Avalonia.Base/Rect.cs
  12. 12
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs
  13. 55
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual.cs
  14. 2
      src/Avalonia.Base/Rendering/DirtyRects.cs
  15. 11
      src/Avalonia.Base/Size.cs
  16. 10
      src/Avalonia.Base/Thickness.cs
  17. 8
      src/Avalonia.Base/Vector.cs
  18. 8
      src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs
  19. 4
      src/Avalonia.Controls.ItemsRepeater/Controls/ViewportManager.cs
  20. 2
      src/Avalonia.Controls/BorderVisual.cs
  21. 2
      src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs
  22. 4
      src/Avalonia.Controls/LayoutTransformControl.cs
  23. 2
      src/Avalonia.Controls/NativeControlHost.cs
  24. 3
      src/Avalonia.Controls/Primitives/PopupPositioning/ManagedPopupPositioner.cs
  25. 3
      src/Avalonia.Controls/VirtualizingStackPanel.cs
  26. 4
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs

9
src/Avalonia.Base/CornerRadius.cs

@ -60,15 +60,6 @@ namespace Avalonia
/// </summary> /// </summary>
public double BottomLeft { get; } public double BottomLeft { get; }
/// <summary>
/// Gets a value indicating whether the instance has default values (all corner radii are set to 0).
/// </summary>
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.
/// </summary> /// </summary>

2
src/Avalonia.Base/Input/GestureRecognizers/VelocityTracker.cs

@ -180,7 +180,7 @@ namespace Avalonia.Input.GestureRecognizers
internal Velocity GetVelocity() internal Velocity GetVelocity()
{ {
var estimate = GetVelocityEstimate(); var estimate = GetVelocityEstimate();
if (estimate == null || estimate.PixelsPerSecond.IsDefault) if (estimate == null || estimate.PixelsPerSecond == default(Vector))
{ {
return new Velocity(Vector.Zero); return new Velocity(Vector.Zero);
} }

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

@ -45,15 +45,6 @@ namespace Avalonia.Media
} }
} }
/// <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' };
struct ArrayReader struct ArrayReader
@ -89,7 +80,7 @@ namespace Avalonia.Media
{ {
var sb = StringBuilderCache.Acquire(); var sb = StringBuilderCache.Acquire();
if (IsDefault) if (this == default)
{ {
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.IsDefault ? 0 : 1; Count = _first == default ? 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.IsDefault && boxShadow.IsInset) if (boxShadow != default && boxShadow.IsInset)
return true; return true;
return false; return false;
} }

5
src/Avalonia.Base/Media/FontFamily.cs

@ -79,11 +79,6 @@ namespace Avalonia.Media
/// <remarks>Key is only used for custom fonts.</remarks> /// <remarks>Key is only used for custom fonts.</remarks>
public FontFamilyKey? Key { get; } public FontFamilyKey? Key { get; }
/// <summary>
/// Returns <c>True</c> if this instance is the system's default.
/// </summary>
public bool IsDefault => Name.Equals(DefaultFontFamilyName);
/// <summary> /// <summary>
/// Implicit conversion of string to FontFamily /// Implicit conversion of string to FontFamily
/// </summary> /// </summary>

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

@ -1393,10 +1393,11 @@ namespace Avalonia.Media
} }
} }
if (accumulatedBounds?.PlatformImpl == null || accumulatedBounds.PlatformImpl.Bounds.IsDefault) if (accumulatedBounds?.PlatformImpl == null ||
(accumulatedBounds.PlatformImpl.Bounds.Width == 0 && accumulatedBounds.PlatformImpl.Bounds.Height == 0))
{ {
return null; return null;
} }
return accumulatedBounds; return accumulatedBounds;
} }

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.IsDefault) if (imageSource is object && (rect.Width != 0 || rect.Height != 0))
{ {
context.DrawImage(imageSource, rect); context.DrawImage(imageSource, rect);
} }

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

@ -77,7 +77,7 @@ namespace Avalonia.Media.Imaging
{ {
if (Source is not IBitmap bmp) if (Source is not IBitmap bmp)
return default; return default;
if (SourceRect.IsDefault) if (SourceRect.Width == 0 && SourceRect.Height == 0)
return Source.Size; return Source.Size;
return SourceRect.Size.ToSizeWithDpi(bmp.Dpi); return SourceRect.Size.ToSizeWithDpi(bmp.Dpi);
} }

19
src/Avalonia.Base/PixelRect.cs

@ -9,12 +9,6 @@ namespace Avalonia
/// </summary> /// </summary>
public readonly struct PixelRect : IEquatable<PixelRect> public readonly struct PixelRect : IEquatable<PixelRect>
{ {
/// <summary>
/// An empty rectangle.
/// </summary>
[Obsolete("Use the default keyword instead.")]
public static readonly PixelRect Empty = default;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PixelRect"/> structure. /// Initializes a new instance of the <see cref="PixelRect"/> structure.
/// </summary> /// </summary>
@ -133,15 +127,6 @@ namespace Avalonia
/// </summary> /// </summary>
public PixelPoint Center => new PixelPoint(X + (Width / 2), Y + (Height / 2)); public PixelPoint Center => new PixelPoint(X + (Width / 2), Y + (Height / 2));
/// <summary>
/// Gets a value indicating whether the instance has default values (the rectangle is empty).
/// </summary>
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.
/// </summary> /// </summary>
@ -295,11 +280,11 @@ namespace Avalonia
/// <returns>The union.</returns> /// <returns>The union.</returns>
public PixelRect Union(PixelRect rect) public PixelRect Union(PixelRect rect)
{ {
if (IsDefault) if (Width == 0 && Height == 0)
{ {
return rect; return rect;
} }
else if (rect.IsDefault) else if (rect.Width == 0 && rect.Height == 0)
{ {
return this; return this;
} }

8
src/Avalonia.Base/Point.cs

@ -288,13 +288,5 @@ namespace Avalonia
x = this._x; x = this._x;
y = this._y; y = this._y;
} }
/// <summary>
/// Gets a value indicating whether the X and Y coordinates are zero.
/// </summary>
public bool IsDefault
{
get { return (_x == 0) && (_y == 0); }
}
} }
} }

34
src/Avalonia.Base/Rect.cs

@ -16,12 +16,6 @@ namespace Avalonia
Animation.Animation.RegisterAnimator<RectAnimator>(prop => typeof(Rect).IsAssignableFrom(prop.PropertyType)); Animation.Animation.RegisterAnimator<RectAnimator>(prop => typeof(Rect).IsAssignableFrom(prop.PropertyType));
} }
/// <summary>
/// An empty rectangle.
/// </summary>
[Obsolete("Use the default keyword instead.")]
public static readonly Rect Empty = default;
/// <summary> /// <summary>
/// The X position. /// The X position.
/// </summary> /// </summary>
@ -170,17 +164,6 @@ namespace Avalonia
/// </summary> /// </summary>
public Point Center => new Point(_x + (_width / 2), _y + (_height / 2)); public Point Center => new Point(_x + (_width / 2), _y + (_height / 2));
/// <summary>
/// Gets a value indicating whether the instance has default values (the rectangle is empty).
/// </summary>
// ReSharper disable CompareOfFloatsByEqualityOperator
public bool IsDefault => _width == 0 && _height == 0;
// 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>
@ -517,19 +500,18 @@ namespace Avalonia
return rect; return rect;
} }
/// <summary>
/// <summary> /// Gets the union of two rectangles.
/// Gets the union of two rectangles. /// </summary>
/// </summary> /// <param name="rect">The other rectangle.</param>
/// <param name="rect">The other rectangle.</param> /// <returns>The union.</returns>
/// <returns>The union.</returns> public Rect Union(Rect rect)
public Rect Union(Rect rect)
{ {
if (IsDefault) if (Width == 0 && Height == 0)
{ {
return rect; return rect;
} }
else if (rect.IsDefault) else if (rect.Width == 0 && rect.Height == 0)
{ {
return this; return this;
} }

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

@ -130,8 +130,8 @@ namespace Avalonia.Rendering.Composition.Server
} }
_renderTarget ??= _compositor.CreateRenderTarget(_surfaces()); _renderTarget ??= _compositor.CreateRenderTarget(_surfaces());
if(_dirtyRect.IsDefault && !_redrawRequested) if ((_dirtyRect.Width == 0 && _dirtyRect.Height == 0) && !_redrawRequested)
return; return;
Revision++; Revision++;
@ -163,7 +163,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.IsDefault) if (_dirtyRect.Width != 0 || _dirtyRect.Height != 0)
{ {
using (var context = _layer.CreateDrawingContext()) using (var context = _layer.CreateDrawingContext())
{ {
@ -260,7 +260,7 @@ namespace Avalonia.Rendering.Composition.Server
public void AddDirtyRect(Rect rect) public void AddDirtyRect(Rect rect)
{ {
if(rect.IsDefault) if (rect.Width == 0 && rect.Height == 0)
return; return;
var snapped = SnapToDevicePixels(rect, Scaling); var snapped = SnapToDevicePixels(rect, Scaling);
DebugEvents?.RectInvalidated(rect); DebugEvents?.RectInvalidated(rect);
@ -275,7 +275,7 @@ namespace Avalonia.Rendering.Composition.Server
public void Dispose() public void Dispose()
{ {
if(_disposed) if (_disposed)
return; return;
_disposed = true; _disposed = true;
using (_compositor.RenderInterface.EnsureCurrent()) using (_compositor.RenderInterface.EnsureCurrent())
@ -302,7 +302,7 @@ namespace Avalonia.Rendering.Composition.Server
{ {
if (_attachedVisuals.Remove(visual) && IsEnabled) if (_attachedVisuals.Remove(visual) && IsEnabled)
visual.Deactivate(); visual.Deactivate();
if(visual.IsVisibleInFrame) if (visual.IsVisibleInFrame)
AddDirtyRect(visual.TransformedOwnContentBounds); AddDirtyRect(visual.TransformedOwnContentBounds);
} }

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

@ -23,21 +23,20 @@ namespace Avalonia.Rendering.Composition.Server
private bool _isBackface; private bool _isBackface;
private Rect? _transformedClipBounds; private Rect? _transformedClipBounds;
private Rect _combinedTransformedClipBounds; private Rect _combinedTransformedClipBounds;
protected virtual void RenderCore(CompositorDrawingContextProxy canvas, Rect currentTransformedClip) protected virtual void RenderCore(CompositorDrawingContextProxy canvas, Rect currentTransformedClip)
{ {
} }
public void Render(CompositorDrawingContextProxy canvas, Rect currentTransformedClip) public void Render(CompositorDrawingContextProxy canvas, Rect currentTransformedClip)
{ {
if(Visible == false || IsVisibleInFrame == false) if (Visible == false || IsVisibleInFrame == false)
return; return;
if(Opacity == 0) if (Opacity == 0)
return; return;
currentTransformedClip = currentTransformedClip.Intersect(_combinedTransformedClipBounds); currentTransformedClip = currentTransformedClip.Intersect(_combinedTransformedClipBounds);
if(currentTransformedClip.IsDefault) if (currentTransformedClip.Width == 0 && currentTransformedClip.Height == 0)
return; return;
Root!.RenderedVisuals++; Root!.RenderedVisuals++;
@ -61,7 +60,7 @@ namespace Avalonia.Rendering.Composition.Server
canvas.PushClip(Root!.SnapToDevicePixels(boundsRect)); canvas.PushClip(Root!.SnapToDevicePixels(boundsRect));
if (Clip != null) if (Clip != null)
canvas.PushGeometryClip(Clip); canvas.PushGeometryClip(Clip);
if(OpacityMaskBrush != null) if (OpacityMaskBrush != null)
canvas.PushOpacityMask(OpacityMaskBrush, boundsRect); canvas.PushOpacityMask(OpacityMaskBrush, boundsRect);
RenderCore(canvas, currentTransformedClip); RenderCore(canvas, currentTransformedClip);
@ -78,12 +77,12 @@ namespace Avalonia.Rendering.Composition.Server
canvas.PopClip(); canvas.PopClip();
if (AdornedVisual != null && AdornerIsClipped) if (AdornedVisual != null && AdornerIsClipped)
canvas.PopClip(); canvas.PopClip();
if(Opacity != 1) if (Opacity != 1)
canvas.PopOpacity(); canvas.PopOpacity();
} }
protected virtual bool HandlesClipToBounds => false; protected virtual bool HandlesClipToBounds => false;
private ReadbackData _readback0, _readback1, _readback2; private ReadbackData _readback0, _readback1, _readback2;
/// <summary> /// <summary>
@ -98,17 +97,17 @@ namespace Avalonia.Rendering.Composition.Server
return ref _readback1; return ref _readback1;
return ref _readback2; return ref _readback2;
} }
public Matrix4x4 CombinedTransformMatrix { get; private set; } = Matrix4x4.Identity; public Matrix4x4 CombinedTransformMatrix { get; private set; } = Matrix4x4.Identity;
public Matrix4x4 GlobalTransformMatrix { get; private set; } public Matrix4x4 GlobalTransformMatrix { get; private set; }
public virtual void Update(ServerCompositionTarget root) public virtual void Update(ServerCompositionTarget root)
{ {
if(Parent == null && Root == null) if (Parent == null && Root == null)
return; return;
var wasVisible = IsVisibleInFrame; var wasVisible = IsVisibleInFrame;
// Calculate new parent-relative transform // Calculate new parent-relative transform
if (_combinedTransformDirty) if (_combinedTransformDirty)
{ {
@ -122,7 +121,7 @@ namespace Avalonia.Rendering.Composition.Server
var parentTransform = (AdornedVisual ?? Parent)?.GlobalTransformMatrix ?? Matrix4x4.Identity; var parentTransform = (AdornedVisual ?? Parent)?.GlobalTransformMatrix ?? Matrix4x4.Identity;
var newTransform = CombinedTransformMatrix * parentTransform; var newTransform = CombinedTransformMatrix * parentTransform;
// Check if visual was moved and recalculate face orientation // Check if visual was moved and recalculate face orientation
var positionChanged = false; var positionChanged = false;
if (GlobalTransformMatrix != newTransform) if (GlobalTransformMatrix != newTransform)
@ -134,23 +133,23 @@ namespace Avalonia.Rendering.Composition.Server
var oldTransformedContentBounds = TransformedOwnContentBounds; var oldTransformedContentBounds = TransformedOwnContentBounds;
var oldCombinedTransformedClipBounds = _combinedTransformedClipBounds; var oldCombinedTransformedClipBounds = _combinedTransformedClipBounds;
if (_parent?.IsDirtyComposition == true) if (_parent?.IsDirtyComposition == true)
{ {
IsDirtyComposition = true; IsDirtyComposition = true;
_isDirtyForUpdate = true; _isDirtyForUpdate = true;
} }
var invalidateOldBounds = _isDirtyForUpdate; var invalidateOldBounds = _isDirtyForUpdate;
var invalidateNewBounds = _isDirtyForUpdate; var invalidateNewBounds = _isDirtyForUpdate;
GlobalTransformMatrix = newTransform; GlobalTransformMatrix = newTransform;
var ownBounds = OwnContentBounds; var ownBounds = OwnContentBounds;
if (ownBounds != _oldOwnContentBounds || positionChanged) if (ownBounds != _oldOwnContentBounds || positionChanged)
{ {
_oldOwnContentBounds = ownBounds; _oldOwnContentBounds = ownBounds;
if (ownBounds.IsDefault) if (ownBounds.Width == 0 && ownBounds.Height == 0)
TransformedOwnContentBounds = default; TransformedOwnContentBounds = default;
else else
TransformedOwnContentBounds = TransformedOwnContentBounds =
@ -171,16 +170,16 @@ namespace Avalonia.Rendering.Composition.Server
AdornedVisual?._combinedTransformedClipBounds AdornedVisual?._combinedTransformedClipBounds
?? Parent?._combinedTransformedClipBounds ?? Parent?._combinedTransformedClipBounds
?? new Rect(Root!.Size); ?? new Rect(Root!.Size);
if (_transformedClipBounds != null) if (_transformedClipBounds != null)
_combinedTransformedClipBounds = _combinedTransformedClipBounds.Intersect(_transformedClipBounds.Value); _combinedTransformedClipBounds = _combinedTransformedClipBounds.Intersect(_transformedClipBounds.Value);
EffectiveOpacity = Opacity * (Parent?.EffectiveOpacity ?? 1); EffectiveOpacity = Opacity * (Parent?.EffectiveOpacity ?? 1);
IsHitTestVisibleInFrame = _parent?.IsHitTestVisibleInFrame != false IsHitTestVisibleInFrame = _parent?.IsHitTestVisibleInFrame != false
&& Visible && Visible
&& !_isBackface && !_isBackface
&& !_combinedTransformedClipBounds.IsDefault; && (_combinedTransformedClipBounds.Width != 0 || _combinedTransformedClipBounds.Height != 0);
IsVisibleInFrame = IsHitTestVisibleInFrame IsVisibleInFrame = IsHitTestVisibleInFrame
&& _parent?.IsVisibleInFrame != false && _parent?.IsVisibleInFrame != false
@ -213,11 +212,11 @@ namespace Avalonia.Rendering.Composition.Server
void AddDirtyRect(Rect rc) void AddDirtyRect(Rect rc)
{ {
if(rc == default) if (rc == default)
return; return;
Root?.AddDirtyRect(rc); Root?.AddDirtyRect(rc);
} }
/// <summary> /// <summary>
/// Data that can be read from the UI thread /// Data that can be read from the UI thread
/// </summary> /// </summary>
@ -228,7 +227,7 @@ namespace Avalonia.Rendering.Composition.Server
public long TargetId; public long TargetId;
public bool Visible; public bool Visible;
} }
partial void DeserializeChangesExtra(BatchStreamReader c) partial void DeserializeChangesExtra(BatchStreamReader c)
{ {
ValuesInvalidated(); ValuesInvalidated();
@ -245,9 +244,8 @@ namespace Avalonia.Rendering.Composition.Server
protected virtual void OnDetachedFromRoot(ServerCompositionTarget target) protected virtual void OnDetachedFromRoot(ServerCompositionTarget target)
{ {
} }
partial void OnRootChanged() partial void OnRootChanged()
{ {
if (Root != null) if (Root != null)
@ -256,12 +254,11 @@ namespace Avalonia.Rendering.Composition.Server
OnAttachedToRoot(Root); OnAttachedToRoot(Root);
} }
} }
protected virtual void OnAttachedToRoot(ServerCompositionTarget target) protected virtual void OnAttachedToRoot(ServerCompositionTarget target)
{ {
} }
protected override void ValuesInvalidated() protected override void ValuesInvalidated()
{ {
_isDirtyForUpdate = true; _isDirtyForUpdate = true;
@ -274,6 +271,4 @@ namespace Avalonia.Rendering.Composition.Server
public Rect TransformedOwnContentBounds { get; set; } public Rect TransformedOwnContentBounds { get; set; }
public virtual Rect OwnContentBounds => new Rect(0, 0, Size.X, Size.Y); public virtual Rect OwnContentBounds => new Rect(0, 0, Size.X, Size.Y);
} }
} }

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

@ -30,7 +30,7 @@ namespace Avalonia.Rendering
/// </remarks> /// </remarks>
public void Add(Rect rect) public void Add(Rect rect)
{ {
if (!rect.IsDefault) if (rect.Width != 0 || rect.Height != 0)
{ {
for (var i = 0; i < _rects.Count; ++i) for (var i = 0; i < _rects.Count; ++i)
{ {

11
src/Avalonia.Base/Size.cs

@ -27,12 +27,6 @@ namespace Avalonia
/// </summary> /// </summary>
public static readonly Size Infinity = new Size(double.PositiveInfinity, double.PositiveInfinity); public static readonly Size Infinity = new Size(double.PositiveInfinity, double.PositiveInfinity);
/// <summary>
/// A size representing zero.
/// </summary>
[Obsolete("Use the default keyword instead.")]
public static readonly Size Empty = new Size(0, 0);
/// <summary> /// <summary>
/// The width. /// The width.
/// </summary> /// </summary>
@ -306,10 +300,5 @@ namespace Avalonia
width = this._width; width = this._width;
height = this._height; height = this._height;
} }
/// <summary>
/// Gets a value indicating whether the Width and Height values are zero.
/// </summary>
public bool IsDefault => (_width == 0) && (_height == 0);
} }
} }

10
src/Avalonia.Base/Thickness.cs

@ -97,10 +97,6 @@ namespace Avalonia
/// </summary> /// </summary>
public double Bottom => _bottom; public double Bottom => _bottom;
/// <inheritdoc cref="IsDefault"/>
[Obsolete("Use IsDefault instead.")]
public bool IsEmpty => IsDefault;
/// <summary> /// <summary>
/// Gets a value indicating whether all sides are equal. /// Gets a value indicating whether all sides are equal.
/// </summary> /// </summary>
@ -293,11 +289,5 @@ namespace Avalonia
right = this._right; right = this._right;
bottom = this._bottom; bottom = this._bottom;
} }
/// <summary>
/// Gets a value indicating whether the instance has default values
/// (the left, top, right and bottom values are zero).
/// </summary>
public bool IsDefault => (_left == 0) && (_top == 0) && (_right == 0) && (_bottom == 0);
} }
} }

8
src/Avalonia.Base/Vector.cs

@ -360,13 +360,5 @@ namespace Avalonia
x = this._x; x = this._x;
y = this._y; y = this._y;
} }
/// <summary>
/// Gets a value indicating whether the X and Y components are zero.
/// </summary>
public bool IsDefault
{
get { return (_x == 0) && (_y == 0); }
}
} }
} }

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

@ -177,14 +177,14 @@ namespace Avalonia.Controls
} }
bool? uneditedValue = editingCheckBox.IsChecked; bool? uneditedValue = editingCheckBox.IsChecked;
if(editingEventArgs is PointerPressedEventArgs args) if (editingEventArgs is PointerPressedEventArgs args)
{ {
void ProcessPointerArgs() void ProcessPointerArgs()
{ {
// Editing was triggered by a mouse click // Editing was triggered by a mouse click
Point position = args.GetPosition(editingCheckBox); Point position = args.GetPosition(editingCheckBox);
Rect rect = new Rect(0, 0, editingCheckBox.Bounds.Width, editingCheckBox.Bounds.Height); Rect rect = new Rect(0, 0, editingCheckBox.Bounds.Width, editingCheckBox.Bounds.Height);
if(rect.Contains(position)) if (rect.Contains(position))
{ {
EditValue(); EditValue();
} }
@ -192,14 +192,14 @@ namespace Avalonia.Controls
void OnLayoutUpdated(object sender, EventArgs e) void OnLayoutUpdated(object sender, EventArgs e)
{ {
if(!editingCheckBox.Bounds.IsDefault) if (editingCheckBox.Bounds.Width != 0 || editingCheckBox.Bounds.Height != 0)
{ {
editingCheckBox.LayoutUpdated -= OnLayoutUpdated; editingCheckBox.LayoutUpdated -= OnLayoutUpdated;
ProcessPointerArgs(); ProcessPointerArgs();
} }
} }
if(editingCheckBox.Bounds.IsDefault) if (editingCheckBox.Bounds.Width == 0 && editingCheckBox.Bounds.Height == 0)
{ {
editingCheckBox.LayoutUpdated += OnLayoutUpdated; editingCheckBox.LayoutUpdated += OnLayoutUpdated;
} }

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

@ -441,7 +441,7 @@ namespace Avalonia.Controls
_pendingViewportShift = default; _pendingViewportShift = default;
_unshiftableShift = default; _unshiftableShift = default;
if (_visibleWindow.IsDefault) if (_visibleWindow.Width == 0 && _visibleWindow.Height == 0)
{ {
// We got cleared. // We got cleared.
_layoutExtent = default; _layoutExtent = default;
@ -527,7 +527,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.IsDefault) if (_visibleWindow.Width != 0 || _visibleWindow.Height != 0)
{ {
// 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/BorderVisual.cs

@ -50,7 +50,7 @@ class CompositionBorderVisual : CompositionDrawListVisual
if (ClipToBounds) if (ClipToBounds)
{ {
var clipRect = Root!.SnapToDevicePixels(new Rect(new Size(Size.X, Size.Y))); var clipRect = Root!.SnapToDevicePixels(new Rect(new Size(Size.X, Size.Y)));
if (_cornerRadius.IsDefault) if (_cornerRadius == default)
canvas.PushClip(clipRect); canvas.PushClip(clipRect);
else else
canvas.PushClip(new RoundedRect(clipRect, _cornerRadius)); canvas.PushClip(new RoundedRect(clipRect, _cornerRadius));

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

@ -407,7 +407,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.IsDefault) if (Popup.Child!.DesiredSize == default)
{ {
// 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());

4
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) && _childActualSize.IsDefault) if (IsSizeSmaller(finalSizeTransformed, arrangedsize) && _childActualSize == default)
{ {
//// 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
@ -122,7 +122,7 @@ namespace Avalonia.Controls
} }
Size measureSize; Size measureSize;
if (_childActualSize.IsDefault) if (_childActualSize == default)
{ {
// Determine the largest size after the transformation // Determine the largest size after the transformation
measureSize = ComputeLargestTransformedSize(availableSize); measureSize = ComputeLargestTransformedSize(availableSize);

2
src/Avalonia.Controls/NativeControlHost.cs

@ -141,7 +141,7 @@ namespace Avalonia.Controls
if (IsEffectivelyVisible && bounds.HasValue) if (IsEffectivelyVisible && bounds.HasValue)
{ {
if (bounds.Value.IsDefault) if (bounds.Value.Width == 0 && bounds.Value.Height == 0)
return false; return false;
_attachment?.ShowInBounds(bounds.Value); _attachment?.ShowInBounds(bounds.Value);
} }

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

@ -112,7 +112,8 @@ 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.IsDefault) if (targetScreen != null &&
(targetScreen.WorkingArea.Width == 0 && targetScreen.WorkingArea.Height == 0))
{ {
return targetScreen.Bounds; return targetScreen.Bounds;
} }

3
src/Avalonia.Controls/VirtualizingStackPanel.cs

@ -459,7 +459,8 @@ namespace Avalonia.Controls
while (c is not null) while (c is not null)
{ {
if (!c.Bounds.IsDefault && c.TransformToVisual(this) is Matrix transform) if ((c.Bounds.Width != 0 || c.Bounds.Height != 0) &&
c.TransformToVisual(this) is Matrix transform)
{ {
viewport = new Rect(0, 0, c.Bounds.Width, c.Bounds.Height) viewport = new Rect(0, 0, c.Bounds.Width, c.Bounds.Height)
.TransformToAABB(transform); .TransformToAABB(transform);

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

@ -375,7 +375,7 @@ namespace Avalonia.Skia
foreach (var boxShadow in boxShadows) foreach (var boxShadow in boxShadows)
{ {
if (!boxShadow.IsDefault && !boxShadow.IsInset) if (boxShadow != default && !boxShadow.IsInset)
{ {
using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _useOpacitySaveLayer ? 1 : _currentOpacity)) using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _useOpacitySaveLayer ? 1 : _currentOpacity))
{ {
@ -432,7 +432,7 @@ namespace Avalonia.Skia
foreach (var boxShadow in boxShadows) foreach (var boxShadow in boxShadows)
{ {
if (!boxShadow.IsDefault && boxShadow.IsInset) if (boxShadow != default && boxShadow.IsInset)
{ {
using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _useOpacitySaveLayer ? 1 : _currentOpacity)) using (var shadow = BoxShadowFilter.Create(_boxShadowPaint, boxShadow, _useOpacitySaveLayer ? 1 : _currentOpacity))
{ {

Loading…
Cancel
Save