-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attached Shadows (Composition and Win2D + Animations) #4179
Attached Shadows (Composition and Win2D + Animations) #4179
Conversation
Thanks michael-hawker for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
/// <summary> | ||
/// Helper class for attaching <see cref="AttachedShadowBase"/> shadows to <see cref="FrameworkElement"/>s. | ||
/// </summary> | ||
public static class Shadows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Community Suggested we call this Effects
and have the property be called Shadow
so we'd get:
<ui:Effects.Shadow>
for the attached property.
// Position our shadow in the correct spot to match the corresponding element. | ||
context.SpriteVisual.Size = context.Element.RenderSize.ToVector2(); | ||
context.SpriteVisual.Offset = context.Element.CoordinatesFrom(CastTo).ToVector3(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ryken100 suggested somehow using composition animation to lock the two together? @Sergio0694 thoughts on this too?
Right now I just update the size/offset when the mask is created and in OnSizeChanged below. This seems to work alright for most basic scenarios, but I would imagine would break down with extra translations and if the element casting is animated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea, but thinking we might be able to use a composition animation to bind the two together like we're doing with BindSize
for the brushes? I mean not with exactly the same code, but by reusing the same concept:
Lines 25 to 34 in b605154
public static void BindSize(this CompositionObject source, UIElement target) | |
{ | |
var visual = ElementCompositionPreview.GetElementVisual(target); | |
var bindSizeAnimation = source.Compositor.CreateExpressionAnimation($"{nameof(visual)}.Size"); | |
bindSizeAnimation.SetReferenceParameter(nameof(visual), visual); | |
// Start the animation | |
source.StartAnimation("Size", bindSizeAnimation); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that could work for Size, but Offset may not work the same as we need to do the absolute offset, eh?
Which means we still need the SizeChanged on the parent at least as that effects the offsets...?
Ugh, need to update to latest. Will fix that and then also need to double-check if I deprecated DropShadowPanel fully... |
…e for simplification
… itself is 1809+ now. Add Deprecation message we missed to RadialProgressBar control.
Add additional shortcuts/fallbacks for parsing other Vector formats to different types
Had to create static Attached Property location Had to convert Vector3 to string for XAML parsing Made empty strings return zerod
b88e4a2
to
b34f441
Compare
Need to update the Vector tests to account for the new format options I added for better string parsing. |
Alright, Vector unit tests are passing locally now (and added new ones). So we should be all good with the new behavior now. Hopefully @Sergio0694 won't mind... 🙈 They do map to existing constructors of the underlying types, so feels good. Also re-used the underlying methods to not add extra complexity to implementation even if it's a bit less performant, but we're doing string parsing here after all still... 😋 This was needed to make shadows play nicer as they're technically Vector3 properties but the Z value is ignored, so it's easier in the Sample App to just take a "16,16" value and make the Vector3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved - nice shadows
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Shadows/AttachedShadowCompositionXaml.bind
Outdated
Show resolved
Hide resolved
…adowCompositionXaml.bind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the API and it works well from my testing!
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
@michael-hawker Removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, left a few notes 😄
Microsoft.Toolkit.Uwp.UI/Shadows/AttachedShadowElementContext.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Sergio Pedri <sergio0694@live.com>
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Fixes #3122 #3607 #3516
Also implements #3693 for the new DropShadow.
FYI @seanocali as this is a different implementation approach (which is simpler to use outside of the DropShadowPanel we've been working on) but should hopefully achieve the same result.
This PR adds attached shadows which can easily be attached to any FrameworkElement without needing to modify the layout like DropShadowPanel does today. They can also be shared using a resource, added to the style of an element, and animated! All the things! 🎉
PR Type
What kind of change does this PR introduce?
What is the current behavior?
DropShadowPanel is clunky and requires modifying how you layout your app.
What is the new behavior?
Just attach a shadow and be done! (DropShadowPanel is deprecated.)
PR Checklist
AttachedCardShadow
directly withBorder
?Please check if your PR fulfills the following requirements:
Other information