use crate::{Border, Color, CornerRadius, FontWeight, Padding, ScrollStyle};
use std::time::Duration;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ListDensity {
Compact,
#[default]
Normal,
Comfortable,
}
impl ListDensity {
pub(super) fn factor(self) -> f32 {
match self {
Self::Compact => 0.8,
Self::Normal => 1.0,
Self::Comfortable => 1.3,
}
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ListBoxStyle {
pub row_height: Option<f32>,
pub header_height: Option<f32>,
pub separator_height: Option<f32>,
pub row_margin: Option<f32>,
pub row_padding: Option<Padding>,
pub row_rounding: Option<CornerRadius>,
pub surface: Option<Color>,
pub border: Option<Border>,
pub idle: Option<Color>,
pub hover: Option<Color>,
pub selected: Option<Color>,
pub selected_inactive: Option<Color>,
pub active_ring: Option<Border>,
pub stripe: Option<Color>,
pub divider: Option<Border>,
pub text: Option<Color>,
pub selected_text: Option<Color>,
pub muted_text: Option<Color>,
pub disabled_text: Option<Color>,
pub header_fill: Option<Color>,
pub header_text: Option<Color>,
pub header_font_size: Option<f32>,
pub font_size: Option<f32>,
pub font_weight: Option<FontWeight>,
pub check_size: Option<f32>,
pub scroll: Option<ScrollStyle>,
pub type_ahead_timeout: Option<Duration>,
}
macro_rules! builders {
($($name:ident: $ty:ty),* $(,)?) => {
impl ListBoxStyle { $(
pub fn $name(mut self, value: $ty) -> Self { self.$name = Some(value); self }
)* }
};
}
builders!(
row_height: f32, header_height: f32, separator_height: f32, row_margin: f32,
row_padding: Padding, row_rounding: CornerRadius, surface: Color, border: Border,
idle: Color, hover: Color, selected: Color, selected_inactive: Color,
active_ring: Border, stripe: Color, divider: Border, text: Color, selected_text: Color,
muted_text: Color, disabled_text: Color, header_fill: Color, header_text: Color,
header_font_size: f32, font_size: f32, font_weight: FontWeight, check_size: f32,
scroll: ScrollStyle, type_ahead_timeout: Duration,
);
impl ListBoxStyle {
pub(crate) fn merge(&mut self, rhs: &Self) {
macro_rules! set { ($($f:ident),*) => { $(if rhs.$f.is_some() { self.$f = rhs.$f; })* }; }
set!(
row_height,
header_height,
separator_height,
row_margin,
row_padding,
row_rounding,
surface,
border,
idle,
hover,
selected,
selected_inactive,
active_ring,
stripe,
divider,
text,
selected_text,
muted_text,
disabled_text,
header_fill,
header_text,
header_font_size,
font_size,
font_weight,
check_size,
scroll,
type_ahead_timeout
);
}
}