Skip to main content

tabs

Function tabs 

Source
pub fn tabs<S: Into<String>>(
    labels: impl IntoIterator<Item = S>,
    selected: usize,
) -> Segmented
Expand description

Tab bar with an underline; the app shows the selected tab’s content. Each tab is as wide as its label, plus an equal share of the spare width; the selected label turns bold, morphing glyph by glyph.

§Example

use dfui::widgets::{Styled, column, stateful, tabs, text};
use dfui::{Color, Element};

const PAGES: [(&str, &str); 3] = [
    ("Inbox", "3 new messages"),
    ("Sent", "Nothing waiting to send"),
    ("Archive", "128 messages"),
];

fn view() -> Element {
    stateful(|&tab: &usize, h| {
        column([
            tabs(PAGES.map(|(label, _)| label), tab)
                .accent(Color::hex(0x3b6fe0))
                .on_change(move |cx, i| cx.update(h, move |t: &mut usize| *t = i))
                .into(),
            text(PAGES[tab].1).size(18.0).into(),
        ])
        .gap(16.0)
    })
    .padding(16.0)
    .into()
}

fn main() {
    dfui::run(view);
}