use std::hash::Hash;
use super::super::SemanticStatus;
use crate::{components::theme::RadioStyle, Id};
pub struct RadioOption<T> {
pub(super) value: T,
pub(super) label: String,
pub(super) description: String,
pub(super) enabled: bool,
pub(super) tooltip: Option<String>,
}
impl<T> RadioOption<T> {
pub fn new(value: T, label: impl Into<String>) -> Self {
Self {
value,
label: label.into(),
description: String::new(),
enabled: true,
tooltip: None,
}
}
pub fn description(mut self, text: impl Into<String>) -> Self {
self.description = text.into();
self
}
pub fn enabled(mut self, enabled: bool) -> Self {
self.enabled = enabled;
self
}
pub fn tooltip(mut self, text: impl Into<String>) -> Self {
self.tooltip = Some(text.into());
self
}
pub(super) fn key(&self) -> Id
where
T: Hash,
{
Id::new(&self.value)
}
}
impl<T, L: Into<String>> From<(T, L)> for RadioOption<T> {
fn from((value, label): (T, L)) -> Self {
Self::new(value, label)
}
}
impl<T, L: Into<String>, D: Into<String>> From<(T, L, D)> for RadioOption<T> {
fn from((value, label, description): (T, L, D)) -> Self {
Self::new(value, label).description(description)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum RadioLayout {
#[default]
Vertical,
Horizontal,
Grid(usize),
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum RadioSize {
Small,
#[default]
Medium,
Large,
}
impl RadioSize {
pub(super) fn factor(self) -> f32 {
match self {
Self::Small => 0.8,
Self::Medium => 1.0,
Self::Large => 1.25,
}
}
}
pub(super) struct Config {
pub id: Option<Id>,
pub enabled: bool,
pub status: SemanticStatus,
pub layout: RadioLayout,
pub size: RadioSize,
pub follow_focus: bool,
pub row_gap: Option<f32>,
pub column_gap: Option<f32>,
pub label_gap: Option<f32>,
pub min_row_height: Option<f32>,
pub style: RadioStyle,
}
impl Default for Config {
fn default() -> Self {
Self {
id: None,
enabled: true,
status: SemanticStatus::Normal,
layout: RadioLayout::Vertical,
size: RadioSize::Medium,
follow_focus: true,
row_gap: None,
column_gap: None,
label_gap: None,
min_row_height: None,
style: RadioStyle::default(),
}
}
}