use crate::values::*;
use std::fmt;
#[derive(Debug, Clone)]
pub struct Property {
name: String,
value: String,
}
impl Property {
pub fn new<T: fmt::Display>(name: &str, value: T) -> Self {
Self {
name: name.to_string(),
value: value.to_string(),
}
}
}
impl fmt::Display for Property {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {};", self.name, self.value)
}
}
pub mod color {
use super::*;
pub fn color(value: Color) -> Property {
Property::new("color", value)
}
pub fn background_color(value: Color) -> Property {
Property::new("background-color", value)
}
pub fn border_color(value: Color) -> Property {
Property::new("border-color", value)
}
}
pub mod size {
use super::*;
pub fn width(value: Size) -> Property {
Property::new("width", value)
}
pub fn height(value: Size) -> Property {
Property::new("height", value)
}
pub fn margin(value: Size) -> Property {
Property::new("margin", value)
}
pub fn margin_top(value: Size) -> Property {
Property::new("margin-top", value)
}
pub fn margin_right(value: Size) -> Property {
Property::new("margin-right", value)
}
pub fn margin_bottom(value: Size) -> Property {
Property::new("margin-bottom", value)
}
pub fn margin_left(value: Size) -> Property {
Property::new("margin-left", value)
}
pub fn padding(value: Size) -> Property {
Property::new("padding", value)
}
pub fn padding_top(value: Size) -> Property {
Property::new("padding-top", value)
}
pub fn padding_right(value: Size) -> Property {
Property::new("padding-right", value)
}
pub fn padding_bottom(value: Size) -> Property {
Property::new("padding-bottom", value)
}
pub fn padding_left(value: Size) -> Property {
Property::new("padding-left", value)
}
pub fn font_size(value: Size) -> Property {
Property::new("font-size", value)
}
pub fn line_height(value: Size) -> Property {
Property::new("line-height", value)
}
pub fn border_width(value: Size) -> Property {
Property::new("border-width", value)
}
}
pub mod display {
use super::*;
pub fn display(value: Display) -> Property {
Property::new("display", value)
}
pub fn position(value: Position) -> Property {
Property::new("position", value)
}
pub fn flex_direction(value: FlexDirection) -> Property {
Property::new("flex-direction", value)
}
pub fn justify_content(value: JustifyContent) -> Property {
Property::new("justify-content", value)
}
pub fn align_items(value: AlignItems) -> Property {
Property::new("align-items", value)
}
}
pub mod font {
use super::*;
pub fn font_weight(value: FontWeight) -> Property {
Property::new("font-weight", value)
}
pub fn font_family(value: &str) -> Property {
Property::new("font-family", value)
}
pub fn text_align(value: TextAlign) -> Property {
Property::new("text-align", value)
}
pub fn font_size_enum(value: FontSize) -> Property {
Property::new("font-size", value)
}
pub fn line_height_enum(value: LineHeight) -> Property {
Property::new("line-height", value)
}
pub fn text_decoration(value: TextDecoration) -> Property {
Property::new("text-decoration", value)
}
}
pub mod border {
use super::*;
pub fn border_style(value: BorderStyle) -> Property {
Property::new("border-style", value)
}
pub fn border_radius(value: Size) -> Property {
Property::new("border-radius", value)
}
pub fn border(width: Size, style: BorderStyle, color: Color) -> Property {
Property::new("border", format!("{} {} {}", width, style, color))
}
pub fn border_top(width: Size, style: BorderStyle, color: Color) -> Property {
Property::new("border-top", format!("{} {} {}", width, style, color))
}
pub fn border_right(width: Size, style: BorderStyle, color: Color) -> Property {
Property::new("border-right", format!("{} {} {}", width, style, color))
}
pub fn border_bottom(width: Size, style: BorderStyle, color: Color) -> Property {
Property::new("border-bottom", format!("{} {} {}", width, style, color))
}
pub fn border_left(width: Size, style: BorderStyle, color: Color) -> Property {
Property::new("border-left", format!("{} {} {}", width, style, color))
}
pub fn box_shadow(value: BoxShadow) -> Property {
Property::new("box-shadow", value)
}
pub fn box_shadow_none() -> Property {
Property::new("box-shadow", "none")
}
}
pub mod position {
use super::*;
pub fn top(value: Size) -> Property {
Property::new("top", value)
}
pub fn right(value: Size) -> Property {
Property::new("right", value)
}
pub fn bottom(value: Size) -> Property {
Property::new("bottom", value)
}
pub fn left(value: Size) -> Property {
Property::new("left", value)
}
pub fn z_index(value: ZIndex) -> Property {
Property::new("z-index", value)
}
}
pub mod layout {
use super::*;
pub fn overflow(value: Overflow) -> Property {
Property::new("overflow", value)
}
pub fn overflow_x(value: Overflow) -> Property {
Property::new("overflow-x", value)
}
pub fn overflow_y(value: Overflow) -> Property {
Property::new("overflow-y", value)
}
pub fn visibility(value: Visibility) -> Property {
Property::new("visibility", value)
}
pub fn opacity(value: f32) -> Property {
let clamped = value.max(0.0).min(1.0);
Property::new("opacity", clamped)
}
pub fn cursor(value: Cursor) -> Property {
Property::new("cursor", value)
}
}
pub mod flex {
use super::*;
pub fn gap(value: Size) -> Property {
Property::new("gap", value)
}
pub fn row_gap(value: Size) -> Property {
Property::new("row-gap", value)
}
pub fn column_gap(value: Size) -> Property {
Property::new("column-gap", value)
}
}
pub mod grid {
use super::*;
pub fn grid_template_columns(value: &str) -> Property {
Property::new("grid-template-columns", value)
}
pub fn grid_template_rows(value: &str) -> Property {
Property::new("grid-template-rows", value)
}
}
pub mod transition {
use super::*;
pub fn transition(value: Transition) -> Property {
Property::new("transition", value)
}
pub fn transition_none() -> Property {
Property::new("transition", "none")
}
pub fn transition_all(duration: f32, timing_function: Option<&str>, delay: Option<f32>) -> Property {
let mut value = format!("all {}s", duration);
if let Some(timing) = timing_function {
value.push_str(&format!(" {}", timing));
}
if let Some(delay_val) = delay {
value.push_str(&format!(" {}s", delay_val));
}
Property::new("transition", value)
}
}
pub mod size_ext {
use super::*;
pub fn max_width(value: Size) -> Property {
Property::new("max-width", value)
}
pub fn min_width(value: Size) -> Property {
Property::new("min-width", value)
}
pub fn max_height(value: Size) -> Property {
Property::new("max-height", value)
}
pub fn min_height(value: Size) -> Property {
Property::new("min-height", value)
}
}