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