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

@ -0,0 +1,57 @@
// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
//! Defines the model that's used by each button in the widget.
use crate::widget::IconSource;
use derive_setters::Setters;
use std::borrow::Cow;
/// Describes a button in a segmented button
#[must_use]
pub fn item() -> SegmentedItem {
SegmentedItem::default()
}
/// Information about a specific button in a segmented button
#[derive(Setters)]
pub struct SegmentedItem {
#[setters(into, strip_option)]
/// The label to display in this button.
pub text: Option<Cow<'static, str>>,
#[setters(into, strip_option)]
/// An optionally-displayed icon beside the label.
pub icon: Option<IconSource<'static>>,
/// Whether the button is clickable or not.
pub enabled: bool,
}
impl Default for SegmentedItem {
fn default() -> Self {
Self {
text: None,
icon: None,
enabled: true,
}
}
}
impl From<String> for SegmentedItem {
fn from(text: String) -> Self {
Self::from(Cow::Owned(text))
}
}
impl From<&'static str> for SegmentedItem {
fn from(text: &'static str) -> Self {
Self::from(Cow::Borrowed(text))
}
}
impl From<Cow<'static, str>> for SegmentedItem {
fn from(text: Cow<'static, str>) -> Self {
SegmentedItem::default().text(text)
}
}