Skip to content

Commit

Permalink
Update Label shadow (dotnet#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot committed Aug 24, 2022
1 parent 9a753e6 commit 82ffa8a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Label/LabelHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public static void MapFont(ILabelHandler handler, ILabel label)
handler.PlatformView?.UpdateFont(label, fontManager);
}

public static void MapShadow(ILabelHandler handler, ILabel label)
{
handler.PlatformView?.UpdateShadow(label);
}

[MissingMapper]
public static void MapCharacterSpacing(ILabelHandler handler, ILabel label) { }

Expand Down
3 changes: 3 additions & 0 deletions src/Core/src/Handlers/Label/LabelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class LabelHandler : ILabelHandler
[nameof(ILabel.Background)] = MapBackground,
[nameof(ILabel.Height)] = MapHeight,
[nameof(ILabel.Opacity)] = MapOpacity,
#endif
#if TIZEN
[nameof(ILabel.Shadow)] = MapShadow,
#endif
[nameof(ITextStyle.CharacterSpacing)] = MapCharacterSpacing,
[nameof(ITextStyle.Font)] = MapFont,
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/Handlers/View/ViewHandlerOfT.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ protected override void RemoveContainer()
var parent = ContainerView!.GetParent();
parent?.Remove(ContainerView!);
ContainerView.Content = null;
ContainerView.Dispose();
ContainerView = null;
parent?.Add(PlatformView);
PlatformView.UpdateBounds(bounds);
}
Expand Down
28 changes: 27 additions & 1 deletion src/Core/src/Platform/Tizen/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Tizen.UIExtensions.NUI;
using TLineBreakMode = Tizen.UIExtensions.Common.LineBreakMode;
using TTextDecorationse = Tizen.UIExtensions.Common.TextDecorations;
using Microsoft.Maui.Graphics;
using Tizen.NUI;
using NColor = Tizen.UIExtensions.Common.Color;

namespace Microsoft.Maui.Platform
{
Expand All @@ -14,7 +17,7 @@ public static void UpdateText(this Label platformLabel, ILabel label)

public static void UpdateTextColor(this Label platformLabel, ILabel label)
{
platformLabel.TextColor = label.TextColor == null ? Color.Black : label.TextColor.ToPlatform();
platformLabel.TextColor = label.TextColor == null ? NColor.Black : label.TextColor.ToPlatform();
}

public static void UpdateFont(this Label platformLabel, ILabel label, IFontManager fontManager)
Expand All @@ -39,6 +42,29 @@ public static void UpdateTextDecorations(this Label platformLabel, ILabel label)
platformLabel.TextDecorations = label.TextDecorations.ToPlatform();
}

public static void UpdateShadow(this Label platformLabel, IView view)
{
if (view.Shadow != null)
{
var offsetX = view.Shadow.Offset.X.ToScaledPixel();
var offsetY = view.Shadow.Offset.Y.ToScaledPixel();
var radius = ((double)view.Shadow.Radius).ToScaledPixel();
var color = view.Shadow.Paint.ToColor() != null ? view.Shadow.Paint.ToColor()!.MultiplyAlpha(view.Shadow.Opacity) : Colors.Black.MultiplyAlpha(view.Shadow.Opacity);
var ncolor = color.ToPlatform().ToNative();

PropertyMap shadow = new PropertyMap();
shadow.Add("offset", new PropertyValue(new Vector2(offsetX, offsetY)));
shadow.Add("color", new PropertyValue(ncolor));
shadow.Add("blurRadius", new PropertyValue(radius));

platformLabel.Shadow = shadow;
}
else
{
platformLabel.Shadow = new PropertyMap();
}
}

public static FontAttributes GetFontAttributes(this Font font)
{
FontAttributes attributes = font.Weight == FontWeight.Bold ? FontAttributes.Bold : FontAttributes.None;
Expand Down

0 comments on commit 82ffa8a

Please sign in to comment.