Skip to main content

freya_components/icons/
tick.rs

1use freya_core::prelude::*;
2use torin::{
3    gaps::Gaps,
4    node::Node,
5    size::Size,
6};
7
8use crate::{
9    get_theme,
10    icons::{
11        IconTheme,
12        IconThemePartial,
13        IconThemePreference,
14    },
15    svg_viewer::SvgViewer,
16};
17
18#[derive(Clone, PartialEq)]
19pub struct TickIcon {
20    layout: LayoutData,
21    pub(crate) theme: Option<IconThemePartial>,
22}
23
24impl LayoutExt for TickIcon {
25    fn layout_mut(&mut self) -> &mut LayoutData {
26        &mut self.layout
27    }
28}
29
30impl ContainerSizeExt for TickIcon {}
31
32impl Default for TickIcon {
33    fn default() -> Self {
34        Self::new()
35    }
36}
37
38impl TickIcon {
39    pub fn new() -> Self {
40        Self {
41            layout: Node {
42                width: Size::px(10.),
43                height: Size::px(10.),
44                ..Default::default()
45            }
46            .into(),
47            theme: None,
48        }
49    }
50
51    pub fn margin(mut self, margin: impl Into<Gaps>) -> Self {
52        self.layout.margin = margin.into();
53        self
54    }
55}
56
57impl Component for TickIcon {
58    fn render(&self) -> impl IntoElement {
59        let IconTheme { fill } = get_theme!(&self.theme, IconThemePreference, "icon");
60        SvgViewer::new(
61            r#"
62            <svg viewBox="0 0 333 263" fill="none" xmlns="http://www.w3.org/2000/svg">
63                <path d="M304.109 0L333 28.8909L99.1812 262.71L70.2903 233.819L304.109 0Z"/>
64                <path d="M0 163.53L27.1003 136.429L126.003 235.332L98.9029 262.433L0 163.53Z"/>
65            </svg>
66        "#
67            .as_bytes(),
68        )
69        .width(self.layout.width.clone())
70        .height(self.layout.height.clone())
71        .margin(self.layout.margin)
72        .fill(fill)
73    }
74}