bevy/examples/ui
ickshonpe 99b9a2fcd7
box shadow (#15204)
# Objective

UI box shadow support

Adds a new component `BoxShadow`:

```rust
pub struct BoxShadow {
    /// The shadow's color
    pub color: Color,
    /// Horizontal offset
    pub x_offset: Val,
    /// Vertical offset
    pub y_offset: Val,
    /// Horizontal difference in size from the occluding uninode
    pub spread_radius: Val,
    /// Blurriness of the shadow
    pub blur_radius: Val,
}
```

To use `BoxShadow`, add the component to any Bevy UI node and a shadow
will be drawn beneath that node.
Also adds a resource `BoxShadowSamples` that can be used to adjust the
shadow quality.

#### Notes
* I'm not super happy with the field names. Maybe we need a `struct Size
{ width: Val, height: Val }` type or something.
* The shader isn't very optimised but I don't see that it's too
important for now as the number of shadows being rendered is not going
to be massive most of the time. I think it's more important to get the
API and geometry correct with this PR.
* I didn't implement an inset property, it's not essential and can
easily be added in a follow up.
* Shadows are only rendered for uinodes, not for images or text.
* Batching isn't supported, it would need out-of-the-scope-of-this-pr
changes to the way the UI handles z-ordering for it to be effective.

# Showcase

```cargo run --example box_shadow -- --samples 4```

<img width="391" alt="br" src="https://github.com/user-attachments/assets/4e8add96-dc93-46e0-9e35-d995eb0943ad">

```cargo run --example box_shadow -- --samples 10```

<img width="391" alt="s10"
src="https://github.com/user-attachments/assets/ecb384c9-4012-4cd6-9dea-5180904bf28e">
2024-10-08 16:26:17 +00:00
..
borders.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
box_shadow.rs box shadow (#15204) 2024-10-08 16:26:17 +00:00
button.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
display_and_visibility.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
flex_layout.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
font_atlas_debug.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ghost_nodes.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
grid.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
overflow_debug.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
overflow.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
relative_cursor_position.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
render_ui_to_texture.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
scroll.rs Rename the Pickable component and fix incorrect documentation (#15707) 2024-10-07 17:09:57 +00:00
size_constraints.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
text_debug.rs Display the bounds of each text node in the text_debug ui example (#15622) 2024-10-05 22:48:57 +00:00
text_wrap_debug.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
text.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
transparency_ui.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_material.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_scaling.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_texture_atlas_slice.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_texture_atlas.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_texture_slice_flip_and_tile.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui_texture_slice.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
ui.rs Rename the Pickable component and fix incorrect documentation (#15707) 2024-10-07 17:09:57 +00:00
viewport_debug.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
window_fallthrough.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
z_index.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00