bevy/crates/bevy_ui/src
ickshonpe 56d5591028
Multiple box shadow support (#16502)
# 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>
2024-12-01 21:30:08 +00:00
..
experimental Migrate UI bundles to required components (#15898) 2024-10-17 21:11:02 +00:00
layout Only use physical coords internally in bevy_ui (#16375) 2024-11-22 00:45:07 +00:00
render Multiple box shadow support (#16502) 2024-12-01 21:30:08 +00:00
widget fix: setting content size to rect size if image has a rect (#16457) 2024-11-22 18:21:45 +00:00
accessibility.rs Properly set accessible value on label nodes (#16418) 2024-11-17 18:10:41 +00:00
focus.rs use scale factor for touches in UI focus (#16522) 2024-11-26 21:23:12 +00:00
geometry.rs Merge Style properties into Node. Use ComputedNode for computed properties. (#15975) 2024-10-18 22:25:33 +00:00
lib.rs Add flags to SpritePlugin and UiPlugin to allow disabling their picking backend (without needing to disable features). (#16473) 2024-11-22 18:16:34 +00:00
measurement.rs Use CosmicFontSystem in public bevy_text APIs and remove cosmic_text re-export (#16063) 2024-10-23 20:05:28 +00:00
node_bundles.rs UiImage -> ImageNode, UiImageSize -> ImageNodeSize (#16271) 2024-11-07 21:52:58 +00:00
picking_backend.rs Only use physical coords internally in bevy_ui (#16375) 2024-11-22 00:45:07 +00:00
stack.rs Merge Style properties into Node. Use ComputedNode for computed properties. (#15975) 2024-10-18 22:25:33 +00:00
ui_material.rs Don't reëxport bevy_image from bevy_render (#16163) 2024-11-10 06:54:38 +00:00
ui_node.rs Multiple box shadow support (#16502) 2024-12-01 21:30:08 +00:00
update.rs Only use physical coords internally in bevy_ui (#16375) 2024-11-22 00:45:07 +00:00