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