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.
- Outside
Drop - 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, aTrack::Flat’s rounded as a control is; the tabs share its width equally down toTRACK_MIN_WIDTH, their labels centred, and a line parts two resting neighbours.
Constants§
- MARK_
SIZE - The box
Label::markpaints in. Lucide’scircle-smallinks 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
Trackstands. Its tabs fill it inside its border and [TRACK_PAD]. - TRACK_
MIN_ WIDTH - The narrowest a tab on a
Trackgets 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 whileState::Focused. Whattabis drawn on, for a label that is not aLabel. - close
- A tab’s
×, for thekeyitstabwas 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 itsdrag_overstyle: a 1px accent line onside, in the gap beside the tab. A shadow, so the tab’s layout does not move. - tab
- One tab, up to the
×: pass the samekeytocloseand chain the result on as a child.