Skip to content

Commit

Permalink
chore: Few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Feb 2, 2023
1 parent 159cc0e commit 66537ba
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 359 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private string InnerGenerateFile()
BuildComponentFields(componentBuilder);

BuildCompiledBindings(componentBuilder);

_generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes);
_generationRunFileInfo.ComponentCode = componentBuilder.ToString();
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/Brush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/BrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 66537ba

Please sign in to comment.