Skip to content

Commit

Permalink
Add mutating toggle method to Visibility component (bevyengine#6268)
Browse files Browse the repository at this point in the history
# Objective

Make toggling the visibility of an entity slightly more convenient.

## Solution

Add a mutating `toggle` method to the `Visibility` component

```rust
fn my_system(mut query: Query<&mut Visibility, With<SomeMarker>>) {
    let mut visibility = query.single_mut();
    // before: 
    visibility.is_visible = !visibility.is_visible;
    // after:
    visibility.toggle();
}
```

## Changelog

### Added
- Added a mutating `toggle` method to the `Visibility` component
  • Loading branch information
sullyj3 authored and Pietrek14 committed Dec 17, 2022
1 parent bf0de2d commit 8374a14
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_render/src/view/visibility/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ impl Visibility {

/// A [`Visibility`], set as invisible.
pub const INVISIBLE: Self = Visibility { is_visible: false };

/// Toggle the visibility.
pub fn toggle(&mut self) {
self.is_visible = !self.is_visible;
}
}

/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering
Expand Down

0 comments on commit 8374a14

Please sign in to comment.