icon_loader/icon/
icon_file.rs1use super::{IconDir, IconSizeType};
2
3use std::{
4 borrow::Borrow,
5 path::{Path, PathBuf},
6 sync::Arc,
7};
8
9#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
11pub enum IconFileType {
12 PNG,
14
15 SVG,
17
18 XPM,
20}
21
22impl IconFileType {
23 pub(crate) const fn types() -> &'static [IconFileType; 3] {
24 const TYPES: [IconFileType; 3] = [IconFileType::PNG, IconFileType::SVG, IconFileType::XPM];
25
26 &TYPES
27 }
28}
29
30impl AsRef<str> for IconFileType {
31 fn as_ref(&self) -> &'static str {
32 match self {
33 IconFileType::PNG => "png",
34 IconFileType::SVG => "svg",
35 IconFileType::XPM => "xpm",
36 }
37 }
38}
39
40#[derive(Clone, Debug, Hash, PartialEq, Eq)]
42pub struct IconFile {
43 dir_info: Arc<IconDir>,
44 path: PathBuf,
45 icon_type: IconFileType,
46}
47
48impl IconFile {
49 pub fn dir_info(&self) -> &IconDir {
51 &self.dir_info
52 }
53
54 pub fn path(&self) -> &Path {
56 &self.path
57 }
58
59 pub const fn icon_type(&self) -> IconFileType {
61 self.icon_type
62 }
63
64 pub fn size(&self) -> u16 {
66 self.dir_info.size()
67 }
68
69 pub fn scale(&self) -> u16 {
71 self.dir_info.scale()
72 }
73
74 pub fn context(&self) -> Option<&str> {
76 self.dir_info.context()
77 }
78
79 pub fn size_type(&self) -> IconSizeType {
81 self.dir_info.size_type()
82 }
83
84 pub fn max_size(&self) -> u16 {
86 self.dir_info.max_size()
87 }
88
89 pub fn min_size(&self) -> u16 {
91 self.dir_info.min_size()
92 }
93
94 pub fn threshold(&self) -> u16 {
96 self.dir_info.threshold()
97 }
98
99 pub(crate) const fn new(
100 dir_info: Arc<IconDir>,
101 path: PathBuf,
102 icon_type: IconFileType,
103 ) -> Self {
104 Self {
105 dir_info,
106 path,
107 icon_type,
108 }
109 }
110}
111
112impl AsRef<Path> for IconFile {
113 fn as_ref(&self) -> &Path {
114 self.path()
115 }
116}
117
118impl Borrow<Path> for IconFile {
119 fn borrow(&self) -> &Path {
120 self.path()
121 }
122}