# Classes

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/controls/struct-classes/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
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`](/docs/0.5.0/api/ferroui-base/controls/trait-ipseudoclasses/).

The value is a shared handle: clones refer to the same collection, and
handles compare by identity.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L24)

## Members

- [`new`](#function-new)
- [`from_names`](#function-from_names)
- [`ptr_eq`](#function-ptr_eq)
- [`parse`](#function-parse)
- [`capacity`](#function-capacity)
- [`set_capacity`](#function-set_capacity)
- [`count`](#function-count)
- [`get`](#function-get)
- [`snapshot`](#function-snapshot)
- [`contains`](#function-contains)
- [`add_collection_changed`](#function-add_collection_changed)
- [`remove_collection_changed`](#function-remove_collection_changed)
- [`add`](#function-add)
- [`add_range`](#function-add_range)
- [`clear`](#function-clear)
- [`insert`](#function-insert)
- [`insert_range`](#function-insert_range)
- [`remove`](#function-remove)
- [`remove_all`](#function-remove_all)
- [`remove_at`](#function-remove_at)
- [`remove_range`](#function-remove_range)
- [`replace`](#function-replace)
- [`set`](#function-set)
- [`add_listener`](#function-add_listener)
- [`remove_listener`](#function-remove_listener)
- [`listener_count`](#function-listener_count)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```

Creates an empty collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L46)

<a id="function-from_names"></a>

### from_names

```rust
fn from_names<S: Into<String>>(items: impl IntoIterator<Item = S>) -> Self
```

Creates a collection from the given class names.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L51)

<a id="function-ptr_eq"></a>

### ptr_eq

```rust
fn ptr_eq(self: &Self, other: &Self) -> bool
```

Whether two handles refer to the same collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L59)

<a id="function-parse"></a>

### parse

```rust
fn parse(s: &str) -> Classes
```

Parses a space-separated list of class names.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L64)

<a id="function-capacity"></a>

### capacity

```rust
fn capacity(self: &Self) -> usize
```

The number of class names the collection can hold before its storage
grows.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L70)

<a id="function-set_capacity"></a>

### set_capacity

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L79)

<a id="function-count"></a>

### count

```rust
fn count(self: &Self) -> usize
```

The number of classes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L84)

<a id="function-get"></a>

### get

```rust
fn get(self: &Self, index: usize) -> String
```

The class at `index`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L89)

<a id="function-snapshot"></a>

### snapshot

```rust
fn snapshot(self: &Self) -> Rc<Vec<String>>
```

A snapshot of the classes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L94)

<a id="function-contains"></a>

### contains

```rust
fn contains(self: &Self, name: &str) -> bool
```

Returns whether a class is present in the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L99)

<a id="function-add_collection_changed"></a>

### add_collection_changed

```rust
fn add_collection_changed(self: &Self, handler: Rc<CollectionChangedHandler<String>>) -> u64
```

Subscribes to collection changes; see `FerroList::add_collection_changed`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L104)

<a id="function-remove_collection_changed"></a>

### remove_collection_changed

```rust
fn remove_collection_changed(self: &Self, token: u64) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L108)

<a id="function-add"></a>

### add

```rust
fn add(self: &Self, name: &str)
```

Adds a style class to the collection. Only standard classes may be
added via this method.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L114)

<a id="function-add_range"></a>

### add_range

```rust
fn add_range<S: AsRef<str>>(self: &Self, names: impl IntoIterator<Item = S>)
```

Adds style classes to the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L123)

<a id="function-clear"></a>

### clear

```rust
fn clear(self: &Self)
```

Removes all non-pseudoclasses from the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L137)

<a id="function-insert"></a>

### insert

```rust
fn insert(self: &Self, index: usize, name: &str)
```

Inserts a style class into the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L149)

<a id="function-insert_range"></a>

### insert_range

```rust
fn insert_range<S: AsRef<str>>(self: &Self, index: usize, names: impl IntoIterator<Item = S>)
```

Inserts style classes into the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L158)

<a id="function-remove"></a>

### remove

```rust
fn remove(self: &Self, name: &str) -> bool
```

Removes a style class from the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L174)

<a id="function-remove_all"></a>

### remove_all

```rust
fn remove_all<S: AsRef<str>>(self: &Self, names: impl IntoIterator<Item = S>)
```

Removes style classes from the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L185)

<a id="function-remove_at"></a>

### remove_at

```rust
fn remove_at(self: &Self, index: usize)
```

Removes the style class at the specified index.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L198)

<a id="function-remove_range"></a>

### remove_range

```rust
fn remove_range(self: &Self, index: usize, count: usize)
```

Removes a range of style classes from the collection.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L206)

<a id="function-replace"></a>

### replace

```rust
fn replace<S: AsRef<str>>(self: &Self, source: &[S])
```

Removes all non-pseudoclasses in the collection and adds a new set.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L212)

<a id="function-set"></a>

### set

```rust
fn set(self: &Self, name: &str, value: bool)
```

Adds or removes a style class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L225)

<a id="function-add_listener"></a>

### add_listener

```rust
fn add_listener(self: &Self, listener: Rc<dyn Fn() -> ()>) -> u64
```

Registers a listener invoked whenever the classes change. Returns a
token for `remove_listener`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L237)

<a id="function-remove_listener"></a>

### remove_listener

```rust
fn remove_listener(self: &Self, token: u64) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L241)

<a id="function-listener_count"></a>

### listener_count

```rust
fn listener_count(self: &Self) -> usize
```

The number of registered listeners.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/controls/classes.rs#L246)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Default`
- `PartialEq`
- `Debug`
- [`IPseudoClasses`](/docs/0.5.0/api/ferroui-base/controls/trait-ipseudoclasses/)
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
