Skip to content

Commit

Permalink
Add helper methods on Visibility (#14898)
Browse files Browse the repository at this point in the history
Fixes #14825

Edit: After feedback, these are the updated methods:

- `toggle_inherited_visible(&mut self)`
- Toggles between `Visibility::Inherited` and `Visibility::Visible`. If
the value is `Visibility::Hidden`, it remains unaffected.
- `toggle_inherited_hidden(&mut self)`
- Toggles between `Visibility::Inherited` and `Visibility::Hidden`. If
the value is `Visibility::Visible`, it remains unaffected.
- `toggle_visible_hidden(&mut self)`
- Toggles between `Visibility::Visible` and `Visibility::Hidden`. If the
value is `Visibility::Inherited`, it remains unaffected.

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
  • Loading branch information
ThomasAlban and chescock authored Aug 24, 2024
1 parent cccc113 commit 0070bdc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 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,39 @@ pub enum Visibility {
Visible,
}

impl Visibility {
/// Toggles between `Visibility::Inherited` and `Visibility::Visible`.
/// If the value is `Visibility::Hidden`, it remains unaffected.
#[inline]
pub fn toggle_inherited_visible(&mut self) {
*self = match *self {
Visibility::Inherited => Visibility::Visible,
Visibility::Visible => Visibility::Inherited,
_ => *self,
};
}
/// Toggles between `Visibility::Inherited` and `Visibility::Hidden`.
/// If the value is `Visibility::Visible`, it remains unaffected.
#[inline]
pub fn toggle_inherited_hidden(&mut self) {
*self = match *self {
Visibility::Inherited => Visibility::Hidden,
Visibility::Hidden => Visibility::Inherited,
_ => *self,
};
}
/// Toggles between `Visibility::Visible` and `Visibility::Hidden`.
/// If the value is `Visibility::Inherited`, it remains unaffected.
#[inline]
pub fn toggle_visible_hidden(&mut self) {
*self = match *self {
Visibility::Visible => Visibility::Hidden,
Visibility::Hidden => Visibility::Visible,
_ => *self,
};
}
}

// Allows `&Visibility == Visibility`
impl PartialEq<Visibility> for &Visibility {
#[inline]
Expand Down

0 comments on commit 0070bdc

Please sign in to comment.