Skip to content

Commit

Permalink
fix: Use fallback color for unsupported brushes
Browse files Browse the repository at this point in the history
(cherry picked from commit a6f162a)

# Conflicts:
#	src/Uno.UI/UI/Xaml/Media/RevealBrush.cs
  • Loading branch information
MartinZikmund authored and mergify[bot] committed Aug 11, 2023
1 parent 5bf4c2c commit 67657f1
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 57 deletions.
17 changes: 17 additions & 0 deletions src/Uno.UI/Microsoft/UI/Xaml/Media/RevealBrush.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Android.Graphics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Rect = Windows.Foundation.Rect;

namespace Microsoft.UI.Xaml.Media;

public partial class RevealBrush : XamlCompositionBrushBase
{
protected override Paint GetPaintInner(Rect destinationRect)
{
var color = this.IsDependencyPropertySet(FallbackColorProperty) ?
GetColorWithOpacity(FallbackColor) :
GetColorWithOpacity(Color);
return new Paint() { Color = color, AntiAlias = true };
}
}
10 changes: 4 additions & 6 deletions src/Uno.UI/UI/Xaml/Media/RevealBackgroundBrush.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

namespace Windows.UI.Xaml.Media
namespace Windows.UI.Xaml.Media;

public partial class RevealBackgroundBrush : RevealBrush
{
public partial class RevealBackgroundBrush : RevealBrush
public RevealBackgroundBrush()
{
public RevealBackgroundBrush()
{

}
}
}
11 changes: 4 additions & 7 deletions src/Uno.UI/UI/Xaml/Media/RevealBorderBrush.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@

namespace Windows.UI.Xaml.Media
namespace Windows.UI.Xaml.Media;

public partial class RevealBorderBrush : RevealBrush
{
public partial class RevealBorderBrush : RevealBrush
public RevealBorderBrush()
{
public RevealBorderBrush()
{

}
}
}
17 changes: 8 additions & 9 deletions src/Uno.UI/UI/Xaml/Media/RevealBrush.Android.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using Android.Graphics;
using Rect = Windows.Foundation.Rect;

namespace Windows.UI.Xaml.Media
namespace Windows.UI.Xaml.Media;

partial class RevealBrush
{
public partial class RevealBrush : XamlCompositionBrushBase
protected override Paint GetPaintInner(Rect destinationRect)
{
protected override Paint GetPaintInner(Rect destinationRect)
{
var color = this.IsDependencyPropertySet(FallbackColorProperty) ?
GetColorWithOpacity(FallbackColor) :
GetColorWithOpacity(Color);
return new Paint() { Color = color, AntiAlias = true };
}
var color = this.IsDependencyPropertySet(FallbackColorProperty) ?
GetColorWithOpacity(FallbackColor) :
GetColorWithOpacity(Color);
return new Paint() { Color = color, AntiAlias = true };
}
}
32 changes: 27 additions & 5 deletions src/Uno.UI/UI/Xaml/Media/RevealBrush.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

namespace Windows.UI.Xaml.Media
namespace Windows.UI.Xaml.Media;

public partial class RevealBrush : XamlCompositionBrushBase
{
public partial class RevealBrush : XamlCompositionBrushBase
public RevealBrush()
{
public RevealBrush()
{

<<<<<<< HEAD
}

[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
Expand All @@ -27,5 +27,27 @@ public RevealBrush()
nameof(Color), typeof(global::Windows.UI.Color),
typeof(global::Windows.UI.Xaml.Media.RevealBrush),
new FrameworkPropertyMetadata(default(global::Windows.UI.Color)));
=======
>>>>>>> a6f162abde (fix: Use fallback color for unsupported brushes)
}

[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Color Color
{
get
{
return (global::Windows.UI.Color)this.GetValue(ColorProperty);
}
set
{
this.SetValue(ColorProperty, value);
}
}

[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty ColorProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Color), typeof(global::Windows.UI.Color),
typeof(global::Windows.UI.Xaml.Media.RevealBrush),
new FrameworkPropertyMetadata(default(global::Windows.UI.Color)));
}
1 change: 0 additions & 1 deletion src/Uno.UI/UI/Xaml/Media/SolidColorBrush.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Windows.UI.Xaml.Media
// Android partial for SolidColorBrush
public partial class SolidColorBrush : Brush
{

protected override Paint GetPaintInner(Rect destinationRect)
{
return new Paint() { Color = this.ColorWithOpacity, AntiAlias = true };
Expand Down
14 changes: 14 additions & 0 deletions src/Uno.UI/UI/Xaml/Media/XamlCompositionBrushBase.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Android.Graphics;
using Rect = Windows.Foundation.Rect;

namespace Windows.UI.Xaml.Media;

public partial class XamlCompositionBrushBase : Brush
{
protected override Paint GetPaintInner(Rect destinationRect)
{
// By default fallback to FallbackColor, unless overridden by a derived class.
var color = GetColorWithOpacity(FallbackColor);
return new Paint() { Color = color, AntiAlias = true };
}
}
55 changes: 26 additions & 29 deletions src/Uno.UI/UI/Xaml/Media/XamlCompositionBrushBase.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
using Color = Windows.UI.Color;
namespace Windows.UI.Xaml.Media;

namespace Windows.UI.Xaml.Media
public partial class XamlCompositionBrushBase : Brush
{
public partial class XamlCompositionBrushBase : Brush
protected XamlCompositionBrushBase() : base()
{
protected XamlCompositionBrushBase() : base()
}

public Color FallbackColor
{
get
{
return (Color)this.GetValue(FallbackColorProperty);
}

public Color FallbackColor
set
{
get
{
return (Color)this.GetValue(FallbackColorProperty);
}
set
{
this.SetValue(FallbackColorProperty, value);
}
this.SetValue(FallbackColorProperty, value);
}
}

public static DependencyProperty FallbackColorProperty { get; } =
DependencyProperty.Register(
nameof(FallbackColor), typeof(Color),
typeof(XamlCompositionBrushBase),
new FrameworkPropertyMetadata(default(Color)));
public static DependencyProperty FallbackColorProperty { get; } =
DependencyProperty.Register(
nameof(FallbackColor), typeof(Color),
typeof(XamlCompositionBrushBase),
new FrameworkPropertyMetadata(default(Color)));

/// <summary>
/// Returns the fallback color mixed with opacity value.
/// </summary>
internal Color FallbackColorWithOpacity => FallbackColor.WithOpacity(Opacity);
/// <summary>
/// Returns the fallback color mixed with opacity value.
/// </summary>
internal Color FallbackColorWithOpacity => FallbackColor.WithOpacity(Opacity);

protected virtual void OnConnected()
{
}
protected virtual void OnConnected()
{
}

protected virtual void OnDisconnected()
{
}
protected virtual void OnDisconnected()
{
}
}

0 comments on commit 67657f1

Please sign in to comment.