freya_devtools_app/components/
attribute.rs1use freya::prelude::*;
2use freya_devtools::AttributeType;
3
4use crate::property::{
5 FillProperty,
6 Property,
7};
8
9pub fn attributes_list(attributes: Vec<(&str, AttributeType)>) -> Element {
10 ScrollView::new()
11 .children(
12 attributes
13 .into_iter()
14 .enumerate()
15 .map(|(i, (name, attribute))| {
16 let background = if i % 2 == 0 {
17 Color::from_af32rgb(0.1, 255, 255, 255)
18 } else {
19 Color::TRANSPARENT
20 };
21 rect()
22 .key(i)
23 .background(background)
24 .padding((5., 16.))
25 .child(attribute_element(name, attribute))
26 .into()
27 }),
28 )
29 .into()
30}
31
32pub fn attribute_element(name: &str, attribute: AttributeType<'_>) -> Element {
33 match attribute {
34 AttributeType::Measure(measure) => Property::new(name, measure.to_string()).into(),
35 AttributeType::Measures(measures) => Property::new(name, measures.pretty()).into(),
36 AttributeType::CornerRadius(radius) => Property::new(name, radius.pretty()).into(),
37 AttributeType::Size(size) => Property::new(name, size.pretty()).into(),
38 AttributeType::VisibleSize(visible_size) => {
39 Property::new(name, visible_size.pretty()).into()
40 }
41 AttributeType::Color(color) => Property::new(name, "").swatch(color, color.pretty()).into(),
42 AttributeType::Fill(fill) => FillProperty::new(name, fill).into(),
43 AttributeType::Border(border) => Property::new(name, border.pretty())
44 .swatch(border.fill, border.fill.pretty())
45 .into(),
46 AttributeType::Text(text) => Property::new(name, text).into(),
47 AttributeType::Direction(direction) => Property::new(name, direction.pretty()).into(),
48 AttributeType::Position(position) => Property::new(name, position.pretty()).into(),
49 AttributeType::Content(content) => Property::new(name, content.pretty()).into(),
50 AttributeType::Alignment(alignment) => Property::new(name, alignment.pretty()).into(),
51 AttributeType::Shadow(shadow) => Property::new(name, shadow.to_string())
52 .swatch(shadow.color, format!("{:?}", shadow.color))
53 .into(),
54 AttributeType::TextShadow(text_shadow) => Property::new(
55 name,
56 format!(
57 "{} {} {}",
58 text_shadow.offset.0, text_shadow.offset.1, text_shadow.blur_sigma
59 ),
60 )
61 .swatch(text_shadow.color, format!("{:?}", text_shadow.color))
62 .into(),
63 AttributeType::TextAlignment(text_align) => Property::new(name, text_align.pretty()).into(),
64 AttributeType::TextOverflow(text_overflow) => {
65 Property::new(name, text_overflow.pretty()).into()
66 }
67 AttributeType::Length(length) => Property::new(name, length.get().to_string()).into(),
68 AttributeType::TextHeightBehavior(text_height) => {
69 Property::new(name, text_height.pretty()).into()
70 }
71 AttributeType::FontSlant(font_slant) => Property::new(name, font_slant.pretty()).into(),
72 AttributeType::TextDecoration(text_decoration) => {
73 Property::new(name, text_decoration.pretty()).into()
74 }
75 }
76}