Skip to main content

freya_components/icons/
arrow.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 ArrowIcon {
12    layout: LayoutData,
13    fill: Color,
14    rotate: Option<f32>,
15}
16
17impl Default for ArrowIcon {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl LayoutExt for ArrowIcon {
24    fn get_layout(&mut self) -> &mut LayoutData {
25        &mut self.layout
26    }
27}
28
29impl ContainerSizeExt for ArrowIcon {}
30
31impl ArrowIcon {
32    pub fn new() -> Self {
33        Self {
34            layout: Node {
35                width: Size::px(10.),
36                height: Size::px(10.),
37                ..Default::default()
38            }
39            .into(),
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        SvgViewer::new(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"/>
66            </svg>
67        "#.as_bytes()).map(self.rotate, |el, data| el.rotation(data)).width(self.layout.width.clone()).height(self.layout.height.clone()).margin(self.layout.margin).fill(self.fill)
68    }
69}