revue/devtools/style/
impls.rs1use super::types::PropertySource;
4use super::types::StyleCategory;
5
6impl PropertySource {
7 pub fn label(&self) -> &'static str {
9 match self {
10 Self::Inline => "inline",
11 Self::Class => "class",
12 Self::Id => "id",
13 Self::Inherited => "inherited",
14 Self::Computed => "computed",
15 Self::Theme => "theme",
16 }
17 }
18
19 pub fn icon(&self) -> &'static str {
21 match self {
22 Self::Inline => "•",
23 Self::Class => ".",
24 Self::Id => "#",
25 Self::Inherited => "↑",
26 Self::Computed => "○",
27 Self::Theme => "◆",
28 }
29 }
30}
31
32impl StyleCategory {
33 pub fn label(&self) -> &'static str {
35 match self {
36 Self::Layout => "Layout",
37 Self::Typography => "Typography",
38 Self::Colors => "Colors",
39 Self::Border => "Border",
40 Self::Effects => "Effects",
41 Self::Other => "Other",
42 }
43 }
44
45 pub fn all() -> &'static [StyleCategory] {
47 &[
48 Self::Layout,
49 Self::Typography,
50 Self::Colors,
51 Self::Border,
52 Self::Effects,
53 Self::Other,
54 ]
55 }
56
57 pub fn from_property(name: &str) -> Self {
59 match name {
60 n if n.starts_with("border") => Self::Border,
62 n if n.starts_with("margin")
63 || n.starts_with("padding")
64 || n.contains("width")
65 || n.contains("height")
66 || n.starts_with("flex")
67 || n.starts_with("grid")
68 || n == "display"
69 || n == "position" =>
70 {
71 Self::Layout
72 }
73 n if n.starts_with("font")
74 || n.starts_with("text")
75 || n == "line-height"
76 || n == "letter-spacing" =>
77 {
78 Self::Typography
79 }
80 n if n.contains("color") || n.contains("background") => Self::Colors,
81 n if n.contains("shadow") || n == "opacity" || n.starts_with("transform") => {
82 Self::Effects
83 }
84 _ => Self::Other,
85 }
86 }
87}