freya_devtools_app/components/
attribute.rs1use freya::prelude::*;
2use freya_devtools::AttributeType;
3
4use crate::property::{
5 BorderProperty,
6 ColorProperty,
7 GradientProperty,
8 Property,
9 ShadowProperty,
10 TextShadowProperty,
11};
12
13pub fn attributes_list(attributes: Vec<(&str, AttributeType)>) -> Element {
14 ScrollView::new()
15 .children(
16 attributes
17 .into_iter()
18 .enumerate()
19 .filter_map(|(i, (name, attribute))| {
20 let background = if i % 2 == 0 {
21 Color::from_af32rgb(0.1, 255, 255, 255)
22 } else {
23 Color::TRANSPARENT
24 };
25 let element = attribute_element(name, attribute)?;
26 Some(
27 rect()
28 .key(i)
29 .background(background)
30 .padding((5., 16.))
31 .child(element)
32 .into(),
33 )
34 }),
35 )
36 .into()
37}
38
39pub fn attribute_element(name: &str, attribute: AttributeType<'_>) -> Option<Element> {
40 match attribute {
41 AttributeType::Measure(measure) => Some(Property::new(name, measure.to_string()).into()),
42 AttributeType::OptionalMeasure(measure) => Some(
43 Property::new(
44 name,
45 measure
46 .map(|measure| measure.to_string())
47 .unwrap_or_else(|| "inherit".to_string()),
48 )
49 .into(),
50 ),
51 AttributeType::Measures(measures) => Some(Property::new(name, measures.pretty()).into()),
52 AttributeType::CornerRadius(radius) => Some(Property::new(name, radius.pretty()).into()),
53 AttributeType::Size(size) => Some(Property::new(name, size.pretty()).into()),
54 AttributeType::VisibleSize(visible_size) => {
55 Some(Property::new(name, visible_size.pretty()).into())
56 }
57 AttributeType::Color(color) => Some(ColorProperty::new(name, color).into()),
58 AttributeType::OptionalColor(fill) => {
59 fill.map(|color| ColorProperty::new(name, color).into())
60 }
61 AttributeType::Gradient(fill) => Some(GradientProperty::new(name, fill).into()),
62 AttributeType::Border(border) => Some(BorderProperty::new(name, border.clone()).into()),
63 AttributeType::Text(text) => Some(Property::new(name, text).into()),
64 AttributeType::Direction(direction) => Some(Property::new(name, direction.pretty()).into()),
65 AttributeType::Position(position) => Some(Property::new(name, position.pretty()).into()),
66 AttributeType::Content(content) => Some(Property::new(name, content.pretty()).into()),
67 AttributeType::Alignment(alignment) => Some(Property::new(name, alignment.pretty()).into()),
68 AttributeType::Shadow(shadow) => Some(ShadowProperty::new(name, shadow.clone()).into()),
69 AttributeType::TextShadow(text_shadow) => {
70 Some(TextShadowProperty::new(name, *text_shadow).into())
71 }
72 AttributeType::TextAlignment(text_align) => {
73 Some(Property::new(name, text_align.pretty()).into())
74 }
75 AttributeType::TextOverflow(text_overflow) => {
76 Some(Property::new(name, text_overflow.pretty()).into())
77 }
78 AttributeType::Length(length) => Some(Property::new(name, length.get().to_string()).into()),
79 AttributeType::TextHeightBehavior(text_height) => {
80 Some(Property::new(name, text_height.pretty()).into())
81 }
82 AttributeType::FontSlant(font_slant) => {
83 Some(Property::new(name, font_slant.pretty()).into())
84 }
85 AttributeType::TextDecoration(text_decoration) => {
86 Some(Property::new(name, text_decoration.pretty()).into())
87 }
88 AttributeType::Layer(layer) => Some(Property::new(name, layer.to_string()).into()),
89 AttributeType::CursorMode(cursor_mode) => {
90 Some(Property::new(name, cursor_mode.pretty()).into())
91 }
92 AttributeType::VerticalAlign(vertical_align) => {
93 Some(Property::new(name, vertical_align.pretty()).into())
94 }
95 }
96}