1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
use flex_message::components::{ ComponentType, Component };
use actions::Action;

pub struct ComponentBuilder {
    align           : String,
    aspect_ratio    : String,
    aspect_mode     : String,
    background_color: String,
    color           : String,
    gravity         : String,
    height          : String,
    layout          : String,
    margin          : String,
    spacing         : String,
    style           : String,
    size            : String,
    text            : String,
    url             : String,
    wrap            : bool,
    weight          : String,
    flex            : u64,
    contents        : Vec<Component>,
    action          : Action,
}

impl ComponentBuilder {
    pub fn new() -> ComponentBuilder {
        ComponentBuilder {
            align           : String::new(),
            aspect_ratio    : String::new(),
            aspect_mode     : String::new(),
            background_color: String::new(),
            color           : String::new(),
            gravity         : String::new(),
            height          : String::new(),
            layout          : String::new(),
            margin          : String::new(),
            spacing         : String::new(),
            style           : String::new(),
            size            : String::new(),
            text            : String::new(),
            url             : String::new(),
            weight          : String::new(),
            wrap            : false,
            flex            : 0,
            contents        : vec![],
            action          : Action::create_empty(),
        }
    }

    pub fn build_box(&mut self) -> Component {
        Component::create_box(&self.layout.clone(), self.contents.clone(), self.flex.clone(), &self.spacing.clone(), &self.margin.clone())
    }

    pub fn build_button(&mut self) -> Component {
        Component::create_button(self.action.clone(), self.flex.clone(), &self.margin.clone(), &self.height.clone(), &self.style.clone(), &self.color.clone(), &self.gravity.clone())
    }

    pub fn build_filler(&mut self) -> Component { Component::create_filler() }

    pub fn build_icon(&mut self) ->Component {
        Component::create_icon(&self.url.clone(), &self.margin.clone(), &self.size.clone(), &self.aspect_ratio.clone())
    }

    pub fn build_image(&mut self) -> Component {
        Component::create_image(&self.url.clone(), self.flex.clone(), &self.margin.clone(), &self.align.clone(), &self.gravity.clone(), &self.size.clone(), &self.aspect_ratio.clone(), &self.aspect_mode.clone(), &self.background_color.clone(), self.action.clone())
    }

    pub fn build_separator(&mut self) -> Component {
        Component::create_separator(&self.margin.clone(), &self.color.clone())
    }

    pub fn build_spacer(&mut self) -> Component {
        Component::create_spacer(&self.size.clone())
    }

    pub fn build_text(&mut self) -> Component {
        Component::create_text(&self.text.clone(), self.flex.clone(), &self.margin.clone(), &self.size.clone(), &self.align.clone(), &self.gravity.clone(), self.wrap.clone(), &self.weight.clone(), &self.color.clone())
    }

    //set values
    pub fn set_align(&mut self, value: &str) -> &mut ComponentBuilder { self.align = String::from(value); self }
    pub fn set_aspect_ratio(&mut self, value: &str) -> &mut ComponentBuilder { self.aspect_ratio = String::from(value); self }
    pub fn set_aspect_mode(&mut self, value: &str) -> &mut ComponentBuilder { self.aspect_mode = String::from(value); self }
    pub fn set_background_color(&mut self, value: &str) -> &mut ComponentBuilder { self.background_color = String::from(value); self }
    pub fn set_color(&mut self, value: &str) -> &mut ComponentBuilder { self.color = String::from(value); self }
    pub fn set_gravity(&mut self, value: &str) -> &mut ComponentBuilder { self.gravity = String::from(value); self }
    pub fn set_height(&mut self, value: &str) -> &mut ComponentBuilder { self.height = String::from(value); self }
    pub fn set_layout(&mut self, value: &str) -> &mut ComponentBuilder { self.layout = String::from(value); self }
    pub fn set_margin(&mut self, value: &str) -> &mut ComponentBuilder { self.margin = String::from(value); self }
    pub fn set_spacing(&mut self, value: &str) -> &mut ComponentBuilder { self.spacing = String::from(value); self }
    pub fn set_style(&mut self, value: &str) -> &mut ComponentBuilder { self.style = String::from(value); self }
    pub fn set_size(&mut self, value: &str) -> &mut ComponentBuilder { self.size = String::from(value); self }
    pub fn set_text(&mut self, value: &str) -> &mut ComponentBuilder { self.text = String::from(value); self }
    pub fn set_url(&mut self, value: &str) -> &mut ComponentBuilder { self.url = String::from(value); self }
    pub fn set_weight(&mut self, value: &str) -> &mut ComponentBuilder { self.url = String::from(value); self }
    pub fn set_wrap(&mut self, value: bool) -> &mut ComponentBuilder { self.wrap = value; self }
    pub fn set_flex(&mut self, value: u64) -> &mut ComponentBuilder { self.flex = value; self }
    pub fn set_contents(&mut self, value: Vec<Component>) -> &mut ComponentBuilder { self.contents = value; self }
    pub fn set_action(&mut self, value: Action) -> &mut ComponentBuilder { self.action = value; self }

}