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
|
use std::collections::HashMap;
use unique_id::{string::StringGenerator, Generator};
use iced::advanced::widget::Id;
use super::ElementName;
#[derive(Debug)]
pub struct RenderedElement {
pub id: Id,
pub child_elements: Vec<RenderedElement>,
pub name: ElementName,
pub props: HashMap<&'static str, &'static str>,
}
impl RenderedElement {
pub fn new(name: ElementName) -> Self {
let gen = StringGenerator::default();
Self {
id: Id::new(gen.next_id()),
child_elements: vec![],
name,
props: HashMap::new(),
}
}
pub fn from_vec(name: ElementName, child_elements: Vec<RenderedElement>) -> Self {
let gen = StringGenerator::default();
Self {
id: Id::new(gen.next_id()),
child_elements,
name,
props: HashMap::new(),
}
}
pub fn push(mut self, element: RenderedElement) -> Self {
self.child_elements.push(element);
self
}
pub fn set_property(&mut self, prop: &'static str, value: &'static str) {
let prop_ref = self.props.entry(prop).or_insert(value);
*prop_ref = value;
}
}
|