Add bundled icons
This commit is contained in:
parent
7b76437224
commit
63ed4691b6
10 changed files with 105 additions and 16 deletions
49
src/icon_cache.rs
Normal file
49
src/icon_cache.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use cosmic::widget::icon;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct IconCacheKey {
|
||||
name: &'static str,
|
||||
size: u16,
|
||||
}
|
||||
|
||||
pub struct IconCache {
|
||||
cache: HashMap<IconCacheKey, icon::Handle>,
|
||||
}
|
||||
|
||||
impl IconCache {
|
||||
pub fn new() -> Self {
|
||||
let mut cache = HashMap::new();
|
||||
|
||||
macro_rules! bundle {
|
||||
($name:expr, $size:expr) => {
|
||||
let data: &'static [u8] = include_bytes!(concat!("../res/icons/", $name, ".svg"));
|
||||
cache.insert(
|
||||
IconCacheKey {
|
||||
name: $name,
|
||||
size: $size,
|
||||
},
|
||||
icon::from_svg_bytes(data).symbolic(true),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
bundle!("folder-open-symbolic", 16);
|
||||
bundle!("go-down-symbolic", 16);
|
||||
bundle!("go-next-symbolic", 16);
|
||||
bundle!("list-add-symbolic", 16);
|
||||
bundle!("object-select-symbolic", 16);
|
||||
bundle!("window-close-symbolic", 16);
|
||||
|
||||
Self { cache }
|
||||
}
|
||||
|
||||
pub fn get(&mut self, name: &'static str, size: u16) -> icon::Icon {
|
||||
let handle = self
|
||||
.cache
|
||||
.entry(IconCacheKey { name, size })
|
||||
.or_insert_with(|| icon::from_name(name).size(size).handle())
|
||||
.clone();
|
||||
icon::icon(handle).size(size)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue