details.rs

 1use std::marker::PhantomData;
 2
 3use crate::prelude::*;
 4use crate::theme;
 5
 6#[derive(Element, Clone)]
 7pub struct Details<S: 'static + Send + Sync + Clone> {
 8    state_type: PhantomData<S>,
 9    text: &'static str,
10    meta: Option<&'static str>,
11}
12
13impl<S: 'static + Send + Sync + Clone> Details<S> {
14    pub fn new(text: &'static str) -> Self {
15        Self {
16            state_type: PhantomData,
17            text,
18            meta: None,
19        }
20    }
21
22    pub fn meta_text(mut self, meta: &'static str) -> Self {
23        self.meta = Some(meta);
24        self
25    }
26
27    fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
28        let theme = theme(cx);
29
30        div()
31            // .flex()
32            // .w_full()
33            .p_1()
34            .gap_0p5()
35            .text_xs()
36            .text_color(theme.lowest.base.default.foreground)
37            .child(self.text)
38            .children(self.meta.map(|m| m))
39    }
40}