Skip to main content

Module tabs

Module tabs 

Source
Expand description

Tabs — an ordered strip of open things, one of them in front.

Not toggle_group, which picks a value out of a fixed set, and not tab_bar, which switches between sections of one page. A tab here has identity: it arrives, it can be closed, it can be dragged past its neighbour, and the strip outlives any particular membership.

Strip is the order and the activation, and imports no gpui — closing, cycling and reordering are Vec arithmetic, testable without a window. The paint is bar, tab and close.

What a tab holds never enters this module. Id is the caller’s key, and the body it opens is the caller’s match on that key.

ui::tabs::bar("panel-tabs").children(self.strip.tabs().iter().map(|id| {
    let key = SharedString::from(format!("panel-{id}"));
    let state = match self.strip.active() == Some(id) {
        true => tabs::State::Focused,
        false => tabs::State::Resting,
    };
    tabs::tab(&theme, key.clone(), self.label(id), state)
        .on_click(cx.listener(move |view, _, _, cx| view.show(id, cx)))
        .child(
            tabs::close(&theme, key, tabs::Close::OnHover)
                .on_click(cx.listener(move |view, _, _, cx| view.close(id, cx))),
        )
}))

Structs§

Label
What a tab shows.
Strip
An ordered set of tabs, one of them active.

Enums§

Close
When a tab’s × is on show.
State
How a tab reads.

Constants§

MARK_SIZE
The box Label::mark paints in. Lucide’s circle-small inks 14 of its 24 units, which puts a solid one at 6px across.
MAX_WIDTH
How wide one tab grows before its label truncates.

Functions§

bar
The strip. Tabs go in it; a +, a ··· and anything else on the row are the caller’s, outside this.
close
A tab’s ×, for the key its tab was built with. The click is the caller’s, and has to stop propagating or the tab under it takes the press as well.
tab
One tab, up to the ×: pass the same key to close and chain the result on as a child.