windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// List and ListItem - Display lists of items

pub struct List {
    items: Vec<string>,
    ordered: bool,
    class: string,
}

impl List {
    pub fn new() -> List {
        List {
            items: Vec::new(),
            ordered: false,
            class: String::new(),
        }
    }
    
    pub fn item(item: string) -> List {
        self.items.push(item)
        self
    }
    
    pub fn ordered(ordered: bool) -> List {
        self.ordered = ordered
        self
    }
    
    pub fn class(class: string) -> List {
        self.class = class
        self
    }
    
    pub fn render() -> string {
        let tag = if self.ordered { "ol" } else { "ul" }
        
        let mut html = String::new()
        html.push('<')
        html.push_str(tag)
        html.push_str(" class=\"wj-list ")
        html.push_str(self.class.as_str())
        html.push_str("\" style=\"list-style-position: inside; padding-left: 0;\">")
        
        for item in self.items {
            html.push_str("<li style=\"padding: 8px 0;\">")
            html.push_str(item.as_str())
            html.push_str("</li>")
        }
        
        html.push_str("</")
        html.push_str(tag)
        html.push('>')
        html
    }
}

pub struct ListItem {
    content: string,
    class: string,
}

impl ListItem {
    pub fn new(content: string) -> ListItem {
        ListItem {
            content,
            class: String::new(),
        }
    }
    
    pub fn class(class: string) -> ListItem {
        self.class = class
        self
    }
    
    pub fn render() -> string {
        let mut html = String::new()
        html.push_str("<li class=\"wj-list-item ")
        html.push_str(self.class.as_str())
        html.push_str("\" style=\"padding: 8px 0;\">")
        html.push_str(self.content.as_str())
        html.push_str("</li>")
        html
    }
}