From 008eeaafde9156fc6fc0845692b6306a675a03ec Mon Sep 17 00:00:00 2001 From: lytico Date: Fri, 22 Mar 2024 01:17:44 +0100 Subject: [PATCH] [Gtk] Controls.Core.csproj, Core.csproj: ViewExtensions: Shadow --- .../Handlers/Gtk/FrameHandler.Gtk.cs | 13 +++++++++++++ src/Core/src/Platform/Gtk/ViewExtensions.cs | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Gtk/FrameHandler.Gtk.cs b/src/Controls/src/Core/Compatibility/Handlers/Gtk/FrameHandler.Gtk.cs index cec07725a0d3..086feedd7efc 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Gtk/FrameHandler.Gtk.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Gtk/FrameHandler.Gtk.cs @@ -12,6 +12,7 @@ public partial class FrameHandler : ViewHandler [Frame.ContentProperty.PropertyName] = MapContent, [Frame.CornerRadiusProperty.PropertyName] = MapCornerRadius, [Frame.BorderColorProperty.PropertyName] = MapBorderColor, + [Frame.ShadowProperty.PropertyName] = MapShadow, }; public static CommandMapper CommandMapper = new(ViewRenderer.VisualElementRendererCommandMapper) { }; @@ -24,6 +25,7 @@ public FrameHandler(IPropertyMapper? mapper) public FrameHandler(IPropertyMapper? mapper, CommandMapper? commandMapper) : base(mapper ?? Mapper, commandMapper ?? CommandMapper) { } + [MissingMapper] protected override FrameView CreatePlatformView() { @@ -31,6 +33,7 @@ protected override FrameView CreatePlatformView() var view = new FrameView() { CrossPlatformLayout = VirtualView }; + ContainerView = view; return view; } @@ -71,5 +74,15 @@ public static void MapBorderColor(FrameHandler handler, Frame frame) { handler.PlatformView.UpdateBorderColor(frame.BorderColor); } + + // see: https://docs.gtk.org/gtk3/css-properties.html + // https://www.w3.org/TR/css-backgrounds-3/#box-shadow + public static void UpdateShadow(FrameView platformView, Frame view) + { + if (platformView is not { }) + return; + + platformView.UpdateShadow((IView)view); + } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Gtk/ViewExtensions.cs b/src/Core/src/Platform/Gtk/ViewExtensions.cs index 54168fb3b819..6b161cdfab6f 100644 --- a/src/Core/src/Platform/Gtk/ViewExtensions.cs +++ b/src/Core/src/Platform/Gtk/ViewExtensions.cs @@ -210,7 +210,23 @@ internal static Matrix4x4 GetViewTransform(this Widget platformView) } [MissingMapper] - public static void UpdateShadow(this Widget? platformView, IView view) { } + // see: https://docs.gtk.org/gtk3/css-properties.html + // https://www.w3.org/TR/css-backgrounds-3/#box-shadow + public static void UpdateShadow(this Widget? platformView, IView view) + { + if (platformView is not { }) + return; + + // box-shadow: none; + if (view.Shadow is not { }) + { + platformView.SetStyleValueNode($"none", platformView.CssMainNode(), "box-shadow"); + } + else + { + platformView.SetStyleValueNode($"{view.Shadow.Offset} {view.Shadow.Offset} 2px -2px {view.Shadow.Paint.ToColor()}", platformView.CssMainNode(), "box-shadow"); + } + } [MissingMapper] public static void UpdateBorder(this Widget? platformView, IView view) { }