fix: fallback to Cosmic icon theme
This commit is contained in:
parent
59e5f2ff38
commit
61427b25b0
3 changed files with 29 additions and 22 deletions
|
|
@ -8,7 +8,7 @@ use cosmic::{
|
|||
iced_core::id,
|
||||
theme::ThemeType,
|
||||
widget::{
|
||||
button, color_picker::ColorPickerUpdate, cosmic_container::container, dropdown, icon,
|
||||
button, color_picker::ColorPickerUpdate, dropdown, icon, layer_container as container,
|
||||
segmented_button, segmented_control, settings, spin_button, tab_bar, toggler,
|
||||
ColorPickerModel,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub const COSMIC: &str = "Cosmic";
|
||||
|
||||
thread_local! {
|
||||
/// The fallback icon theme to search if no icon theme was specified.
|
||||
pub(crate) static DEFAULT: RefCell<Cow<'static, str>> = RefCell::new("Cosmic".into());
|
||||
|
|
|
|||
|
|
@ -56,43 +56,48 @@ impl Named {
|
|||
pub fn path(self) -> Option<PathBuf> {
|
||||
let name = &*self.name;
|
||||
let fallback = &self.fallback;
|
||||
let locate = |theme: &str, name| {
|
||||
let mut lookup = freedesktop_icons::lookup(name)
|
||||
.with_theme(theme.as_ref())
|
||||
.with_cache();
|
||||
|
||||
if let Some(scale) = self.scale {
|
||||
lookup = lookup.with_scale(scale);
|
||||
}
|
||||
|
||||
if let Some(size) = self.size {
|
||||
lookup = lookup.with_size(size);
|
||||
}
|
||||
|
||||
if self.prefer_svg {
|
||||
lookup = lookup.force_svg();
|
||||
}
|
||||
lookup.find()
|
||||
};
|
||||
|
||||
crate::icon_theme::DEFAULT.with(|theme| {
|
||||
let theme = theme.borrow();
|
||||
|
||||
let locate = |name| {
|
||||
let mut lookup = freedesktop_icons::lookup(name)
|
||||
.with_theme(theme.as_ref())
|
||||
.with_cache();
|
||||
|
||||
if let Some(scale) = self.scale {
|
||||
lookup = lookup.with_scale(scale);
|
||||
}
|
||||
|
||||
if let Some(size) = self.size {
|
||||
lookup = lookup.with_size(size);
|
||||
}
|
||||
|
||||
if self.prefer_svg {
|
||||
lookup = lookup.force_svg();
|
||||
}
|
||||
|
||||
lookup.find()
|
||||
let themes = if theme.as_ref() == crate::icon_theme::COSMIC {
|
||||
vec![theme.as_ref()]
|
||||
} else {
|
||||
vec![theme.as_ref(), crate::icon_theme::COSMIC]
|
||||
};
|
||||
|
||||
let mut result = locate(name);
|
||||
let mut result = themes.iter().find_map(|t| locate(t, name));
|
||||
|
||||
// On failure, attempt to locate fallback icon.
|
||||
if result.is_none() {
|
||||
if matches!(fallback, Some(IconFallback::Default)) {
|
||||
for new_name in name.rmatch_indices('-').map(|(pos, _)| &name[..pos]) {
|
||||
result = locate(new_name);
|
||||
result = themes.iter().find_map(|t| locate(t, new_name));
|
||||
if result.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if let Some(IconFallback::Names(fallbacks)) = fallback {
|
||||
for fallback in fallbacks {
|
||||
result = locate(fallback);
|
||||
result = themes.iter().find_map(|t| locate(t, fallback));
|
||||
if result.is_some() {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue