Skip to main content

Controls

Trait Controls 

Source
pub trait Controls: ThemeExt {
    // Provided methods
    fn toggle(&self, on: bool) -> Div { ... }
    fn checkbox(&self, checked: bool) -> Div { ... }
    fn radio_button(&self, selected: bool) -> Div { ... }
    fn progress_bar(&self, fraction: f32) -> Div { ... }
    fn slider(&self, fraction: f32) -> Div { ... }
    fn select_trigger(&self, label: impl Into<SharedString>) -> Div { ... }
    fn toggle_group(&self) -> Div { ... }
    fn toggle_group_item(
        &self,
        label: impl Into<SharedString>,
        selected: bool,
    ) -> Div { ... }
}

Provided Methods§

Source

fn toggle(&self, on: bool) -> Div

Display-only toggle switch (the reference branch-picker.tsx Toggle): an 18×32 pill whose knob slides right and track flips white when on. State is owned by the parent row — the caller adds .id(..) and .on_click(..).

Source

fn checkbox(&self, checked: bool) -> Div

Display-only checkbox: a 16px rounded square that fills with the text tone and shows a check when on. State is the caller’s; add .id(..)/.on_click(..).

Source

fn radio_button(&self, selected: bool) -> Div

Display-only radio button: a 16px ring with an inner dot when selected. Radios are a set — the caller owns which index is on.

Source

fn progress_bar(&self, fraction: f32) -> Div

Determinate progress bar. fraction is clamped to 0..=1; the track keeps its full width so the row never reflows as the value moves.

Source

fn slider(&self, fraction: f32) -> Div

Display-only slider: filled track behind a knob at fraction (clamped to 0..=1). Dragging is the caller’s — it owns the value and the mouse handlers; this is the paint.

The element is the drag source, so the gesture is grab-anywhere-and-slide, and slider_fraction turns the pointer into the value — passing the element’s own id, because every slider hears every slider’s drag:

focus::focusable(&theme, &self.slider, theme.slider(self.level))
    .id("slider")
    .on_drag(SliderDrag("slider".into()), |_, _, _, cx| cx.new(|_| gpui::Empty))
    .on_drag_move(cx.listener(|view, event: &DragMoveEvent<SliderDrag>, _, cx| {
        let Some(fraction) = widgets::slider_fraction(event, "slider", cx) else {
            return;
        };
        view.level = fraction;
        cx.notify();
    }))
Source

fn select_trigger(&self, label: impl Into<SharedString>) -> Div

The face of a select: current value plus a chevron, shaped and toned like crate::input::TextField so a form of fields and selects reads as one system. One look, open or shut — the menu hanging under it is what says which it is.

There is no Select component, deliberately — a select IS this trigger plus crate::popover::anchored_menu_below over crate::popover::menu_rows, and the caller already owns the open state and the selection. Wrapping that in a struct would buy an abstraction and cost the caller its control over both.

Source

fn toggle_group(&self) -> Div

Segmented control: one pill holding mutually exclusive choices, for when there are few enough that a Self::select_trigger would be overkill.

self_start because a segmented control must hug its segments: dropped into a flex_col, flexbox’s default align-items: stretch would otherwise blow it out to the column’s full width.

Source

fn toggle_group_item( &self, label: impl Into<SharedString>, selected: bool, ) -> Div

One segment. The selected segment carries the active wash over the track’s own — the two alphas stack, which is what makes it read — and the rest are bare, so exactly one is pressed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Controls for Theme

Implementors§