pub trait HasClasses {
Show 13 methods
// Required methods
fn classes(&self) -> &Classes;
fn classes_mut(&mut self) -> &mut Classes;
// Provided methods
fn has_class(&self, class: &str) -> bool { ... }
fn add_class(&mut self, class: impl Into<ClassName>) -> &mut Self
where Self: Sized { ... }
fn set_class(
&mut self,
class: impl Into<ClassName>,
present: bool,
) -> &mut Self
where Self: Sized { ... }
fn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Self
where Self: Sized { ... }
fn with_class(self, class: impl Into<ClassName>) -> Self
where Self: Sized { ... }
fn add_classes(&mut self, classes: Classes) -> &mut Self { ... }
fn with_classes(self, classes: Classes) -> Self
where Self: Sized { ... }
fn add_class_if(
&mut self,
class: impl Into<ClassName>,
condition: bool,
) -> &mut Self
where Self: Sized { ... }
fn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Self
where Self: Sized { ... }
fn iter_classes(&self) -> Iter<'_, ClassName> ⓘ { ... }
fn classes_as_slice(&self) -> &[ClassName] { ... }
}Expand description
Any widgets supporting crate::class::Classes must implement this trait.
Required Methods§
Provided Methods§
Sourcefn add_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
fn add_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
Add the given class in-place.
Sourcefn set_class(&mut self, class: impl Into<ClassName>, present: bool) -> &mut Selfwhere
Self: Sized,
fn set_class(&mut self, class: impl Into<ClassName>, present: bool) -> &mut Selfwhere
Self: Sized,
Add the given class in-place if present, remove it otherwise.
Use this for a setter that takes a bool, so that the last call wins.
Sourcefn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
fn remove_class(&mut self, class: impl Into<ClassName>) -> &mut Selfwhere
Self: Sized,
Remove the given class in-place.
Sourcefn with_class(self, class: impl Into<ClassName>) -> Selfwhere
Self: Sized,
fn with_class(self, class: impl Into<ClassName>) -> Selfwhere
Self: Sized,
Add the given class by consuming self.
Sourcefn add_classes(&mut self, classes: Classes) -> &mut Self
fn add_classes(&mut self, classes: Classes) -> &mut Self
Append all the given classes at the end, deduplicating them.
Sourcefn with_classes(self, classes: Classes) -> Selfwhere
Self: Sized,
fn with_classes(self, classes: Classes) -> Selfwhere
Self: Sized,
Append all the given classes at the end, deduplicating them. Consuming self.
Sourcefn add_class_if(
&mut self,
class: impl Into<ClassName>,
condition: bool,
) -> &mut Selfwhere
Self: Sized,
fn add_class_if(
&mut self,
class: impl Into<ClassName>,
condition: bool,
) -> &mut Selfwhere
Self: Sized,
Add a class to the list if the condition is true.
A class is never added twice. This never removes a class: use Self::set_class for that.
Sourcefn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Selfwhere
Self: Sized,
fn with_class_if(self, class: impl Into<ClassName>, condition: bool) -> Selfwhere
Self: Sized,
Add the given class by consuming self if the condition is true.
A class is never added twice. This never removes a class: use Self::set_class for that.
Sourcefn iter_classes(&self) -> Iter<'_, ClassName> ⓘ
fn iter_classes(&self) -> Iter<'_, ClassName> ⓘ
Iterate over the classes, in the order they were added.
Sourcefn classes_as_slice(&self) -> &[ClassName]
fn classes_as_slice(&self) -> &[ClassName]
Return the classes as a slice.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".