freya_devtools_app/
property.rs1use freya::prelude::*;
2use freya_core::{
3 prelude::Border,
4 style::{
5 color::Color,
6 text_shadow::TextShadow,
7 },
8};
9
10const NAME_COLOR: (u8, u8, u8) = (102, 163, 217);
11const SEPARATOR_COLOR: (u8, u8, u8) = (215, 215, 215);
12const VALUE_COLOR: (u8, u8, u8) = (252, 181, 172);
13
14fn color_swatch(color: Color) -> impl IntoElement {
15 rect()
16 .width(Size::px(17.))
17 .height(Size::px(17.))
18 .corner_radius(CornerRadius::new_all(5.))
19 .background(Color::WHITE)
20 .padding(2.5)
21 .child(
22 rect()
23 .corner_radius(CornerRadius::new_all(3.))
24 .width(Size::fill())
25 .height(Size::fill())
26 .background(color),
27 )
28}
29
30#[derive(Clone, PartialEq)]
31pub struct Property {
32 name: String,
33 value: String,
34}
35
36impl Property {
37 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
38 Self {
39 name: name.into(),
40 value: value.into(),
41 }
42 }
43}
44
45impl Component for Property {
46 fn render(&self) -> impl IntoElement {
47 rect()
48 .overflow(Overflow::Clip)
49 .width(Size::fill())
50 .direction(Direction::Horizontal)
51 .cross_align(Alignment::center())
52 .child(
53 paragraph()
54 .width(Size::fill())
55 .font_size(15.)
56 .span(Span::new(self.name.clone()).color(NAME_COLOR))
57 .span(Span::new(": ").color(SEPARATOR_COLOR))
58 .span(Span::new(self.value.clone()).color(VALUE_COLOR)),
59 )
60 }
61}
62
63#[derive(Clone, PartialEq)]
64pub struct GradientProperty {
65 name: String,
66 fill: Fill,
67}
68
69impl GradientProperty {
70 pub fn new(name: impl Into<String>, fill: Fill) -> Self {
71 Self {
72 name: name.into(),
73 fill,
74 }
75 }
76}
77
78impl Component for GradientProperty {
79 fn render(&self) -> impl IntoElement {
80 paragraph()
81 .line_height(1.9)
82 .font_size(15.)
83 .span(Span::new(self.name.to_string()).color(NAME_COLOR))
84 .span(Span::new(": ").color(SEPARATOR_COLOR))
85 .span(Span::new(format!("{:?}", self.fill)).color(VALUE_COLOR))
86 }
87}
88
89#[derive(Clone, PartialEq)]
90pub struct ColorProperty {
91 name: String,
92 color: Color,
93}
94
95impl ColorProperty {
96 pub fn new(name: impl Into<String>, color: Color) -> Self {
97 Self {
98 name: name.into(),
99 color,
100 }
101 }
102}
103
104impl Component for ColorProperty {
105 fn render(&self) -> impl IntoElement {
106 rect()
107 .overflow(Overflow::Clip)
108 .width(Size::fill())
109 .direction(Direction::Horizontal)
110 .cross_align(Alignment::center())
111 .child(
112 paragraph()
113 .font_size(15.)
114 .span(Span::new(self.name.clone()).color(NAME_COLOR))
115 .span(Span::new(": ").color(SEPARATOR_COLOR)),
116 )
117 .child(rect().width(Size::px(5.)))
118 .child(color_swatch(self.color))
119 .child(rect().width(Size::px(5.)))
120 .child(
121 label()
122 .font_size(15.)
123 .color(Color::from_rgb(VALUE_COLOR.0, VALUE_COLOR.1, VALUE_COLOR.2))
124 .text(self.color.pretty()),
125 )
126 }
127}
128
129#[derive(Clone, PartialEq)]
130pub struct ShadowProperty {
131 name: String,
132 shadow: Shadow,
133}
134
135impl ShadowProperty {
136 pub fn new(name: impl Into<String>, shadow: Shadow) -> Self {
137 Self {
138 name: name.into(),
139 shadow,
140 }
141 }
142}
143
144impl Component for ShadowProperty {
145 fn render(&self) -> impl IntoElement {
146 rect()
147 .overflow(Overflow::Clip)
148 .width(Size::fill())
149 .direction(Direction::Horizontal)
150 .cross_align(Alignment::center())
151 .font_size(15.)
152 .children(vec![
153 paragraph()
154 .span(Span::new(self.name.clone()).color(NAME_COLOR))
155 .span(Span::new(": ").color(SEPARATOR_COLOR))
156 .span(Span::new(self.shadow.to_string()).color(VALUE_COLOR))
157 .into(),
158 rect().width(Size::px(5.)).into(),
159 color_swatch(self.shadow.color).into_element(),
160 rect().width(Size::px(5.)).into(),
161 label()
162 .color(Color::from_rgb(VALUE_COLOR.0, VALUE_COLOR.1, VALUE_COLOR.2))
163 .text(format!("{:?}", self.shadow.color))
164 .into(),
165 ])
166 }
167}
168
169#[derive(Clone, PartialEq)]
170pub struct BorderProperty {
171 name: String,
172 border: Border,
173}
174
175impl BorderProperty {
176 pub fn new(name: impl Into<String>, border: Border) -> Self {
177 Self {
178 name: name.into(),
179 border,
180 }
181 }
182}
183
184impl Component for BorderProperty {
185 fn render(&self) -> impl IntoElement {
186 rect()
187 .overflow(Overflow::Clip)
188 .width(Size::fill())
189 .direction(Direction::Horizontal)
190 .cross_align(Alignment::center())
191 .children(vec![
192 paragraph()
193 .font_size(15.)
194 .span(Span::new(self.name.clone()).color(NAME_COLOR))
195 .span(Span::new(": ").color(SEPARATOR_COLOR))
196 .span(Span::new(self.border.pretty()).color(VALUE_COLOR))
197 .into(),
198 rect().width(Size::px(5.)).into(),
199 color_swatch(self.border.fill).into_element(),
200 rect().width(Size::px(5.)).into(),
201 label()
202 .font_size(15.)
203 .color(Color::from_rgb(VALUE_COLOR.0, VALUE_COLOR.1, VALUE_COLOR.2))
204 .text(self.border.fill.pretty())
205 .into(),
206 ])
207 }
208}
209
210#[derive(Clone, PartialEq)]
211pub struct TextShadowProperty {
212 name: String,
213 text_shadow: TextShadow,
214}
215
216impl TextShadowProperty {
217 pub fn new(name: impl Into<String>, text_shadow: TextShadow) -> Self {
218 Self {
219 name: name.into(),
220 text_shadow,
221 }
222 }
223}
224
225impl Component for TextShadowProperty {
226 fn render(&self) -> impl IntoElement {
227 let color = self.text_shadow.color;
228 let value = format!(
229 "{} {} {}",
230 self.text_shadow.offset.0, self.text_shadow.offset.1, self.text_shadow.blur_sigma
231 );
232
233 rect()
234 .width(Size::fill())
235 .direction(Direction::Horizontal)
236 .cross_align(Alignment::center())
237 .font_size(15.)
238 .children(vec![
239 paragraph()
240 .span(Span::new(self.name.to_string()).color(NAME_COLOR))
241 .span(Span::new(": ").color(SEPARATOR_COLOR))
242 .span(Span::new(value).color(VALUE_COLOR))
243 .into(),
244 rect().width(Size::px(5.)).into(),
245 color_swatch(color).into_element(),
246 rect().width(Size::px(5.)).into(),
247 label()
248 .color(Color::from_rgb(VALUE_COLOR.0, VALUE_COLOR.1, VALUE_COLOR.2))
249 .text(format!("{:?}", color))
250 .into(),
251 ])
252 }
253}