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, with drop_mark for a drop target and Reorder for a tab carried along its strip.

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§

Bar
Label
What a tab shows.
Move
A committed move. The active tab remains the host’s choice.
OutsideDrop
A carried tab released outside its strip; local reordering is cancelled.
Reorder
Persistent gesture and animation state, one per strip.
Strip
An ordered set of tabs, one of them active.
TabBar

Enums§

Close
When a tab’s × is on show.
Side
The edge of a tab a drop lands on.
State
How a tab reads.
Track
What a reorderable strip’s tabs stand on — see Bar::on_track. A track and its tabs are capsules, a Track::Flat’s rounded as a control is; the tabs share its width equally down to TRACK_MIN_WIDTH, their labels centred, and a line parts two resting neighbours.

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.
TAB_PAD
Inset at a tab’s ends, and the gap between what it holds.
TRACK_HEIGHT
How tall a Track stands. Its tabs fill it inside its border and [TRACK_PAD].
TRACK_MIN_WIDTH
The narrowest a tab on a Track gets before its strip scrolls.

Functions§

bar
The strip. Tabs go in it; a +, a ··· and anything else on the row are the caller’s, outside this.
chip
A tab’s frame without its label: its height, inset, corners and ring slot, the label’s ink for state, and the selected wash and ring while State::Focused. What tab is drawn on, for a label that is not a Label.
close
A tab’s ×, for the key its tab was built with. The click is the caller’s. It stops mouse-down propagation, so a press on it neither clicks nor picks up the tab under it.
drop_mark
A tab’s drop mark, for its drag_over style: a 1px accent line on side, in the gap beside the tab. A shadow, so the tab’s layout does not move.
tab
One tab, up to the ×: pass the same key to close and chain the result on as a child.