Skip to main content

single_choice_segmented_button_row

Function single_choice_segmented_button_row 

Source
pub fn single_choice_segmented_button_row() -> SingleChoiceSegmentedButtonRowBuilder
Expand description

§single_choice_segmented_button_row

Lay out segmented buttons for single-selection groups.

§Usage

Use when only one option should be active at a time.

§Parameters

  • modifier — modifiers applied to the row container.
  • overlap — overlap amount between adjacent segments.
  • cross_axis_alignment — cross-axis alignment for segments.
  • equal_width — whether segments should share equal width.
  • content — row content slot.

§Examples

use tessera_components::segmented_buttons::{
    SegmentedButtonDefaults, segmented_button, single_choice_segmented_button_row,
};
use tessera_components::theme::{MaterialTheme, material_theme};
use tessera_ui::{remember, tessera};

#[tessera]
fn demo() {
    material_theme()
        .theme(|| MaterialTheme::default())
        .child(|| {
            let selected = remember(|| 0usize);
            single_choice_segmented_button_row().content(move |mode| {
                segmented_button().selection_mode(mode)
                    .label("Day")
                    .selected(selected.get() == 0)
                    .shape(SegmentedButtonDefaults::item_shape(
                        0,
                        2,
                        SegmentedButtonDefaults::shape(),
                    ))
                    .on_click(|| {});
                segmented_button().selection_mode(mode)
                    .label("Week")
                    .selected(selected.get() == 1)
                    .shape(SegmentedButtonDefaults::item_shape(
                        1,
                        2,
                        SegmentedButtonDefaults::shape(),
                    ))
                    .on_click(|| {});
            });
        });
}