rustyle_css/dynamic/
builder.rs1use crate::css::{Color, Radius, Spacing};
6
7pub struct DynamicStyleBuilder {
9 styles: Vec<String>,
10}
11
12impl DynamicStyleBuilder {
13 pub fn new() -> Self {
15 Self { styles: Vec::new() }
16 }
17
18 pub fn background_color(mut self, color: Color) -> Self {
20 self.styles
21 .push(format!("background-color: {};", color.to_css()));
22 self
23 }
24
25 pub fn color(mut self, color: Color) -> Self {
27 self.styles.push(format!("color: {};", color.to_css()));
28 self
29 }
30
31 pub fn padding(mut self, padding: Spacing) -> Self {
33 self.styles.push(format!("padding: {};", padding.to_css()));
34 self
35 }
36
37 pub fn margin(mut self, margin: Spacing) -> Self {
39 self.styles.push(format!("margin: {};", margin.to_css()));
40 self
41 }
42
43 pub fn border_radius(mut self, radius: Radius) -> Self {
45 self.styles
46 .push(format!("border-radius: {};", radius.to_css()));
47 self
48 }
49
50 pub fn property(mut self, property: &str, value: &str) -> Self {
52 self.styles.push(format!("{}: {};", property, value));
53 self
54 }
55
56 pub fn build(self) -> String {
58 self.styles.join(" ")
59 }
60}
61
62impl Default for DynamicStyleBuilder {
63 fn default() -> Self {
64 Self::new()
65 }
66}