diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlConstants.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlConstants.cs index 61bdddf934d5..c9c2a0164439 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlConstants.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlConstants.cs @@ -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"; diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index bf1b163e6ecf..141f8631d2cc 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -527,7 +527,7 @@ private string InnerGenerateFile() BuildComponentFields(componentBuilder); BuildCompiledBindings(componentBuilder); - + _generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes); _generationRunFileInfo.ComponentCode = componentBuilder.ToString(); } @@ -5319,19 +5319,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); } } diff --git a/src/Uno.UI/UI/Xaml/Media/Brush.cs b/src/Uno.UI/UI/Xaml/Media/Brush.cs index 9c537d6b409f..b0106fa9ce1e 100644 --- a/src/Uno.UI/UI/Xaml/Media/Brush.cs +++ b/src/Uno.UI/UI/Xaml/Media/Brush.cs @@ -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); diff --git a/src/Uno.UI/UI/Xaml/Media/BrushConverter.cs b/src/Uno.UI/UI/Xaml/Media/BrushConverter.cs index 6cbfed1b8202..c63efecd7fb8 100644 --- a/src/Uno.UI/UI/Xaml/Media/BrushConverter.cs +++ b/src/Uno.UI/UI/Xaml/Media/BrushConverter.cs @@ -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); diff --git a/src/Uno.UI/UI/Xaml/SolidColorBrushHelper.cs b/src/Uno.UI/UI/Xaml/SolidColorBrushHelper.cs index b2f2af86f72b..6f663d21921f 100644 --- a/src/Uno.UI/UI/Xaml/SolidColorBrushHelper.cs +++ b/src/Uno.UI/UI/Xaml/SolidColorBrushHelper.cs @@ -1,59 +1,9 @@ -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 { 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. /// @@ -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);