2022-12-28 23:18:31 +01:00
|
|
|
// Copyright 2022 System76 <info@system76.com>
|
2022-12-28 12:42:28 +01:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2022-12-28 23:18:31 +01:00
|
|
|
|
|
|
|
|
//! A widget providing a conjoined set of linear buttons for choosing between.
|
|
|
|
|
//!
|
|
|
|
|
//! ## Example
|
|
|
|
|
//!
|
|
|
|
|
//! Add the state and a message variant in your application for handling selections.
|
|
|
|
|
//!
|
2023-01-04 01:26:33 +01:00
|
|
|
//! ```ignore
|
2022-12-28 23:18:31 +01:00
|
|
|
//! use iced_core::Length;
|
|
|
|
|
//! use cosmic::theme;
|
|
|
|
|
//! use cosmic::widget::segmented_button;
|
|
|
|
|
//!
|
|
|
|
|
//! enum AppMessage {
|
|
|
|
|
//! Selected(segmented_button::Key)
|
|
|
|
|
//! }
|
|
|
|
|
//!
|
|
|
|
|
//! struct App {
|
|
|
|
|
//! ...
|
|
|
|
|
//! state: segmented_button::State<u16>(),
|
|
|
|
|
//! ...
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Then add choices to the state, while activating the first.
|
|
|
|
|
//!
|
2023-01-04 01:26:33 +01:00
|
|
|
//! ```ignore
|
2022-12-28 23:18:31 +01:00
|
|
|
//! 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);
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Then use it in the view method to create segmented button widgets.
|
|
|
|
|
//!
|
2023-01-04 01:26:33 +01:00
|
|
|
//! ```ignore
|
2022-12-28 23:18:31 +01:00
|
|
|
//! let widget = segmentend_button(&application.state)
|
|
|
|
|
//! .style(theme::SegmentedButton::Selection)
|
|
|
|
|
//! .height(Length::Units(32))
|
|
|
|
|
//! .on_activate(AppMessage::Selected);
|
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
|
|
/// COSMIC configurations of [`SegmentedButton`].
|
|
|
|
|
pub mod cosmic;
|
|
|
|
|
|
2023-01-03 19:35:34 +01:00
|
|
|
mod horizontal;
|
2022-12-28 12:42:28 +01:00
|
|
|
mod state;
|
|
|
|
|
mod style;
|
2023-01-03 19:35:34 +01:00
|
|
|
mod vertical;
|
2022-12-28 12:42:28 +01:00
|
|
|
|
2023-01-03 19:35:34 +01:00
|
|
|
pub use self::horizontal::{horizontal_segmented_button, HorizontalSegmentedButton};
|
|
|
|
|
pub use self::state::{ButtonContent, Key, SecondaryState, SharedWidgetState, State};
|
2022-12-28 12:42:28 +01:00
|
|
|
pub use self::style::{Appearance, ButtonAppearance, StyleSheet};
|
2023-01-03 19:35:34 +01:00
|
|
|
pub use self::vertical::{vertical_segmented_button, VerticalSegmentedButton};
|
2022-12-28 12:42:28 +01:00
|
|
|
|
2023-01-03 19:35:34 +01:00
|
|
|
/// State that is maintained by each individual widget.
|
2022-12-28 19:27:05 +01:00
|
|
|
#[derive(Default)]
|
2023-01-03 19:35:34 +01:00
|
|
|
struct UniqueWidgetState {
|
2022-12-28 19:27:05 +01:00
|
|
|
/// The ID of the button that is being hovered. Defaults to null.
|
|
|
|
|
hovered: Key,
|
|
|
|
|
}
|