Expand description
A tabs component that provides a horizontal tab bar with animated indicator and paged content.
The tabs
component renders a row of tab titles and a content area. It manages an internal
animated indicator that transitions between active tabs and scrolls the content area to match
the selected tab. State (see TabsState
) is provided by the application to control the
currently active tab and animation progress.
§Key Components
tabs
: The main component function. Call it inside a component to render a tab group.TabsState
: Holds active tab index, animation progress and per-tab ripple states.TabsArgs
: Configuration for the tabs layout and indicator color.
§Behavior
- The active tab indicator animates between tabs using an easing function.
- Clicking a tab updates the shared
TabsState
(viaTabsState::set_active_tab
) and triggers the indicator/content animation. - The component registers a
input_handler
to advance the animation while a transition is in progress.
§Example
use std::sync::Arc;
use parking_lot::RwLock;
use tessera_ui_basic_components::tabs::{tabs, TabsArgsBuilder, TabsState};
// Shared state for the tabs (start on tab 0)
let tabs_state = Arc::new(RwLock::new(TabsState::new(0)));
// Render a simple tab group with two tabs (titles and contents are closures)
tabs(
TabsArgsBuilder::default().build().unwrap(),
tabs_state.clone(),
|scope| {
scope.child(|| { /* title 0 */ }, || { /* content 0 */ });
scope.child(|| { /* title 1 */ }, || { /* content 1 */ });
},
);
Structs§
- TabDef
- Tabs
Args - Configuration arguments for the
tabs
component. - Tabs
Args Builder - Builder for
TabsArgs
. - Tabs
Scope - Tabs
State - Holds the mutable state used by the
tabs
component.
Enums§
- Tabs
Args Builder Error - Error type for TabsArgsBuilder
Functions§
- tabs
- Renders a tabs control with a row of titles and a paged content area.