# Simplify toggle, some \`ui2\` reorganization \(\#3234\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b243de407ebc2c5ff8d5245a1fb1c39c8ef82804)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b243de407ebc2c5ff8d5245a1fb1c39c8ef82804

Requested commit: b243de407ebc2c5ff8d5245a1fb1c39c8ef82804

Commit: b243de407ebc2c5ff8d5245a1fb1c39c8ef82804

Tree: f91d4b7ebfb40008643aaeb1d625ab26831e6c2f

Author: Nate Butler

Committer: GitHub

## Message

````
Simplify toggle, some `ui2` reorganization (#3234)

[[PR Description]]

A few mix organizational things in UI, as well as some toggle changes.

Simplify toggle:

```rust
/// Whether the entry is toggleable, and if so, whether it is currently toggled.
///
/// To make an element toggleable, simply add a `Toggle::Toggled(_)` and handle it's cases.
///
/// You can check if an element is toggleable with `.is_toggleable()`
///
/// Possible values:
/// - `Toggle::NotToggleable` - The entry is not toggleable
/// - `Toggle::Toggled(true)` - The entry is toggleable and toggled
/// - `Toggle::Toggled(false)` - The entry is toggleable and not toggled
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Toggle {
    NotToggleable,
    Toggled(bool),
}
```

Adds helper functions to easily get the toggle and toggleable states:

```rust
impl Toggle {
    /// Returns true if the entry is toggled (or is not toggleable.)
    ///
    /// As element that isn't toggleable is always "expanded" or "enabled"
    /// returning true in that case makes sense.
    pub fn is_toggled(&self) -> bool {
        match self {
            Self::Toggled(false) => false,
            _ => true,
        }
    }

    pub fn is_toggleable(&self) -> bool {
        match self {
            Self::Toggled(_) => true,
            _ => false,
        }
    }
}
```

Pulls `disclosure_control` out of components and creates a common def:

```rust
pub fn disclosure_control<V: 'static>(toggle: Toggle) -> impl Component<V> {
    match (toggle.is_toggleable(), toggle.is_toggled()) {
        (false, _) => div(),
        (_, true) => div().child(
            IconElement::new(Icon::ChevronDown)
                .color(IconColor::Muted)
                .size(IconSize::Small),
        ),
        (_, false) => div().child(
            IconElement::new(Icon::ChevronRight)
                .color(IconColor::Muted)
                .size(IconSize::Small),
        ),
    }
}
```

disclosure_control will likely get pulled into it's own component in the
future instead of being in toggle.

Release Notes:

- N/A
````

## Parents

- [ac9efaebb706d498fe3a96613f61ee55f25b2bfe](https://git.cafe/gitcafe/zed/commit/ac9efaebb706d498fe3a96613f61ee55f25b2bfe?format=markdown)

- [b125cc279f5cbcb2042d7383322119fcddc2e00c](https://git.cafe/gitcafe/zed/commit/b125cc279f5cbcb2042d7383322119fcddc2e00c?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b243de407ebc2c5ff8d5245a1fb1c39c8ef82804?format=markdown)
