pub struct Tabs<'a> { /* private fields */ }Expand description
A horizontal strip of titles with the tab at selected highlighted.
Unlike Table/List, Tabs is a plain Widget, not a
StatefulWidget: there is no scroll offset for a tab strip, only a
selected index, so it takes selected: Option<usize> directly (set via Tabs::select)
rather than a ListState – the app is free to drive that index however
it likes (a plain usize it owns, a FocusRing, whatever fits), the same
“app- or interaction-machinery-driven, widget just reads it” division of labor as every other
widget here.
Titles render left to right, column_spacing blank columns apart (default 1, matching
Table::column_spacing), with an optional single-character
divider (default None, i.e. no divider) centered in that spacing – set with
Tabs::divider. Drawing stops once a title would start past the area’s right edge; there is
no horizontal scrolling.
style and selected_style each default to the same fixed palette as
Table’s row_style/selected_style; set them with Tabs::style/
Tabs::selected_style.
Implementations§
Source§impl<'a> Tabs<'a>
impl<'a> Tabs<'a>
Sourcepub fn new(titles: &'a [&'a str]) -> Self
pub fn new(titles: &'a [&'a str]) -> Self
A tab strip over titles, with nothing selected and the default style.
Sourcepub const fn select(self, index: Option<usize>) -> Self
pub const fn select(self, index: Option<usize>) -> Self
Select tab index (or clear the selection with None).
Sourcepub const fn selected_style(self, style: Style) -> Self
pub const fn selected_style(self, style: Style) -> Self
Set the style of the selected tab, including its background fill.
Sourcepub const fn column_spacing(self, spacing: u16) -> Self
pub const fn column_spacing(self, spacing: u16) -> Self
Set the number of blank columns between tabs.
Sourcepub const fn divider(self, divider: Option<char>) -> Self
pub const fn divider(self, divider: Option<char>) -> Self
Set a divider character drawn within the spacing between tabs. None (the default) draws
no divider – just column_spacing blank columns.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Applies theme’s named roles to this tab strip: style becomes theme.dim (unselected
tabs read as de-emphasized) on theme.panel_bg, and selected_style becomes
theme.accent on theme.panel_bg.
style sets an explicit background rather than leaving it at Style::new()’s default:
an unset background isn’t “transparent” once a real backend draws it (a bare
Color::Default cell paints as solid black behind the glyph – see
retroglyph-software’s DEFAULT_BG), so this widget assumes it’s drawn on
theme.panel_bg, true when composed with a themed super::Panel/super::Modal.
Drawing this tab strip directly on the raw screen background instead needs a manual
.style(...) override afterwards.
Call before any manual Tabs::style/Tabs::selected_style override you want to keep.