use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type", content = "value")]
pub enum Dimension {
Px(f64),
Auto,
Fill,
Percent(f64),
}
impl Dimension {
pub fn from_number(n: f64) -> Self {
Dimension::Px(n)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Edges {
Uniform(f64),
Sides {
top: f64,
bottom: f64,
start: f64,
end: f64,
},
}
impl Edges {
pub fn from_number(n: f64) -> Self {
Edges::Uniform(n)
}
pub fn sides(top: f64, bottom: f64, start: f64, end: f64) -> Self {
Edges::Sides {
top,
bottom,
start,
end,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum Alignment {
Start,
Center,
End,
Stretch,
SpaceBetween,
SpaceAround,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BorderStyle {
pub width: f64,
pub color: ColorValue,
#[serde(skip_serializing_if = "Option::is_none")]
pub style: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ShadowStyle {
pub offset_x: f64,
pub offset_y: f64,
pub blur: f64,
pub color: ColorValue,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ColorValue {
pub r: f64,
pub g: f64,
pub b: f64,
pub a: f64,
}
impl ColorValue {
pub fn new(r: f64, g: f64, b: f64, a: f64) -> Self {
Self { r, g, b, a }
}
pub fn rgb(r: f64, g: f64, b: f64) -> Self {
Self { r, g, b, a: 1.0 }
}
}