-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Multiple box shadow support #16502
Multiple box shadow support #16502
Conversation
* `BoxShadow` is renamed to `DropShadow`. * New `BoxShadow` component newtyping a `Vec<DropShadow`.
* Added a node with multiple shadows to the `BoxShadow` example
I like the feature and the API. I'd probably do a smallvec myself, but we should bench that and do it in follow-up. |
Wondering if it's more or less confusing to call optional components non-required/unrequired instead 😕 |
Yeah it seems to me in practical terms it's unusual to use a very large number of shadows and if you do it's most likely because you are are using multiple shadows in which case the smallvec would allocate on the heap anyway. |
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.
I was thinking it was going to be more complex, same but in a loop. 👌
# Objective Add support for multiple box shadows on a single `Node`. ## Solution * Rename `BoxShadow` to `ShadowStyle` and remove its `Component` derive. * Create a new `BoxShadow` component that newtypes a `Vec<ShadowStyle>`. * Add a `new` constructor method to `BoxShadow` for single shadows. * Change `extract_shadows` to iterate through a list of shadows per node. Render order is determined implicitly from the order of the shadows stored in the `BoxShadow` component, back-to-front. Might be more efficient to use a `SmallVec<[ShadowStyle; 1]>` for the list of shadows but not sure if the extra friction is worth it. ## Testing Added a node with four differently coloured shadows to the `box_shadow` example. --- ## Showcase ``` cargo run --example box_shadow ``` <img width="460" alt="four-shadow" src="https://github.com/user-attachments/assets/2f728c47-33b4-42e1-96ba-28a774b94b24"> ## Migration Guide Bevy UI now supports multiple shadows per node. A new struct `ShadowStyle` is used to set the style for each shadow. And the `BoxShadow` component is changed to a tuple struct wrapping a vector containing a list of `ShadowStyle`s. To spawn a node with a single shadow you can use the `new` constructor function: ```rust commands.spawn(( Node::default(), BoxShadow::new( Color::BLACK.with_alpha(0.8), Val::Percent(offset.x), Val::Percent(offset.y), Val::Percent(spread), Val::Px(blur), ) )); ``` --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
# Objective Add support for multiple box shadows on a single `Node`. ## Solution * Rename `BoxShadow` to `ShadowStyle` and remove its `Component` derive. * Create a new `BoxShadow` component that newtypes a `Vec<ShadowStyle>`. * Add a `new` constructor method to `BoxShadow` for single shadows. * Change `extract_shadows` to iterate through a list of shadows per node. Render order is determined implicitly from the order of the shadows stored in the `BoxShadow` component, back-to-front. Might be more efficient to use a `SmallVec<[ShadowStyle; 1]>` for the list of shadows but not sure if the extra friction is worth it. ## Testing Added a node with four differently coloured shadows to the `box_shadow` example. --- ## Showcase ``` cargo run --example box_shadow ``` <img width="460" alt="four-shadow" src="https://github.com/user-attachments/assets/2f728c47-33b4-42e1-96ba-28a774b94b24"> ## Migration Guide Bevy UI now supports multiple shadows per node. A new struct `ShadowStyle` is used to set the style for each shadow. And the `BoxShadow` component is changed to a tuple struct wrapping a vector containing a list of `ShadowStyle`s. To spawn a node with a single shadow you can use the `new` constructor function: ```rust commands.spawn(( Node::default(), BoxShadow::new( Color::BLACK.with_alpha(0.8), Val::Percent(offset.x), Val::Percent(offset.y), Val::Percent(spread), Val::Px(blur), ) )); ``` --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Objective
Add support for multiple box shadows on a single
Node
.Solution
BoxShadow
toShadowStyle
and remove itsComponent
derive.BoxShadow
component that newtypes aVec<ShadowStyle>
.new
constructor method toBoxShadow
for single shadows.extract_shadows
to iterate through a list of shadows per node.Render order is determined implicitly from the order of the shadows stored in the
BoxShadow
component, back-to-front.Might be more efficient to use a
SmallVec<[ShadowStyle; 1]>
for the list of shadows but not sure if the extra friction is worth it.Testing
Added a node with four differently coloured shadows to the
box_shadow
example.Showcase
Migration Guide
Bevy UI now supports multiple shadows per node. A new struct
ShadowStyle
is used to set the style for each shadow. And theBoxShadow
component is changed to a tuple struct wrapping a vector containing a list ofShadowStyle
s. To spawn a node with a single shadow you can use thenew
constructor function: