freya_components/icons/
arrow.rs1use freya_core::prelude::*;
2use torin::{
3 gaps::Gaps,
4 node::Node,
5 size::Size,
6};
7
8use crate::{
9 get_theme,
10 icons::{
11 IconTheme,
12 IconThemePartial,
13 IconThemePreference,
14 },
15 svg_viewer::SvgViewer,
16};
17
18#[derive(Clone, PartialEq)]
19pub struct ArrowIcon {
20 layout: LayoutData,
21 pub(crate) theme: Option<IconThemePartial>,
22 rotate: Option<f32>,
23}
24
25impl Default for ArrowIcon {
26 fn default() -> Self {
27 Self::new()
28 }
29}
30
31impl LayoutExt for ArrowIcon {
32 fn layout_mut(&mut self) -> &mut LayoutData {
33 &mut self.layout
34 }
35}
36
37impl ContainerSizeExt for ArrowIcon {}
38
39impl ArrowIcon {
40 pub fn new() -> Self {
41 Self {
42 layout: Node {
43 width: Size::px(10.),
44 height: Size::px(10.),
45 ..Default::default()
46 }
47 .into(),
48 theme: None,
49 rotate: None,
50 }
51 }
52
53 pub fn margin(mut self, margin: impl Into<Gaps>) -> Self {
54 self.layout.margin = margin.into();
55 self
56 }
57
58 pub fn rotate(mut self, rotate: f32) -> Self {
59 self.rotate = Some(rotate);
60 self
61 }
62}
63
64impl Component for ArrowIcon {
65 fn render(&self) -> impl IntoElement {
66 let IconTheme { fill } = get_theme!(&self.theme, IconThemePreference, "icon");
67 SvgViewer::new(r#"
68 <svg viewBox="0 0 18 12" fill="none" xmlns="http://www.w3.org/2000/svg">
69 <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"/>
70 </svg>
71 "#.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(fill)
72 }
73}