Skip to main content

TabItem

Struct TabItem 

Source
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>

Source

pub fn new(label: impl Into<String>) -> Self

A tab that is a word — what TabBar::tab builds.

Source

pub fn icon(icon: IconData, label: impl Into<String>) -> Self

A tab with an icon over its label.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<Msg = Callback> !RefUnwindSafe for TabItem<Msg>

§

impl<Msg = Callback> !Send for TabItem<Msg>

§

impl<Msg = Callback> !Sync for TabItem<Msg>

§

impl<Msg = Callback> !UnwindSafe for TabItem<Msg>

§

impl<Msg> Freeze for TabItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: Freeze,

§

impl<Msg> Unpin for TabItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: Unpin,

§

impl<Msg> UnsafeUnpin for TabItem<Msg>
where Option<Rc<dyn Widget<Msg>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.