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!: Make SolidColorBrushHelper internal #11168

Merged
Changes from 3 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
2 changes: 1 addition & 1 deletion build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
@@ -9133,13 +9133,13 @@
<Member fullName="Microsoft.UI.Xaml.Automation.Peers.ScrollPresenterAutomationPeer" reason="Not present in WinAppSDK 1.2" />
<Member fullName="Microsoft.UI.Xaml.Media.RevealBrushState" reason="Not present in WinAppSDK 1.2" />
<Member fullName="Windows.Foundation.IClosable" reason="Shouldn't be visible in .NET and shows as IDisposable instead." />
<Member fullName="Windows.Storage.Streams.InMemoryBuffer reason="Windows.Storage.Streams.Buffer should be used." />
<Member fullName="Windows.Foundation.HResult" reason="Type is hidden in .NET and shouldn't be used" />
<Member fullName="Windows.Storage.Streams.InMemoryBuffer" reason="Windows.Storage.Streams.Buffer should be used." />
<Member fullName="Uno.Extensions.JavaObjectExtensions" reason="Only needed internally" />
<Member fullName="Uno.Client.ICommandExtensions" reason="Only needed internally" />
<Member fullName="Uno.Extensions.UriExtensions" reason="Not needed publicly" />
<Member fullName="Windows.UI.Xaml.FontFamilyHelper" reason="Only needed internally. The public facing type is Uno.UI.Xaml.Media.FontFamilyHelper" />
<Member fullName="Windows.UI.Xaml.SolidColorBrushHelper" reason="Not needed publicly and not present in Windows." />
</Types>
<Events>
<Member fullName="Windows.Foundation.TypedEventHandler`2&lt;Microsoft.UI.Xaml.Controls.IInputValidationControl,Microsoft.UI.Xaml.Controls.HasValidationErrorsChangedEventArgs&gt; Microsoft.UI.Xaml.Controls.AutoSuggestBox::HasValidationErrorsChanged" reason="Not present in WinAppSDK 1.2" />
Original file line number Diff line number Diff line change
@@ -95,7 +95,6 @@ public static class Types
// Misc
public const string Setter = BaseXamlNamespace + ".Setter";
public const string CornerRadius = BaseXamlNamespace + ".CornerRadius";
public const string SolidColorBrushHelper = BaseXamlNamespace + ".SolidColorBrushHelper";
public const string GridLength = BaseXamlNamespace + ".GridLength";
public const string GridUnitType = BaseXamlNamespace + ".GridUnitType";
public const string Color = RootWUINamespace + ".Color";
Original file line number Diff line number Diff line change
@@ -5317,19 +5317,18 @@ private string BuildFontWeight(string memberValue)

private string BuildBrush(string memberValue)
{
var colorHelper = (INamedTypeSymbol)_metadataHelper.GetTypeByFullName(XamlConstants.Types.SolidColorBrushHelper);
var colors = (INamedTypeSymbol)_metadataHelper.GetTypeByFullName(XamlConstants.Types.Colors);

// This ensures that a memberValue "DarkGoldenRod" gets converted to colorName "DarkGoldenrod" (notice the lowercase 'r')
var colorName = colorHelper.GetProperties().FirstOrDefault(m => m.Name.Equals(memberValue, StringComparison.OrdinalIgnoreCase))?.Name;
var colorName = colors.GetProperties().FirstOrDefault(m => m.Name.Equals(memberValue, StringComparison.OrdinalIgnoreCase))?.Name;
if (colorName != null)
{
return "SolidColorBrushHelper." + colorName;
return $"new global::{XamlConstants.Types.SolidColorBrush}(global::{XamlConstants.Types.Colors}.{colorName})";
}
else
{
memberValue = ColorCodeParser.ParseColorCode(memberValue);

return "SolidColorBrushHelper.FromARGB({0})".InvariantCultureFormat(memberValue);
return $"new global::{XamlConstants.Types.SolidColorBrush}(global::{XamlConstants.Types.Color}.FromArgb({{0}}))".InvariantCultureFormat(memberValue);
}
}

2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/Brush.cs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public Brush()
InitializeBinder();
}

public static implicit operator Brush(Color uiColor) => SolidColorBrushHelper.FromARGB(uiColor.A, uiColor.R, uiColor.G, uiColor.B);
public static implicit operator Brush(Color uiColor) => new SolidColorBrush(uiColor);

public static implicit operator Brush(string colorCode) => SolidColorBrushHelper.Parse(colorCode);

