Classes
struct · ferroui-base · v0.5.0
struct Classes
Holds a collection of style classes for a styled element.
Similar to CSS, each control may have any number of styling classes
applied. Classes whose name starts with : are pseudoclasses and may only
be added or removed by the control itself, through IPseudoClasses.
The value is a shared handle: clones refer to the same collection, and handles compare by identity.
Members
newfrom_namesptr_eqparsecapacityset_capacitycountgetsnapshotcontainsadd_collection_changedremove_collection_changedaddadd_rangeclearinsertinsert_rangeremoveremove_allremove_atremove_rangereplacesetadd_listenerremove_listenerlistener_count
new
fn new() -> Self
Creates an empty collection.
from_names
fn from_names<S: Into<String>>(items: impl IntoIterator<Item = S>) -> Self
Creates a collection from the given class names.
ptr_eq
fn ptr_eq(self: &Self, other: &Self) -> bool
Whether two handles refer to the same collection.
parse
fn parse(s: &str) -> Classes
Parses a space-separated list of class names.
capacity
fn capacity(self: &Self) -> usize
The number of class names the collection can hold before its storage grows.
set_capacity
fn set_capacity(self: &Self, capacity: usize)
Sets the number of class names the collection can hold before its storage grows.
Panics
Panics if capacity is less than the number of class names.
count
fn count(self: &Self) -> usize
The number of classes.
get
fn get(self: &Self, index: usize) -> String
The class at index.
snapshot
fn snapshot(self: &Self) -> Rc<Vec<String>>
A snapshot of the classes.
contains
fn contains(self: &Self, name: &str) -> bool
Returns whether a class is present in the collection.
add_collection_changed
fn add_collection_changed(self: &Self, handler: Rc<CollectionChangedHandler<String>>) -> u64
Subscribes to collection changes; see FerroList::add_collection_changed.
remove_collection_changed
fn remove_collection_changed(self: &Self, token: u64) -> bool
add
fn add(self: &Self, name: &str)
Adds a style class to the collection. Only standard classes may be added via this method.
add_range
fn add_range<S: AsRef<str>>(self: &Self, names: impl IntoIterator<Item = S>)
Adds style classes to the collection.
clear
fn clear(self: &Self)
Removes all non-pseudoclasses from the collection.
insert
fn insert(self: &Self, index: usize, name: &str)
Inserts a style class into the collection.
insert_range
fn insert_range<S: AsRef<str>>(self: &Self, index: usize, names: impl IntoIterator<Item = S>)
Inserts style classes into the collection.
remove
fn remove(self: &Self, name: &str) -> bool
Removes a style class from the collection.
remove_all
fn remove_all<S: AsRef<str>>(self: &Self, names: impl IntoIterator<Item = S>)
Removes style classes from the collection.
remove_at
fn remove_at(self: &Self, index: usize)
Removes the style class at the specified index.
remove_range
fn remove_range(self: &Self, index: usize, count: usize)
Removes a range of style classes from the collection.
replace
fn replace<S: AsRef<str>>(self: &Self, source: &[S])
Removes all non-pseudoclasses in the collection and adds a new set.
set
fn set(self: &Self, name: &str, value: bool)
Adds or removes a style class.
add_listener
fn add_listener(self: &Self, listener: Rc<dyn Fn() -> ()>) -> u64
Registers a listener invoked whenever the classes change. Returns a
token for remove_listener.
remove_listener
fn remove_listener(self: &Self, token: u64) -> bool
listener_count
fn listener_count(self: &Self) -> usize
The number of registered listeners.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedErasedDestructorIntoEitherCloneDefaultPartialEqDebugIPseudoClassesMarkupTypedValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.