Skip to content

Commit

Permalink
[Gtk] Controls.Core.csproj, Core.csproj: ViewExtensions: Shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
lytico committed Mar 22, 2024
1 parent ed4c11e commit 008eeaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public partial class FrameHandler : ViewHandler<Frame, FrameView>
[Frame.ContentProperty.PropertyName] = MapContent,
[Frame.CornerRadiusProperty.PropertyName] = MapCornerRadius,
[Frame.BorderColorProperty.PropertyName] = MapBorderColor,
[Frame.ShadowProperty.PropertyName] = MapShadow,
};

public static CommandMapper<Frame, FrameHandler> CommandMapper = new(ViewRenderer.VisualElementRendererCommandMapper) { };
Expand All @@ -24,13 +25,15 @@ public FrameHandler(IPropertyMapper? mapper)
public FrameHandler(IPropertyMapper? mapper, CommandMapper? commandMapper)
: base(mapper ?? Mapper, commandMapper ?? CommandMapper) { }


[MissingMapper]
protected override FrameView CreatePlatformView()
{
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a {nameof(Frame)}");

var view = new FrameView() { CrossPlatformLayout = VirtualView };

ContainerView = view;
return view;
}

Expand Down Expand Up @@ -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);
}
}
}
18 changes: 17 additions & 1 deletion src/Core/src/Platform/Gtk/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down

0 comments on commit 008eeaa

Please sign in to comment.