ass_editor/core/builders/
event.rs1use ass_core::parser::ast::EventType;
4
5#[cfg(feature = "std")]
6use std::borrow::Cow;
7
8#[cfg(not(feature = "std"))]
9use alloc::{borrow::Cow, string::ToString};
10
11#[derive(Debug, Default)]
38pub struct EventBuilder<'a> {
39 pub(super) event_type: Option<EventType>,
40 pub(super) start: Option<Cow<'a, str>>,
41 pub(super) end: Option<Cow<'a, str>>,
42 pub(super) style: Option<Cow<'a, str>>,
43 pub(super) name: Option<Cow<'a, str>>,
44 pub(super) text: Option<Cow<'a, str>>,
45 pub(super) layer: Option<Cow<'a, str>>,
46 pub(super) margin_l: Option<Cow<'a, str>>,
47 pub(super) margin_r: Option<Cow<'a, str>>,
48 pub(super) margin_v: Option<Cow<'a, str>>,
49 pub(super) margin_t: Option<Cow<'a, str>>,
50 pub(super) margin_b: Option<Cow<'a, str>>,
51 pub(super) effect: Option<Cow<'a, str>>,
52}
53
54impl<'a> EventBuilder<'a> {
55 pub fn new() -> Self {
57 Self::default()
58 }
59
60 pub fn dialogue() -> Self {
62 Self {
63 event_type: Some(EventType::Dialogue),
64 ..Self::default()
65 }
66 }
67
68 pub fn comment() -> Self {
70 Self {
71 event_type: Some(EventType::Comment),
72 ..Self::default()
73 }
74 }
75
76 pub fn start_time<S: Into<Cow<'a, str>>>(mut self, time: S) -> Self {
78 self.start = Some(time.into());
79 self
80 }
81
82 pub fn end_time<S: Into<Cow<'a, str>>>(mut self, time: S) -> Self {
84 self.end = Some(time.into());
85 self
86 }
87
88 pub fn speaker<S: Into<Cow<'a, str>>>(mut self, name: S) -> Self {
90 self.name = Some(name.into());
91 self
92 }
93
94 pub fn text<S: Into<Cow<'a, str>>>(mut self, text: S) -> Self {
96 self.text = Some(text.into());
97 self
98 }
99
100 pub fn style<S: Into<Cow<'a, str>>>(mut self, style: S) -> Self {
102 self.style = Some(style.into());
103 self
104 }
105
106 pub fn layer(mut self, layer: u32) -> Self {
108 self.layer = Some(Cow::Owned(layer.to_string()));
109 self
110 }
111
112 pub fn margin_left(mut self, margin: u32) -> Self {
114 self.margin_l = Some(Cow::Owned(margin.to_string()));
115 self
116 }
117
118 pub fn margin_right(mut self, margin: u32) -> Self {
120 self.margin_r = Some(Cow::Owned(margin.to_string()));
121 self
122 }
123
124 pub fn margin_vertical(mut self, margin: u32) -> Self {
126 self.margin_v = Some(Cow::Owned(margin.to_string()));
127 self
128 }
129
130 pub fn margin_top(mut self, margin: u32) -> Self {
132 self.margin_t = Some(Cow::Owned(margin.to_string()));
133 self
134 }
135
136 pub fn margin_bottom(mut self, margin: u32) -> Self {
138 self.margin_b = Some(Cow::Owned(margin.to_string()));
139 self
140 }
141
142 pub fn effect<S: Into<Cow<'a, str>>>(mut self, effect: S) -> Self {
144 self.effect = Some(effect.into());
145 self
146 }
147}