1use gpui::{IntoElement, Point};
2
3use crate::{
4 prelude::*, traits::component_preview::ComponentPreview, IconDecoration, IconDecorationKind,
5};
6
7#[derive(IntoElement)]
8pub struct DecoratedIcon {
9 icon: Icon,
10 decoration: Option<IconDecoration>,
11}
12
13impl DecoratedIcon {
14 pub fn new(icon: Icon, decoration: Option<IconDecoration>) -> Self {
15 Self { icon, decoration }
16 }
17}
18
19impl RenderOnce for DecoratedIcon {
20 fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
21 div()
22 .relative()
23 .size(self.icon.size)
24 .child(self.icon)
25 .children(self.decoration)
26 }
27}
28
29impl ComponentPreview for DecoratedIcon {
30 fn examples(cx: &mut WindowContext) -> Vec<ComponentExampleGroup<Self>> {
31 let icon_1 = Icon::new(IconName::FileDoc);
32 let icon_2 = Icon::new(IconName::FileDoc);
33 let icon_3 = Icon::new(IconName::FileDoc);
34 let icon_4 = Icon::new(IconName::FileDoc);
35
36 let decoration_x = IconDecoration::new(
37 IconDecorationKind::X,
38 cx.theme().colors().surface_background,
39 cx,
40 )
41 .color(cx.theme().status().error)
42 .position(Point {
43 x: px(-2.),
44 y: px(-2.),
45 });
46
47 let decoration_triangle = IconDecoration::new(
48 IconDecorationKind::Triangle,
49 cx.theme().colors().surface_background,
50 cx,
51 )
52 .color(cx.theme().status().error)
53 .position(Point {
54 x: px(-2.),
55 y: px(-2.),
56 });
57
58 let decoration_dot = IconDecoration::new(
59 IconDecorationKind::Dot,
60 cx.theme().colors().surface_background,
61 cx,
62 )
63 .color(cx.theme().status().error)
64 .position(Point {
65 x: px(-2.),
66 y: px(-2.),
67 });
68
69 let examples = vec![
70 single_example("no_decoration", DecoratedIcon::new(icon_1, None)),
71 single_example(
72 "with_decoration",
73 DecoratedIcon::new(icon_2, Some(decoration_x)),
74 ),
75 single_example(
76 "with_decoration",
77 DecoratedIcon::new(icon_3, Some(decoration_triangle)),
78 ),
79 single_example(
80 "with_decoration",
81 DecoratedIcon::new(icon_4, Some(decoration_dot)),
82 ),
83 ];
84
85 vec![example_group(examples)]
86 }
87}