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 attribute_element(name: &str, attribute: AttributeType<'_>) -> Option<Element> {
14 match attribute {
15 AttributeType::Measure(measure) => Some(Property::new(name, measure.to_string()).into()),
16 AttributeType::OptionalMeasure(measure) => Some(
17 Property::new(
18 name,
19 measure
20 .map(|measure| measure.to_string())
21 .unwrap_or_else(|| "inherit".to_string()),
22 )
23 .into(),
24 ),
25 AttributeType::Measures(measures) => Some(Property::new(name, measures.pretty()).into()),
26 AttributeType::CornerRadius(radius) => Some(Property::new(name, radius.pretty()).into()),
27 AttributeType::Size(size) => Some(Property::new(name, size.pretty()).into()),
28 AttributeType::VisibleSize(visible_size) => {
29 Some(Property::new(name, visible_size.pretty()).into())
30 }
31 AttributeType::Color(color) => Some(ColorProperty::new(name, color).into()),
32 AttributeType::OptionalColor(fill) => {
33 fill.map(|color| ColorProperty::new(name, color).into())
34 }
35 AttributeType::Gradient(fill) => Some(GradientProperty::new(name, fill).into()),
36 AttributeType::Border(border) => Some(BorderProperty::new(name, border.clone()).into()),
37 AttributeType::Text(text) => Some(Property::new(name, text).into()),
38 AttributeType::Direction(direction) => Some(Property::new(name, direction.pretty()).into()),
39 AttributeType::Position(position) => Some(Property::new(name, position.pretty()).into()),
40 AttributeType::Content(content) => Some(Property::new(name, content.pretty()).into()),
41 AttributeType::Alignment(alignment) => Some(Property::new(name, alignment.pretty()).into()),
42 AttributeType::Shadow(shadow) => Some(ShadowProperty::new(name, shadow.clone()).into()),
43 AttributeType::TextShadow(text_shadow) => {
44 Some(TextShadowProperty::new(name, *text_shadow).into())
45 }
46 AttributeType::TextAlignment(text_align) => {
47 Some(Property::new(name, text_align.pretty()).into())
48 }
49 AttributeType::TextOverflow(text_overflow) => {
50 Some(Property::new(name, text_overflow.pretty()).into())
51 }
52 }
53}