windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// Style - Type-safe CSS style builder

pub struct Style {
    properties: Vec<StyleProperty>,
}

pub struct StyleProperty {
    name: string,
    value: string,
}

impl Style {
    pub fn new() -> Style {
        Style {
            properties: Vec::new(),
        }
    }
    
    // Layout
    pub fn display(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "display".to_string(),
            value,
        })
        self
    }
    
    pub fn flex_direction(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "flex-direction".to_string(),
            value,
        })
        self
    }
    
    pub fn gap(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "gap".to_string(),
            value,
        })
        self
    }
    
    pub fn align_items(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "align-items".to_string(),
            value,
        })
        self
    }
    
    pub fn justify_content(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "justify-content".to_string(),
            value,
        })
        self
    }
    
    // Spacing
    pub fn margin(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "margin".to_string(),
            value,
        })
        self
    }
    
    pub fn padding(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "padding".to_string(),
            value,
        })
        self
    }
    
    // Sizing
    pub fn width(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "width".to_string(),
            value,
        })
        self
    }
    
    pub fn height(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "height".to_string(),
            value,
        })
        self
    }
    
    pub fn min_width(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "min-width".to_string(),
            value,
        })
        self
    }
    
    pub fn max_width(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "max-width".to_string(),
            value,
        })
        self
    }
    
    // Colors
    pub fn color(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "color".to_string(),
            value,
        })
        self
    }
    
    pub fn background_color(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "background-color".to_string(),
            value,
        })
        self
    }
    
    pub fn border_color(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "border-color".to_string(),
            value,
        })
        self
    }
    
    // Border
    pub fn border(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "border".to_string(),
            value,
        })
        self
    }
    
    pub fn border_radius(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "border-radius".to_string(),
            value,
        })
        self
    }
    
    // Typography
    pub fn font_size(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "font-size".to_string(),
            value,
        })
        self
    }
    
    pub fn font_weight(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "font-weight".to_string(),
            value,
        })
        self
    }
    
    pub fn text_align(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "text-align".to_string(),
            value,
        })
        self
    }
    
    // Position
    pub fn position(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "position".to_string(),
            value,
        })
        self
    }
    
    pub fn top(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "top".to_string(),
            value,
        })
        self
    }
    
    pub fn right(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "right".to_string(),
            value,
        })
        self
    }
    
    pub fn bottom(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "bottom".to_string(),
            value,
        })
        self
    }
    
    pub fn left(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "left".to_string(),
            value,
        })
        self
    }
    
    // Effects
    pub fn opacity(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "opacity".to_string(),
            value,
        })
        self
    }
    
    pub fn box_shadow(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "box-shadow".to_string(),
            value,
        })
        self
    }
    
    pub fn cursor(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "cursor".to_string(),
            value,
        })
        self
    }
    
    // Overflow
    pub fn overflow(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "overflow".to_string(),
            value,
        })
        self
    }
    
    pub fn overflow_x(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "overflow-x".to_string(),
            value,
        })
        self
    }
    
    pub fn overflow_y(value: string) -> Style {
        self.properties.push(StyleProperty {
            name: "overflow-y".to_string(),
            value,
        })
        self
    }
    
    pub fn to_string() -> string {
        let mut result = String::new()
        
        for (i, prop) in self.properties.iter().enumerate() {
            if i > 0 {
                result.push_str("; ")
            }
            result.push_str(prop.name.as_str())
            result.push_str(": ")
            result.push_str(prop.value.as_str())
        }
        
        result
    }
}