freya_components/icons/
arrow.rs

1use freya_core::prelude::*;
2use torin::{
3    gaps::Gaps,
4    size::Size,
5};
6
7#[derive(Clone, PartialEq)]
8pub struct ArrowIcon {
9    width: Size,
10    height: Size,
11    margin: Gaps,
12    fill: Color,
13    rotate: Option<f32>,
14}
15
16impl Default for ArrowIcon {
17    fn default() -> Self {
18        Self::new()
19    }
20}
21
22impl ArrowIcon {
23    pub fn new() -> Self {
24        Self {
25            width: Size::px(10.),
26            height: Size::px(10.),
27            margin: Gaps::new_all(0.),
28            fill: Color::BLACK,
29            rotate: None,
30        }
31    }
32
33    pub fn width(mut self, width: impl Into<Size>) -> Self {
34        self.width = width.into();
35        self
36    }
37
38    pub fn height(mut self, height: impl Into<Size>) -> Self {
39        self.height = height.into();
40        self
41    }
42
43    pub fn margin(mut self, margin: impl Into<Gaps>) -> Self {
44        self.margin = margin.into();
45        self
46    }
47
48    pub fn rotate(mut self, rotate: impl Into<f32>) -> Self {
49        self.rotate = Some(rotate.into());
50        self
51    }
52
53    pub fn fill(mut self, fill: impl Into<Color>) -> Self {
54        self.fill = fill.into();
55        self
56    }
57}
58
59impl Render for ArrowIcon {
60    fn render(&self) -> impl IntoElement {
61        svg(Bytes::from_static(r#"
62            <svg viewBox="0 0 18 12" fill="none" xmlns="http://www.w3.org/2000/svg">
63            <path fill-rule="evenodd" clip-rule="evenodd" d="M7.18177 9.58579L0 2.40401L1.81823 0.585785L9 7.76756L16.1818 0.585787L18 2.40402L10.8182 9.58579L10.8185 9.58601L9.00023 11.4042L9 11.404L8.99977 11.4042L7.18154 9.58602L7.18177 9.58579Z" fill="{fill}" stroke="{fill}" stroke-width="2"/>
64            </svg>
65        "#.as_bytes())).rotate(self.rotate).width(self.width.clone()).height(self.height.clone()).margin(self.margin).fill(self.fill)
66    }
67}