|
| 1 | +use pgml_components::component; |
| 2 | +use sailfish::TemplateOnce; |
| 3 | + |
| 4 | +#[derive(TemplateOnce, Default)] |
| 5 | +#[template(path = "inputs/range_group/template.html")] |
| 6 | +pub struct RangeGroup { |
| 7 | + pub title: String, |
| 8 | + pub identifier: String, |
| 9 | + pub min: i64, |
| 10 | + pub max: i64, |
| 11 | + pub step: f32, |
| 12 | + pub initial_value: f64, |
| 13 | + pub text_target: Option<String>, |
| 14 | + pub range_target: Option<String>, |
| 15 | + pub cost_rate: Option<f32>, |
| 16 | + pub units: String, |
| 17 | +} |
| 18 | + |
| 19 | +impl RangeGroup { |
| 20 | + pub fn new(title: &str) -> RangeGroup { |
| 21 | + RangeGroup { |
| 22 | + title: title.to_owned(), |
| 23 | + identifier: title.replace(" ", "_"), |
| 24 | + min: 0, |
| 25 | + max: 100, |
| 26 | + step: 1.0, |
| 27 | + initial_value: 1.0, |
| 28 | + text_target: None, |
| 29 | + range_target: None, |
| 30 | + cost_rate: None, |
| 31 | + units: String::default(), |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + pub fn identifier(mut self, identifier: &str) -> Self { |
| 36 | + self.identifier = identifier.replace(" ", "_").to_owned(); |
| 37 | + self |
| 38 | + } |
| 39 | + |
| 40 | + pub fn bounds(mut self, min: i64, max: i64, step: f32) -> Self { |
| 41 | + self.min = min; |
| 42 | + self.max = max; |
| 43 | + self.step = step; |
| 44 | + self |
| 45 | + } |
| 46 | + |
| 47 | + pub fn initial_value(mut self, value: f64) -> Self { |
| 48 | + self.initial_value = value; |
| 49 | + self |
| 50 | + } |
| 51 | + |
| 52 | + pub fn text_target(mut self, target: &str) -> Self { |
| 53 | + self.text_target = Some(target.to_owned()); |
| 54 | + self |
| 55 | + } |
| 56 | + |
| 57 | + pub fn range_target(mut self, target: &str) -> Self { |
| 58 | + self.range_target = Some(target.to_owned()); |
| 59 | + self |
| 60 | + } |
| 61 | + |
| 62 | + pub fn cost_rate(mut self, cost_rate: f32) -> Self { |
| 63 | + self.cost_rate = Some(cost_rate); |
| 64 | + self |
| 65 | + } |
| 66 | + |
| 67 | + pub fn units(mut self, units: &str) -> Self { |
| 68 | + self.units = units.to_owned(); |
| 69 | + self |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +component!(RangeGroup); |
0 commit comments