bevy/examples/2d
ickk a0448eca2f enum Visibility component (#6320)
Consolidation of all the feedback about #6271 as well as the addition of an "unconditionally visible" mode.

# Objective

The current implementation of the `Visibility` struct simply wraps a boolean.. which seems like an odd pattern when rust has such nice enums that allow for more expression using pattern-matching. 

Additionally as it stands Bevy only has two settings for visibility of an entity: 
- "unconditionally hidden" `Visibility { is_visible: false }`, 
- "inherit visibility from parent" `Visibility { is_visible: true }`
   where a root level entity set to "inherit" is visible. 

Note that given the behaviour, the current naming of the inner field is a little deceptive or unclear.

Using an enum for `Visibility` opens the door for adding an extra behaviour mode. This PR adds a new "unconditionally visible" mode, which causes an entity to be visible even if its Parent entity is hidden. There should not really be any performance cost to the addition of this new mode.

--
The recently added `toggle` method is removed in this PR, as its semantics could be confusing with 3 variants.

## Solution

Change the Visibility component into
```rust
enum Visibility {
  Hidden,    // unconditionally hidden
  Visible,   // unconditionally visible
  Inherited, // inherit visibility from parent
}
```

---

## Changelog

### Changed

`Visibility` is now an enum

## Migration Guide

- evaluation of the `visibility.is_visible` field should now check for `visibility == Visibility::Inherited`.
- setting the `visibility.is_visible` field should now directly set the value: `*visibility = Visibility::Inherited`.
- usage of `Visibility::VISIBLE` or `Visibility::INVISIBLE` should now use `Visibility::Inherited` or `Visibility::Hidden` respectively.
- `ComputedVisibility::INVISIBLE` and `SpatialBundle::VISIBLE_IDENTITY` have been renamed to `ComputedVisibility::HIDDEN` and `SpatialBundle::INHERITED_IDENTITY` respectively.






Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2022-12-25 00:39:29 +00:00
..
2d_shapes.rs Rename shapes examples for consistency (#6082) 2022-09-25 00:57:07 +00:00
mesh2d.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
mesh2d_manual.rs enum Visibility component (#6320) 2022-12-25 00:39:29 +00:00
mesh2d_vertex_color_texture.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
move_sprite.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
pixel_perfect.rs Add pixelated Bevy to assets and an example (#6408) 2022-11-14 22:15:46 +00:00
rotation.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
sprite.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
sprite_flipping.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
sprite_sheet.rs Sprite sheet example: specify animation indices (#6861) 2022-12-11 18:22:10 +00:00
text2d.rs Add global time scaling (#5752) 2022-10-22 18:52:29 +00:00
texture_atlas.rs Add more info to texture loading error in texture_atlas example (#6456) 2022-11-05 16:30:13 +00:00
transparency_2d.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00