iced-cube

Navigation

Tabs

Switches between related views that share one place on screen.

use iced_cube::navigation::tabs::{self, Variant, tab, tabs};
API reference
Underline: Labels over a rule, with a disabled tab.Underline: Labels over a rule, with a disabled tab.
Static preview
Underline. Labels over a rule, with a disabled tab.

Usage

The app owns a tabs::State and routes events into it, then renders the view for state.selected() itself. The tab list is only the switcher, so the content can be anything.

Next and Previous wrap round at the ends and skip disabled tabs. The widget does not listen to the keyboard itself: the app subscribes with keys::subscription() and resolves each key press through a keymap, as the keyboard example does. The arrow keys, Home and End are bound app-wide, so an app with text inputs or other arrow-driven controls may want to unbind them and keep Ctrl+Tab.

Document tabs also bind Ctrl+Tab and Ctrl+Shift+Tab. When both are on screen, unbind the chords from one of the keymaps, usually this one, with tabs::default_keymap().unbind(&Chord::named(Named::Tab).ctrl()).unbind(&Chord::named(Named::Tab).ctrl().shift()). See Keyboard shortcuts for other shared keys.

Use the underline variant for page sections and the pills variant for a compact switch between views of the same data.

Examples

Pills

A segmented control with icons.

Pills: A segmented control with icons.Pills: A segmented control with icons.
Static preview

Keyboard shortcuts

Key presses resolve through the default keymap, skipping disabled tabs. In the browser, use the arrow keys, Home and End: browsers keep Ctrl+Tab for themselves.

Keyboard shortcuts: Key presses resolve through the default keymap, skipping disabled tabs. In the browser, use the arrow keys, Home and End: browsers keep Ctrl+Tab for themselves.Keyboard shortcuts: Key presses resolve through the default keymap, skipping disabled tabs. In the browser, use the arrow keys, Home and End: browsers keep Ctrl+Tab for themselves.
Static preview

API

ItemDescription
State::new(tabs)Holds the tabs and selects the first enabled one.
.with_selected(id)Starts on a given tab, if it exists and is enabled.
tab(id, label)Creates a tab. Add .icon(glyph) or .disabled(true).
state.update(Event)Select(id), Next or Previous. Returns the new id when the selection changed.
state.selected() / state.is_selected(id)The selected id, or None when every tab is disabled, and a check for one id.
state.tabs()The tabs, in order.
state.set_disabled(id, bool)Enables or disables a tab at runtime.
tabs(&state)Renders the tab list. Tabs render disabled until .on_event is set.
.variant(Variant)Underline or Pills. Defaults to Underline.
.width(length)Overrides the width. Underline tabs fill the available width and pills shrink to fit by default.
.on_event(f)Maps tab events to your message, such as Message::Tabs.
tabs::default_keymap()The default shortcuts as a Keymap<Action>. Bind, unbind or clear chords to change them.
action.event(&state)Turns a resolved Action (Next, Previous, First or Last) into the Event to pass to state.update.

Keyboard

Default shortcuts. Every one can be changed or removed with a keymap; see Keyboard shortcuts.

KeysAction
Ctrl+Tab or ArrowRightNext Selects the next enabled tab, wrapping at the end.
Ctrl+Shift+Tab or ArrowLeftPrevious Selects the previous enabled tab, wrapping at the start.
HomeFirst Selects the first enabled tab.
EndLast Selects the last enabled tab.
Esc