Skip to main content

ass_editor/core/builders/
style_setters.rs

1//! Fluent setter methods for [`StyleBuilder`].
2
3use super::StyleBuilder;
4
5#[cfg(not(feature = "std"))]
6use alloc::string::ToString;
7
8impl StyleBuilder {
9    /// Set style name
10    pub fn name(mut self, name: &str) -> Self {
11        self.name = Some(name.to_string());
12        self
13    }
14
15    /// Set font name
16    pub fn font(mut self, font: &str) -> Self {
17        self.fontname = Some(font.to_string());
18        self
19    }
20
21    /// Set font size
22    pub fn size(mut self, size: u32) -> Self {
23        self.fontsize = Some(size);
24        self
25    }
26
27    /// Set primary text color (in ASS color format)
28    pub fn color(mut self, color: &str) -> Self {
29        self.primary_colour = Some(color.to_string());
30        self
31    }
32
33    /// Set bold formatting
34    pub fn bold(mut self, bold: bool) -> Self {
35        self.bold = Some(bold);
36        self
37    }
38
39    /// Set italic formatting
40    pub fn italic(mut self, italic: bool) -> Self {
41        self.italic = Some(italic);
42        self
43    }
44
45    /// Set alignment (1-9, numpad style)
46    pub fn align(mut self, alignment: u32) -> Self {
47        self.alignment = Some(alignment);
48        self
49    }
50
51    /// Set secondary color (for collision effects)
52    pub fn secondary_color(mut self, color: &str) -> Self {
53        self.secondary_colour = Some(color.to_string());
54        self
55    }
56
57    /// Set outline color
58    pub fn outline_color(mut self, color: &str) -> Self {
59        self.outline_colour = Some(color.to_string());
60        self
61    }
62
63    /// Set shadow/background color
64    pub fn back_color(mut self, color: &str) -> Self {
65        self.back_colour = Some(color.to_string());
66        self
67    }
68
69    /// Set underline formatting
70    pub fn underline(mut self, underline: bool) -> Self {
71        self.underline = Some(underline);
72        self
73    }
74
75    /// Set strikeout formatting
76    pub fn strikeout(mut self, strikeout: bool) -> Self {
77        self.strikeout = Some(strikeout);
78        self
79    }
80
81    /// Set horizontal scale percentage
82    pub fn scale_x(mut self, scale: f32) -> Self {
83        self.scale_x = Some(scale);
84        self
85    }
86
87    /// Set vertical scale percentage
88    pub fn scale_y(mut self, scale: f32) -> Self {
89        self.scale_y = Some(scale);
90        self
91    }
92
93    /// Set character spacing in pixels
94    pub fn spacing(mut self, spacing: f32) -> Self {
95        self.spacing = Some(spacing);
96        self
97    }
98
99    /// Set rotation angle in degrees
100    pub fn angle(mut self, angle: f32) -> Self {
101        self.angle = Some(angle);
102        self
103    }
104
105    /// Set border style (1=outline+shadow, 3=opaque box)
106    pub fn border_style(mut self, style: u32) -> Self {
107        self.border_style = Some(style);
108        self
109    }
110
111    /// Set outline width in pixels
112    pub fn outline(mut self, width: f32) -> Self {
113        self.outline = Some(width);
114        self
115    }
116
117    /// Set shadow depth in pixels
118    pub fn shadow(mut self, depth: f32) -> Self {
119        self.shadow = Some(depth);
120        self
121    }
122
123    /// Set left margin in pixels
124    pub fn margin_left(mut self, margin: u32) -> Self {
125        self.margin_l = Some(margin);
126        self
127    }
128
129    /// Set right margin in pixels
130    pub fn margin_right(mut self, margin: u32) -> Self {
131        self.margin_r = Some(margin);
132        self
133    }
134
135    /// Set vertical margin in pixels
136    pub fn margin_vertical(mut self, margin: u32) -> Self {
137        self.margin_v = Some(margin);
138        self
139    }
140
141    /// Set top margin in pixels (V4++)
142    pub fn margin_top(mut self, margin: u32) -> Self {
143        self.margin_t = Some(margin);
144        self
145    }
146
147    /// Set bottom margin in pixels (V4++)
148    pub fn margin_bottom(mut self, margin: u32) -> Self {
149        self.margin_b = Some(margin);
150        self
151    }
152
153    /// Set font encoding identifier
154    pub fn encoding(mut self, encoding: u32) -> Self {
155        self.encoding = Some(encoding);
156        self
157    }
158
159    /// Set alpha level (SSA v4) - transparency from 0-255 (0=opaque, 255=transparent)
160    pub fn alpha_level(mut self, alpha: u32) -> Self {
161        self.alpha_level = Some(alpha);
162        self
163    }
164
165    /// Set positioning context (V4++)
166    pub fn relative_to(mut self, relative: &str) -> Self {
167        self.relative_to = Some(relative.to_string());
168        self
169    }
170}