improv(icon): icon theme set to None by default

This commit is contained in:
Michael Aaron Murphy 2023-01-05 13:21:04 +01:00 committed by Michael Murphy
parent 38f9de4405
commit 043485c68d

View file

@ -9,10 +9,10 @@ use iced::{
widget::{svg, Image}, widget::{svg, Image},
ContentFit, Length, ContentFit, Length,
}; };
use std::{hash::Hash, path::PathBuf};
use std::{ use std::{
borrow::Cow, collections::hash_map::DefaultHasher, ffi::OsStr, hash::Hasher, path::Path, borrow::Cow, collections::hash_map::DefaultHasher, ffi::OsStr, hash::Hasher, path::Path,
}; };
use std::{hash::Hash, path::PathBuf};
#[derive(Debug, Hash)] #[derive(Debug, Hash)]
pub enum IconSource<'a> { pub enum IconSource<'a> {
@ -68,8 +68,8 @@ impl<'a> From<Image> for IconSource<'a> {
pub struct Icon<'a> { pub struct Icon<'a> {
#[setters(skip)] #[setters(skip)]
name: IconSource<'a>, name: IconSource<'a>,
#[setters(into)] #[setters(strip_option, into)]
theme: Cow<'a, str>, theme: Option<Cow<'a, str>>,
style: crate::theme::Svg, style: crate::theme::Svg,
size: u16, size: u16,
#[setters(strip_option)] #[setters(strip_option)]
@ -90,7 +90,7 @@ pub fn icon<'a>(name: impl Into<IconSource<'a>>, size: u16) -> Icon<'a> {
name: name.into(), name: name.into(),
size, size,
style: crate::theme::Svg::default(), style: crate::theme::Svg::default(),
theme: Cow::Borrowed("Pop"), theme: None,
width: None, width: None,
force_svg: false, force_svg: false,
} }
@ -117,11 +117,13 @@ impl<'a> Icon<'a> {
let icon: Option<&Path> = match &self.name { let icon: Option<&Path> = match &self.name {
IconSource::Path(path) => Some(path), IconSource::Path(path) => Some(path),
IconSource::Name(name) => { IconSource::Name(name) => {
let icon = freedesktop_icons::lookup(name) let mut builder = freedesktop_icons::lookup(name).with_size(self.size);
.with_size(self.size)
.with_theme(&self.theme) if let Some(theme) = self.theme.as_deref() {
.with_cache() builder = builder.with_theme(theme);
.find(); }
let icon = builder.with_cache().find();
name_path_buffer = if icon.is_none() { name_path_buffer = if icon.is_none() {
freedesktop_icons::lookup(name) freedesktop_icons::lookup(name)