freya_components/icons/
arrow.rs

1use freya_core::prelude::*;
2use torin::{
3    gaps::Gaps,
4    node::Node,
5    size::Size,
6};
7
8#[derive(Clone, PartialEq)]
9pub struct ArrowIcon {
10    layout: LayoutData,
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 LayoutExt for ArrowIcon {
23    fn get_layout(&mut self) -> &mut LayoutData {
24        &mut self.layout
25    }
26}
27
28impl ContainerSizeExt for ArrowIcon {}
29
30impl ArrowIcon {
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            margin: Gaps::new_all(0.),
40            fill: Color::BLACK,
41            rotate: None,
42        }
43    }
44
45    pub fn margin(mut self, margin: impl Into<Gaps>) -> Self {
46        self.layout.margin = margin.into();
47        self
48    }
49
50    pub fn rotate(mut self, rotate: impl Into<f32>) -> Self {
51        self.rotate = Some(rotate.into());
52        self
53    }
54
55    pub fn fill(mut self, fill: impl Into<Color>) -> Self {
56        self.fill = fill.into();
57        self
58    }
59}
60
61impl Component for ArrowIcon {
62    fn render(&self) -> impl IntoElement {
63        svg(Bytes::from_static(r#"
64            <svg viewBox="0 0 18 12" fill="none" xmlns="http://www.w3.org/2000/svg">
65            <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"/>
66            </svg>
67        "#.as_bytes())).rotate(self.rotate).width(self.layout.width.clone()).height(self.layout.height.clone()).margin(self.margin).fill(self.fill)
68    }
69}