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
// Authors: Robert Lopez
use super::Style;
use crate::error::WasmCssError;
impl Style {
/// Extend `Style` with `Style`, re-rendering if `s2` is not empty.
///
/// Returns error if missing access to: `Head`, `Window`, `Document`.
///
/// ---
/// Example Usage:
/// ```
///
/// let mut style1 = named_style!(
/// "my_style",
/// "
/// display: flex;
/// flex-direction: row;
/// "
/// )?;
///
///
/// let style2 = style!(
/// "
/// color: red;
/// flex-direction: column;
/// "
/// )?;
///
/// style1.extend_from_style(&style2)?;
/// ```
pub fn extend_from_style(&mut self, s2: &Style) -> Result<(), WasmCssError> {
if !s2.components.fields.is_empty() || !s2.components.effects.is_empty() {
self.components.fields.extend(s2.components.fields.clone());
'effect_loop: for effect in s2.components.effects.iter() {
for index in 0..self.components.effects.len() {
if effect.key == self.components.effects[index].key {
self.components.effects[index] = effect.to_owned();
continue 'effect_loop;
}
}
self.components.effects.push(effect.to_owned());
}
self.css = self.components.to_css(&self.css_name);
self.render()?;
}
Ok(())
}
}