feat: focusable segmented items in segmented button

This commit is contained in:
Michael Aaron Murphy 2023-01-09 16:18:02 +01:00 committed by Michael Murphy
parent a89ec01297
commit 29c7444a30
14 changed files with 794 additions and 611 deletions

View file

@ -1,7 +1,7 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
//! A widget providing a conjoined set of linear buttons for choosing between.
//! A widget providing a conjoined set of linear buttons that function in conjunction with each other.
//!
//! ## Example
//!
@ -17,27 +17,30 @@
//! }
//!
//! struct App {
//! ...
//! state: segmented_button::State<u16>(),
//! ...
//! state: segmented_button::SingleSelectModel<u16>(),
//! }
//! ```
//!
//! Then add choices to the state, while activating the first.
//!
//! ```ignore
//! let first_key = application.state.insert("Choice A", 0);
//! application.state.insert("Choice B", 1);
//! application.state.insert("Choice C", 2);
//! application.state.activate(first_key);
//! application.model = SingleSelectModel::builder()
//! .insert_activate("Choice A", 0)
//! .insert("Choice B", 1)
//! .insert("Choice C", 2)
//! .build();
//! ```
//!
//! Then use it in the view method to create segmented button widgets.
//!
//! ```ignore
//! let widget = horizontal_segmentend_button(&application.state)
//! .style(theme::SegmentedButton::Selection)
//! .height(Length::Units(32))
//! let widget = horizontal_segmented_button(&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);
//! ```
@ -45,16 +48,17 @@
pub mod cosmic;
mod horizontal;
mod state;
mod item;
mod model;
mod selection_modes;
mod style;
mod vertical;
mod widget;
pub use self::horizontal::{horizontal_segmented_button, Horizontal, HorizontalSegmentedButton};
pub use self::state::{
Content, Key, MultiSelect, SecondaryState, Selectable, SharedWidgetState, SingleSelect, State,
};
pub use self::horizontal::{horizontal_segmented_button, HorizontalSegmentedButton};
pub use self::item::{item, SegmentedItem};
pub use self::model::{Batch, Key, Model, ModelBuilder, MultiSelectModel, SingleSelectModel};
pub use self::selection_modes::Selectable;
pub use self::style::{Appearance, ButtonAppearance, ButtonStatusAppearance, StyleSheet};
pub use self::vertical::{vertical_segmented_button, Vertical, VerticalSegmentedButton};
pub use self::widget::{SegmentedButton, SegmentedVariant};
pub use self::vertical::{vertical_segmented_button, VerticalSegmentedButton};
pub use self::widget::{focus, Id, SegmentedButton, SegmentedVariant};