2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/BrushConverter.cs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
switch (value)
{
case string color:
return SolidColorBrushHelper.FromARGB(color);
return SolidColorBrushHelper.Parse(color);

case Color color:
return new SolidColorBrush(color);
357 changes: 4 additions & 353 deletions src/Uno.UI/UI/Xaml/SolidColorBrushHelper.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using Windows.UI.Xaml.Media;
using Windows.UI;

#if XAMARIN_IOS_UNIFIED
using GenericColor = UIKit.UIColor;
using UIKit;
#elif XAMARIN_IOS
using GenericColor = MonoTouch.UIKit.UIColor;
using MonoTouch.UIKit;
#elif XAMARIN_ANDROID
using GenericColor = Android.Graphics.Color;
#elif NETFX_CORE
using Windows.UI.Xaml.Media;
using GenericColor = Windows.UI.Color;
using Windows.UI;
#elif __MACOS__
using GenericColor = Windows.UI.Color;
#else
using GenericColor = System.Drawing.Color;
#endif
using Windows.UI.Xaml.Media;

namespace Windows.UI.Xaml
{
public static class SolidColorBrushHelper
internal static class SolidColorBrushHelper
{
#if XAMARIN_IOS
public static SolidColorBrush FromARGB(byte a, byte r, byte g, byte b)
{
return new SolidColorBrush(UIColor.FromRGBA(r, g, b, a));
}
#elif XAMARIN_ANDROID
public static SolidColorBrush FromARGB(byte a, byte r, byte g, byte b)
{
return new SolidColorBrush(Android.Graphics.Color.Argb(a, r, g, b));
}
#else
public static SolidColorBrush FromARGB(byte a, byte r, byte g, byte b)
{
return new SolidColorBrush(Windows.UI.Color.FromArgb(a, r, g, b));
}
#endif

/// <summary>
/// Takes a color code as an ARGB or RGB string and returns a solid color brush.
///
/// Remark: if single digits are used to define the color, they will
/// be duplicated (example: FFD8 will become FFFFDD88)
/// </summary>
public static SolidColorBrush FromARGB(string colorCode)
{
return new SolidColorBrush(Colors.Parse(colorCode));
}

/// <summary>
/// Takes a color code as an ARGB or RGB, or textual string from <see cref="Colors"/> string and returns a solid color brush.
///
/// Takes a color code as an ARGB or RGB, or textual string from <see cref="Colors"/> string and returns a solid color brush.
///
/// Remark: if single digits are used to define the color, they will
/// be duplicated (example: FFD8 will become FFFFDD88)
/// </summary>
@@ -65,305 +15,6 @@ public static SolidColorBrush Parse(string colorCode)
return new SolidColorBrush(Colors.Parse(colorCode));
}

/// <summary>
/// Takes a standard color name (E.G. White) and returns a solid color brush
/// </summary>
public static SolidColorBrush FromName(string colorName)
{
// I know, I don't like it either. Need to check for perf.
switch (colorName)
{
case "Transparent":
return Transparent;
case "AliceBlue":
return AliceBlue;
case "AntiqueWhite":
return AntiqueWhite;
case "Aqua":
return Aqua;
case "Aquamarine":
return Aquamarine;
case "Azure":
return Azure;
case "Beige":
return Beige;
case "Bisque":
return Bisque;
case "Black":
return Black;
case "BlanchedAlmond":
return BlanchedAlmond;
case "Blue":
return Blue;
case "BlueViolet":
return BlueViolet;
case "Brown":
return Brown;
case "BurlyWood":
return BurlyWood;
case "CadetBlue":
return CadetBlue;
case "Chartreuse":
return Chartreuse;
case "Chocolate":
return Chocolate;
case "Coral":
return Coral;
case "CornflowerBlue":
return CornflowerBlue;
case "Cornsilk":
return Cornsilk;
case "Crimson":
return Crimson;
case "Cyan":
return Cyan;
case "DarkBlue":
return DarkBlue;
case "DarkCyan":
return DarkCyan;
case "DarkGoldenrod":
case "DarkGoldenRod":
return DarkGoldenrod;
case "DarkGray":
return DarkGray;
case "DarkGreen":
return DarkGreen;
case "DarkKhaki":
return DarkKhaki;
case "DarkMagenta":
return DarkMagenta;
case "DarkOliveGreen":
return DarkOliveGreen;
case "DarkOrange":
return DarkOrange;
case "DarkOrchid":
return DarkOrchid;
case "DarkRed":
return DarkRed;
case "DarkSalmon":
return DarkSalmon;
case "DarkSeaGreen":
return DarkSeaGreen;
case "DarkSlateBlue":
return DarkSlateBlue;
case "DarkSlateGray":
return DarkSlateGray;
case "DarkTurquoise":
return DarkTurquoise;
case "DarkViolet":
return DarkViolet;
case "DeepPink":
return DeepPink;
case "DeepSkyBlue":
return DeepSkyBlue;
case "DimGray":
return DimGray;
case "DodgerBlue":
return DodgerBlue;
case "Firebrick":
return Firebrick;
case "FloralWhite":
return FloralWhite;
case "ForestGreen":
return ForestGreen;
case "Fuchsia":
return Fuchsia;
case "Gainsboro":
return Gainsboro;
case "GhostWhite":
return GhostWhite;
case "Gold":
return Gold;
case "Goldenrod":
case "GoldenRod":
return Goldenrod;
case "Gray":
return Gray;
case "Green":
return Green;
case "GreenYellow":
return GreenYellow;
case "Honeydew":
return Honeydew;
case "HotPink":
return HotPink;
case "IndianRed":
return IndianRed;
case "Indigo":
return Indigo;
case "Ivory":
return Ivory;
case "Khaki":
return Khaki;
case "Lavender":
return Lavender;
case "LavenderBlush":
return LavenderBlush;
case "LawnGreen":
return LawnGreen;
case "LemonChiffon":
return LemonChiffon;
case "LightBlue":
return LightBlue;
case "LightCoral":
return LightCoral;
case "LightCyan":
return LightCyan;
case "LightGoldenrodYellow":
case "LightGoldenRodYellow":
return LightGoldenrodYellow;
case "LightGray":
return LightGray;
case "LightGreen":
return LightGreen;
case "LightPink":
return LightPink;
case "LightSalmon":
return LightSalmon;
case "LightSeaGreen":
return LightSeaGreen;
case "LightSkyBlue":
return LightSkyBlue;
case "LightSlateGray":
return LightSlateGray;
case "LightSteelBlue":
return LightSteelBlue;
case "LightYellow":
return LightYellow;
case "Lime":
return Lime;
case "LimeGreen":
return LimeGreen;
case "Linen":
return Linen;
case "Magenta":
return Magenta;
case "Maroon":
return Maroon;
case "MediumAquamarine":
return MediumAquamarine;
case "MediumBlue":
return MediumBlue;
case "MediumOrchid":
return MediumOrchid;
case "MediumPurple":
return MediumPurple;
case "MediumSeaGreen":
return MediumSeaGreen;
case "MediumSlateBlue":
return MediumSlateBlue;
case "MediumSpringGreen":
return MediumSpringGreen;
case "MediumTurquoise":
return MediumTurquoise;
case "MediumVioletRed":
return MediumVioletRed;
case "MidnightBlue":
return MidnightBlue;
case "MintCream":
return MintCream;
case "MistyRose":
return MistyRose;
case "Moccasin":
return Moccasin;
case "NavajoWhite":
return NavajoWhite;
case "Navy":
return Navy;
case "OldLace":
return OldLace;
case "Olive":
return Olive;
case "OliveDrab":
return OliveDrab;
case "Orange":
return Orange;
case "OrangeRed":
return OrangeRed;
case "Orchid":
return Orchid;
case "PaleGoldenrod":
case "PaleGoldenRod":
return PaleGoldenrod;
case "PaleGreen":
return PaleGreen;
case "PaleTurquoise":
return PaleTurquoise;
case "PaleVioletRed":
return PaleVioletRed;
case "PapayaWhip":
return PapayaWhip;
case "PeachPuff":
return PeachPuff;
case "Peru":
return Peru;
case "Pink":
return Pink;
case "Plum":
return Plum;
case "PowderBlue":
return PowderBlue;
case "Purple":
return Purple;
case "Red":
return Red;
case "RosyBrown":
return RosyBrown;
case "RoyalBlue":
return RoyalBlue;
case "SaddleBrown":
return SaddleBrown;
case "Salmon":
return Salmon;
case "SandyBrown":
return SandyBrown;
case "SeaGreen":
return SeaGreen;
case "SeaShell":
return SeaShell;
case "Sienna":
return Sienna;
case "Silver":
return Silver;
case "SkyBlue":
return SkyBlue;
case "SlateBlue":
return SlateBlue;
case "SlateGray":
return SlateGray;
case "Snow":
return Snow;
case "SpringGreen":
return SpringGreen;
case "SteelBlue":
return SteelBlue;
case "Tan":
return Tan;
case "Teal":
return Teal;
case "Thistle":
return Thistle;
case "Tomato":
return Tomato;
case "Turquoise":
return Turquoise;
case "Violet":
return Violet;
case "Wheat":
return Wheat;
case "White":
return White;
case "WhiteSmoke":
return WhiteSmoke;
case "Yellow":
return Yellow;
case "YellowGreen":
return YellowGreen;
default:
throw new ArgumentOutOfRangeException("There is no default Brush with the name " + colorName);
};
}

public static SolidColorBrush Transparent => new SolidColorBrush(Colors.Transparent);
public static SolidColorBrush AliceBlue => new SolidColorBrush(Colors.AliceBlue);
public static SolidColorBrush AntiqueWhite => new SolidColorBrush(Colors.AntiqueWhite);