Add helper methods on Visibility (#14898)

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>
This commit is contained in:
Thomas Alban 2024-08-24 14:49:54 +01:00 committed by GitHub
parent cccc1137b4
commit 0070bdccd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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]