Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RadialGradientBrush.Radius obsolete usages #14774

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ internal static IGradientBrush ConvertSolidColorBrushToGradient(IGradientBrush g
CreateStopsFromSolidColorBrush(solidColorBrush, oldRadial.GradientStops), solidColorBrush.Opacity,
oldRadial.Transform is { } ? new ImmutableTransform(oldRadial.Transform.Value) : null,
oldRadial.TransformOrigin,
oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin, oldRadial.Radius);
oldRadial.SpreadMethod, oldRadial.Center, oldRadial.GradientOrigin,
oldRadial.RadiusX, oldRadial.RadiusY);

case IConicGradientBrush oldConic:
return new ImmutableConicGradientBrush(
Expand Down
8 changes: 8 additions & 0 deletions src/Avalonia.Base/Media/RadialGradientBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed class RadialGradientBrush : GradientBrush, IRadialGradientBrush
/// <summary>
/// Defines the <see cref="Radius"/> property.
/// </summary>
[Obsolete("Use RadiusX/RadiusY, note that those properties use _relative_ values, so Radius=0.55 would become RadiusX=55% RadiusY=55%. Radius property is always relative even if the rest of the brush uses absolute values.")]
public static readonly StyledProperty<double> RadiusProperty =
AvaloniaProperty.Register<RadialGradientBrush, double>(
nameof(Radius),
Expand Down Expand Up @@ -73,7 +74,9 @@ public RelativePoint GradientOrigin
/// Gets or sets the horizontal radius of the outermost circle of the radial
/// gradient.
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
[DependsOn(nameof(Radius))]
#pragma warning restore CS0618 // Type or member is obsolete
public RelativeScalar RadiusX
{
get { return GetValue(RadiusXProperty); }
Expand All @@ -84,7 +87,9 @@ public RelativeScalar RadiusX
/// Gets or sets the vertical radius of the outermost circle of the radial
/// gradient.
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
[DependsOn(nameof(Radius))]
#pragma warning restore CS0618 // Type or member is obsolete
public RelativeScalar RadiusY
{
get { return GetValue(RadiusYProperty); }
Expand Down Expand Up @@ -119,12 +124,15 @@ private protected override void SerializeChanges(Compositor c, BatchStreamWriter

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
#pragma warning disable CS0618 // Type or member is obsolete: compatibility code for Radius
if (change.IsEffectiveValueChange && change.Property == RadiusProperty)
{
var compatibilityValue = new RelativeScalar(Radius, RelativeUnit.Relative);
SetCurrentValue(RadiusXProperty, compatibilityValue);
SetCurrentValue(RadiusYProperty, compatibilityValue);
}
#pragma warning restore CS0618 // Type or member is obsolete

base.OnPropertyChanged(change);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Avalonia.Base/RelativePoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ public override int GetHashCode()
/// </summary>
/// <param name="size">The size of the visual.</param>
/// <returns>The origin point in pixels.</returns>
[Obsolete("Use ToPixels(Rect) overload to properly map relative points")]
public Point ToPixels(Size size)
{
return _unit == RelativeUnit.Absolute ?
Expand Down
6 changes: 4 additions & 2 deletions tests/Avalonia.RenderTests/Media/RadialGradientBrushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public async Task RadialGradientBrush_RedGreenBlue_Offset_Inside()
},
GradientOrigin = new RelativePoint(0.25, 0.25, RelativeUnit.Relative),
Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative),
Radius = 0.5
RadiusX = RelativeScalar.Middle,
RadiusY = RelativeScalar.Middle
}
}
};
Expand Down Expand Up @@ -157,7 +158,8 @@ public async Task RadialGradientBrush_RedGreenBlue_Offset_Outside()
},
GradientOrigin = new RelativePoint(0.1, 0.1, RelativeUnit.Relative),
Center = new RelativePoint(0.5, 0.5, RelativeUnit.Relative),
Radius = 0.5
RadiusX = RelativeScalar.Middle,
RadiusY = RelativeScalar.Middle
}
}
};
Expand Down
Loading