Skip to main content

lgui_core/core/view/declarative/
content.rs

1use super::*;
2
3impl IntoElementContent for Element {
4    fn append_to(self, children: &mut Vec<Element>) {
5        children.push(self);
6    }
7}
8
9impl IntoElementContent for Fragment {
10    fn append_to(self, children: &mut Vec<Element>) {
11        children.extend(self.children);
12    }
13}
14
15impl<T> IntoElementContent for Option<T>
16where
17    T: IntoElementContent,
18{
19    fn append_to(self, children: &mut Vec<Element>) {
20        if let Some(content) = self {
21            content.append_to(children);
22        }
23    }
24}
25
26impl<T> IntoElementContent for Vec<T>
27where
28    T: IntoElementContent,
29{
30    fn append_to(self, children: &mut Vec<Element>) {
31        for content in self {
32            content.append_to(children);
33        }
34    }
35}
36
37impl<T, const N: usize> IntoElementContent for [T; N]
38where
39    T: IntoElementContent,
40{
41    fn append_to(self, children: &mut Vec<Element>) {
42        for content in self {
43            content.append_to(children);
44        }
45    }
46}
47
48impl IntoElementContent for String {
49    fn append_to(self, children: &mut Vec<Element>) {
50        children.push(content_text(self));
51    }
52}
53
54impl IntoElementContent for &'static str {
55    fn append_to(self, children: &mut Vec<Element>) {
56        children.push(content_text(self));
57    }
58}
59
60macro_rules! impl_numeric_content {
61    ($($value:ty),+ $(,)?) => {
62        $(
63            impl IntoElementContent for $value {
64                fn append_to(self, children: &mut Vec<Element>) {
65                    children.push(content_text(self.to_string()));
66                }
67            }
68        )+
69    };
70}
71
72impl_numeric_content!(i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64);
73
74macro_rules! impl_tuple_content {
75    ($($type:ident),+ $(,)?) => {
76        impl<$($type),+> IntoElementContent for ($($type,)+)
77        where
78            $($type: IntoElementContent),+
79        {
80            #[allow(non_snake_case)]
81            fn append_to(self, children: &mut Vec<Element>) {
82                let ($($type,)+) = self;
83                $($type.append_to(children);)+
84            }
85        }
86    };
87}
88
89impl_tuple_content!(A);
90impl_tuple_content!(A, B);
91impl_tuple_content!(A, B, C);
92impl_tuple_content!(A, B, C, D);
93impl_tuple_content!(A, B, C, D, E);
94impl_tuple_content!(A, B, C, D, E, F);
95impl_tuple_content!(A, B, C, D, E, F, G);
96impl_tuple_content!(A, B, C, D, E, F, G, H);