pub struct TabItem<Msg = Callback> { /* private fields */ }Expand description
One tab of a TabBar: what is drawn on it, and what it is called.
The four shorthands on the bar — tab, icon_tab,
icon_only_tab and tab_widget — each
build one of these and are what most call sites should write. This is the door to the
one thing they cannot carry: how wide a tab asks to be on a bar that scrolls.
The label is never optional, even on a tab that draws neither the word nor anything resembling one. It is what a screen reader says, and a tab nobody can name is a tab nobody can use. The reference leaves such a tab nameless and expects the caller to wrap it in something that names it; asking for the word here costs nothing and cannot be forgotten.
use frus_widgets::{Align, Badge, Container, Flex, TabBar, TabItem, text};
let unread: Flex<Msg> = Flex::row()
.align(Align::Center)
.gap(6.0)
.child(text("Inbox").size(14.0))
.child(Badge::new("12"));
let bar = TabBar::new(0, Msg::Select)
.scrollable(true)
.item(
TabItem::widget(unread, "Inbox").width(110.0),
Container::<Msg>::new(),
)
.tab("Archive", Container::<Msg>::new());Implementations§
Source§impl<Msg> TabItem<Msg>
impl<Msg> TabItem<Msg>
Sourcepub fn new(label: impl Into<String>) -> Self
pub fn new(label: impl Into<String>) -> Self
A tab that is a word — what TabBar::tab builds.
Sourcepub fn icon(icon: IconData, label: impl Into<String>) -> Self
pub fn icon(icon: IconData, label: impl Into<String>) -> Self
A tab with an icon over its label.
Sourcepub fn icon_only(icon: IconData, label: impl Into<String>) -> Self
pub fn icon_only(icon: IconData, label: impl Into<String>) -> Self
A tab showing only an icon, in a row of the ordinary height. The label is what it is called, not what is drawn.
Sourcepub fn widget(
child: impl Widget<Msg> + 'static,
label: impl Into<String>,
) -> Self
pub fn widget( child: impl Widget<Msg> + 'static, label: impl Into<String>, ) -> Self
A tab the caller draws: a label with an unread count beside it, a coloured dot, two lines, rich text.
label is what it is called. The bar paints nothing of its own on such a tab —
drawing a label under the caller’s own would be drawing the same thing twice — but
the ink of a press, the indicator and the announcement are all still the bar’s.
Sourcepub fn width(self, width: f32) -> Self
pub fn width(self, width: f32) -> Self
How wide this tab asks to be when the bar scrolls, in logical pixels.
A bar that does not scroll shares its width between its tabs in equal parts and never asks, so this is meaningless there. When it does scroll, an ordinary tab is measured from its label and a tab the caller drew cannot be measured at all — a widget cannot be asked how wide it would like to be (#52) — so it falls back to its name, which is right for a label with a dot beside it and short for a label with a count in a pill. This is how the caller says.