Expand description
A widget providing a conjoined set of linear items that function in conjunction as a single button.
§Example
Add the model and a message variant in your application for handling selections.
ⓘ
use iced_core::Length;
use cosmic::theme;
use cosmic::widget::segmented_button;
enum AppMessage {
    Selected(segmented_button::Key)
}
struct App {
    model: segmented_button::SingleSelectModel,
}Then add choices to the model, while activating the first.
ⓘ
application.model = segmented_button::Model::builder()
    .insert(|b| b.text("Choice A").data(0u16))
    .insert(|b| b.text("Choice B").data(1u16))
    .insert(|b| b.text("Choice C").data(2u16))
    .build();Or incrementally insert items with
ⓘ
let id = application.model.insert()
    .text("Choice C")
    .icon("custom-icon")
    .data(3u16)
    .data("custom-meta")
    .id();Then use it in the view method to create segmented button widgets.
ⓘ
let widget = segmented_button::horizontal(&application.model)
    .style(theme::SegmentedButton::ViewSeitcher)
    .button_height(32)
    .button_padding([16, 10, 16, 10])
    .button_spacing(8)
    .icon_size(16)
    .spacing(8)
    .on_activate(AppMessage::Selected);And respond to events like so:
ⓘ
match message {
    AppMessage::Selected(id) => {
        application.model.activate(id);
        if let Some(number) = application.model.data::<u16>(id) {
            println!("activated item with number {number}");
        }
        if let Some(text) = application.text(id) {
            println!("activated button with text {text}");
        }
    }
}Structs§
- Appearance
 - Appearance of the segmented button.
 - Builder
Entity  - Constructs a new item for the 
ModelBuilder. - Entity
 - A unique ID for an item in the 
Model. - Entity
Mut  - A newly-inserted item which may have additional actions applied to it.
 - Id
 - The iced identifier of a segmented button.
 - Item
Appearance  - Appearance of an item in the segmented button.
 - Item
Status Appearance  - Appearance of an item based on its status.
 - Model
 - The model held by the application, containing the unique IDs and data of each inserted item.
 - Model
Builder  - A builder for a 
Model. - Multi
Select  Model<MultiSelect>permits multiple keys to be active at a time.- Segmented
Button  - A conjoined group of items that function together as a button.
 - Single
Select  Model<SingleSelect>Ensures that only one key may be selected.
Traits§
- Segmented
Variant  - Isolates variant-specific behaviors from 
SegmentedButton. - Selectable
 - Describes a type that has selectable items.
 - Style
Sheet  - Defines the 
Appearanceof a segmented button. 
Functions§
- focus
 - A command that focuses a segmented item stored in a widget.
 - horizontal
 - Horizontal implementation of the 
SegmentedButton. - vertical
 - Vertical implementation of the 
SegmentedButton. 
Type Aliases§
- Horizontal
Segmented Button  - Horizontal 
SegmentedButton. - Multi
Select Entity Mut  - Multi-select variant of an 
EntityMut. - Multi
Select Model  - A model for multi-select button selection.
 - Secondary
Map  - Associates extra data with an external secondary map.
 - Single
Select Entity Mut  - Single-select variant of an 
EntityMut. - Single
Select Model  - A model for single-select button selection.
 - Sparse
Secondary Map  - Associates extra data with an external sparse secondary map.
 - Vertical
Segmented Button  - Vertical 
SegmentedButton.