fix: Evaluate icon size variants correctly

This commit is contained in:
Josh Megnauth 2024-04-19 23:14:26 -04:00
parent 78d597c56f
commit 900e17bb99
No known key found for this signature in database
GPG key ID: 70813183462EFAD3

View file

@ -36,7 +36,9 @@ use super::wallpaper::widgets::color_image;
const ICON_PREV_N: usize = 6; const ICON_PREV_N: usize = 6;
const ICON_PREV_ROW: usize = 3; const ICON_PREV_ROW: usize = 3;
const ICON_PREV_SIZE: u16 = 32; const ICON_TRY_SIZES: [u16; 3] = [32, 48, 64];
const ICON_THUMB_SIZE: u16 = 32;
const ICON_NAME_TRUNC: usize = 20;
type IconThemes = Vec<String>; type IconThemes = Vec<String>;
type IconHandles = Vec<[icon::Handle; ICON_PREV_N]>; type IconHandles = Vec<[icon::Handle; ICON_PREV_N]>;
@ -1655,12 +1657,18 @@ fn preview_handles(theme: String) -> [icon::Handle; ICON_PREV_N] {
} }
fn icon_handle(icon_name: &str) -> icon::Handle { fn icon_handle(icon_name: &str) -> icon::Handle {
icon::from_name(icon_name) ICON_TRY_SIZES
// Get the path to the icon for the currently set theme. .iter()
// Without the exact path, the handles will all resolve to icons from the same theme in .find_map(|&size| {
// [`icon_theme_button`] rather than the icons for each different theme icon::from_name(icon_name)
.path() // Set the size on the handle to evaluate the correct icon
.map(icon::from_path) .size(size)
// Get the path to the icon for the currently set theme.
// Without the exact path, the handles will all resolve to icons from the same theme in
// [`icon_theme_button`] rather than the icons for each different theme
.path()
.map(icon::from_path)
})
// Fallback icon handle // Fallback icon handle
.unwrap_or_else(|| icon::from_name(icon_name).handle()) .unwrap_or_else(|| icon::from_name(icon_name).handle())
} }
@ -1687,7 +1695,7 @@ fn icon_theme_button(
.take(ICON_PREV_ROW) .take(ICON_PREV_ROW)
.cloned() .cloned()
// TODO: Maybe allow choosable sizes/zooming // TODO: Maybe allow choosable sizes/zooming
.map(|handle| handle.icon().size(ICON_PREV_SIZE)), .map(|handle| handle.icon().size(ICON_THUMB_SIZE)),
) )
.spacing(theme.space_xxs()) .spacing(theme.space_xxs())
.into(), .into(),
@ -1698,7 +1706,7 @@ fn icon_theme_button(
.skip(ICON_PREV_ROW) .skip(ICON_PREV_ROW)
.cloned() .cloned()
// TODO: Maybe allow choosable sizes/zooming // TODO: Maybe allow choosable sizes/zooming
.map(|handle| handle.icon().size(ICON_PREV_SIZE)), .map(|handle| handle.icon().size(ICON_THUMB_SIZE)),
) )
.spacing(theme.space_xxs()) .spacing(theme.space_xxs())
.into(), .into(),
@ -1752,12 +1760,12 @@ fn icon_theme_button(
}), }),
) )
.push( .push(
text(if name.len() > 18 { text(if name.len() > ICON_NAME_TRUNC {
format!("{name:.20}...") format!("{name:.ICON_NAME_TRUNC$}...")
} else { } else {
name.into() name.into()
}) })
.width(Length::Fixed((ICON_PREV_SIZE * 3) as _)), .width(Length::Fixed((ICON_THUMB_SIZE * 3) as _)),
) )
.spacing(theme.space_xs()) .spacing(theme.space_xs())
.into() .into()