windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// Spacer Component - Flexible spacing between elements


use super::traits::Renderable
pub struct Spacer {
    width: string,
    height: string,
    flex: bool,
}

impl Spacer {
    pub fn new() -> Spacer {
        Spacer {
            width: "".to_string(),
            height: "".to_string(),
            flex: false,
        }
    }

    pub fn horizontal(width: string) -> Spacer {
        Spacer {
            width: width,
            height: "".to_string(),
            flex: false,
        }
    }

    pub fn vertical(height: string) -> Spacer {
        Spacer {
            width: "".to_string(),
            height: height,
            flex: false,
        }
    }

    pub fn flexible() -> Spacer {
        Spacer {
            width: "".to_string(),
            height: "".to_string(),
            flex: true,
        }
    }

    pub fn width(self, width: string) -> Spacer {
        self.width = width
        self
    }

    pub fn height(self, height: string) -> Spacer {
        self.height = height
        self
    }



    // Grid system helpers (8px multiples)
    pub fn xxs() -> Spacer {
        Spacer::vertical("4px".to_string())
    }

    pub fn xs() -> Spacer {
        Spacer::vertical("8px".to_string())
    }

    pub fn sm() -> Spacer {
        Spacer::vertical("12px".to_string())
    }

    pub fn md() -> Spacer {
        Spacer::vertical("16px".to_string())
    }

    pub fn lg() -> Spacer {
        Spacer::vertical("24px".to_string())
    }

    pub fn xl() -> Spacer {
        Spacer::vertical("32px".to_string())
    }

    pub fn xxl() -> Spacer {
        Spacer::vertical("48px".to_string())
    }
}

impl Renderable for Spacer {
pub fn render(self) -> string {
        let mut style = "".to_string()

        if self.flex {
            style = "flex: 1; ".to_string()
        }

        if self.width != "" {
            style = format!("{}width: {}; ", style, self.width)
        }

        if self.height != "" {
            style = format!("{}height: {}; ", style, self.height)
        }

        format!("<div class='wj-spacer' style='{}'></div>", style)
    }
}

fn main() {
    let spacer1 = Spacer::horizontal("20px".to_string())
    println!("Horizontal: {}", spacer1.render())

    let spacer2 = Spacer::vertical("30px".to_string())
    println!("Vertical: {}", spacer2.render())

    let spacer3 = Spacer::flexible()
    println!("Flexible: {}", spacer3.render())

    let spacer4 = Spacer::md()
    println!("Medium (16px): {}", spacer4.render())
}