bevy/examples/shader
Carter Anderson 015f2c69ca
Merge Style properties into Node. Use ComputedNode for computed properties. (#15975)
# Objective

Continue improving the user experience of our UI Node API in the
direction specified by [Bevy's Next Generation Scene / UI
System](https://github.com/bevyengine/bevy/discussions/14437)

## Solution

As specified in the document above, merge `Style` fields into `Node`,
and move "computed Node fields" into `ComputedNode` (I chose this name
over something like `ComputedNodeLayout` because it currently contains
more than just layout info. If we want to break this up / rename these
concepts, lets do that in a separate PR). `Style` has been removed.

This accomplishes a number of goals:

## Ergonomics wins

Specifying both `Node` and `Style` is now no longer required for
non-default styles

Before:
```rust
commands.spawn((
    Node::default(),
    Style {
        width:  Val::Px(100.),
        ..default()
    },
));
```

After:

```rust
commands.spawn(Node {
    width:  Val::Px(100.),
    ..default()
});
```

## Conceptual clarity

`Style` was never a comprehensive "style sheet". It only defined "core"
style properties that all `Nodes` shared. Any "styled property" that
couldn't fit that mold had to be in a separate component. A "real" style
system would style properties _across_ components (`Node`, `Button`,
etc). We have plans to build a true style system (see the doc linked
above).

By moving the `Style` fields to `Node`, we fully embrace `Node` as the
driving concept and remove the "style system" confusion.

## Next Steps

* Consider identifying and splitting out "style properties that aren't
core to Node". This should not happen for Bevy 0.15.

---

## Migration Guide

Move any fields set on `Style` into `Node` and replace all `Style`
component usage with `Node`.

Before:
```rust
commands.spawn((
    Node::default(),
    Style {
        width:  Val::Px(100.),
        ..default()
    },
));
```

After:

```rust
commands.spawn(Node {
    width:  Val::Px(100.),
    ..default()
});
```

For any usage of the "computed node properties" that used to live on
`Node`, use `ComputedNode` instead:

Before:
```rust
fn system(nodes: Query<&Node>) {
    for node in &nodes {
        let computed_size = node.size();
    }
}
```

After:
```rust
fn system(computed_nodes: Query<&ComputedNode>) {
    for computed_node in &computed_nodes {
        let computed_size = computed_node.size();
    }
}
```
2024-10-18 22:25:33 +00:00
..
animate_shader.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
array_texture.rs Remove incorrect equality comparisons for asset load error types (#15890) 2024-10-14 01:00:45 +00:00
automatic_instancing.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
compute_shader_game_of_life.rs Migrate from Query::single and friends to Single (#15872) 2024-10-13 20:32:06 +00:00
custom_phase_item.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
custom_post_processing.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
custom_shader_instancing.rs Deprecate SpatialBundle (#15830) 2024-10-13 17:28:22 +00:00
custom_vertex_attribute.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
extended_material.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
fallback_image.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
gpu_readback.rs Gpu readback (#15419) 2024-09-30 17:28:55 +00:00
shader_defs.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shader_material.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shader_material_2d.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shader_material_glsl.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
shader_material_screenspace_texture.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
shader_prepass.rs Merge Style properties into Node. Use ComputedNode for computed properties. (#15975) 2024-10-18 22:25:33 +00:00
specialized_mesh_pipeline.rs Fix panic due to malformed mesh in specialized_mesh_pipeline (#15899) 2024-10-15 02:34:33 +00:00
storage_buffer.rs aligning public apis of Time,Timer and Stopwatch (#15962) 2024-10-16 21:09:32 +00:00
texture_binding_array.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00