use super::{IconDir, IconSizeType};
use std::{
borrow::Borrow,
path::{Path, PathBuf},
sync::Arc,
};
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum IconFileType {
PNG,
SVG,
XPM,
}
impl IconFileType {
pub(crate) const fn types() -> &'static [IconFileType; 3] {
const TYPES: [IconFileType; 3] = [IconFileType::PNG, IconFileType::SVG, IconFileType::XPM];
&TYPES
}
}
impl AsRef<str> for IconFileType {
fn as_ref(&self) -> &'static str {
match self {
IconFileType::PNG => "png",
IconFileType::SVG => "svg",
IconFileType::XPM => "xpm",
}
}
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct IconFile {
dir_info: Arc<IconDir>,
path: PathBuf,
icon_type: IconFileType,
}
impl IconFile {
pub fn dir_info(&self) -> &IconDir {
&self.dir_info
}
pub fn path(&self) -> &Path {
&self.path
}
pub const fn icon_type(&self) -> IconFileType {
self.icon_type
}
pub fn size(&self) -> u16 {
self.dir_info.size()
}
pub fn scale(&self) -> u16 {
self.dir_info.scale()
}
pub fn context(&self) -> Option<&str> {
self.dir_info.context()
}
pub fn size_type(&self) -> IconSizeType {
self.dir_info.size_type()
}
pub fn max_size(&self) -> u16 {
self.dir_info.max_size()
}
pub fn min_size(&self) -> u16 {
self.dir_info.min_size()
}
pub fn threshold(&self) -> u16 {
self.dir_info.threshold()
}
pub(crate) const fn new(
dir_info: Arc<IconDir>,
path: PathBuf,
icon_type: IconFileType,
) -> Self {
Self {
dir_info,
path,
icon_type,
}
}
}
impl AsRef<Path> for IconFile {
fn as_ref(&self) -> &Path {
self.path()
}
}
impl Borrow<Path> for IconFile {
fn borrow(&self) -> &Path {
self.path()
}
}