windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
// Text component - Pure Windjammer implementation
// NO `mut` keyword needed - compiler infers everything!

use super::traits::Renderable

pub enum TextSize {
    Small,
    Medium,
    Large,
    XLarge,
}

pub enum TextWeight {
    Normal,
    Bold,
}

pub struct Text {
    content: string,
    size: TextSize,
    weight: TextWeight,
    color: string,
}

impl Text {
    // Constructor - returns new Text
    pub fn new(content: string) -> Text {
        Text {
            content: content,
            size: TextSize::Medium,
            weight: TextWeight::Normal,
            color: "".to_string(),
        }
    }
    
    // Builder pattern: consumes self, modifies, returns self
    // Compiler infers: mut self (owned, mutable)
    pub fn size(self, size: TextSize) -> Text {
        self.size = size
        self
    }
    
    // Builder pattern: consumes self, modifies, returns self  
    // Compiler infers: mut self (owned, mutable)
    pub fn bold(self) -> Text {
        self.weight = TextWeight::Bold
        self
    }
    
    // Set text color
    pub fn color(self, color: string) -> Text {
        self.color = color
        self
    }
    
}

// Implement Renderable trait for Text
impl Renderable for Text {
    // TODO: Once external type bindings work, this will return VNode
    // For now, return a string representation for testing
    fn render(self) -> string {
        let size_class = match self.size {
            TextSize::Small => "sm",
            TextSize::Medium => "md",
            TextSize::Large => "lg",
            TextSize::XLarge => "xl",
        }
        
        let weight_class = match self.weight {
            TextWeight::Normal => "normal",
            TextWeight::Bold => "bold",
        }
        
        let style = if self.color != "" {
            format!(" style='color: {};'", self.color)
        } else {
            "".to_string()
        }
        
        format!("<span class='wj-text {} {}'{}>{}</span>", size_class, weight_class, style, self.content)
    }
}

// Test the Text component
fn main() {
    let text = Text::new("Hello, Windjammer!")
        .size(TextSize::Large)
        .bold()
    
    let html = text.render()
    println!("{}", html)
}