icons: the set a theme names resolves in the style layer that holds it

This commit is contained in:
aiongg committed 2026-11-18 08:34:26 +00:00
1 parent e157a6c330
commit 97ca29aeb9
4 files changed
+24 -23

No files matched your search

+1 -20
View File
@@ -2,7 +2,7 @@
use super::svg_set;
use super::textures::TextureCache;
use crate::style::{DataColor, Ink, StyleColor, UiTokens, ink_color};
use crate::style::{DataColor, Ink, StyleColor, UiTokens, ink_color, log_once};
use craft_behavior::IconId;
use craft_i18n::Direction;
use craft_theme::{IconPackId, Srgba};
@@ -220,15 +220,6 @@ pub(crate) fn paint(painter: &Painter, tokens: &UiTokens, direction: Direction,
}
}
/// Runs `log` the first time `key` is seen: lookups repeat on every repaint and every resolve.
fn log_once(key: String, log: impl FnOnce()) {
static REPORTED: std::sync::Mutex<Option<std::collections::HashSet<String>>> = std::sync::Mutex::new(None);
let mut reported = REPORTED.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
if reported.get_or_insert_with(Default::default).insert(key) {
log();
}
}
impl IconSet {
/// The built-in set a theme's `icon_pack` names: `craft.` and the set's [`id`](IconSet::id), such as
/// `craft.tabler`; `None` for any other id.
@@ -238,16 +229,6 @@ impl IconSet {
}
}
/// The set SVG icons draw from under a theme that names `pack`: the default set when it names none, and, with a log
/// line the first time, when it names one that is not installed.
pub(crate) fn theme_icons(pack: Option<&IconPackId>) -> IconSet {
let Some(pack) = pack else { return IconSet::default() };
IconSet::of_pack(pack).unwrap_or_else(|| {
log_once(format!("pack:{pack}"), || log::warn!("icon pack {pack:?} is not installed; the default icons are drawn"));
IconSet::default()
})
}
/// A catalog or app icon as it is drawn: its entry and set, whether it is mirrored, and its stroke width in points.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct SvgIcon {
+1 -1
View File
@@ -36,8 +36,8 @@ pub use draw::{Dashes, DataStrokeWidth, DataWidth, Draw, PaintShape, StrokeColor
pub use faces::FacesCx;
pub use focus_ring::{FocusKind, FocusRing};
pub use handle::{Handle, HandleShape};
pub(crate) use icon::SvgIcon;
pub use icon::{Glyph, IconSet, IconSource, IconSpec, Mirror, has_icon, icon_names};
pub(crate) use icon::{SvgIcon, theme_icons};
pub use ime_surface::ImeSurface;
pub use kit::{
Checker, CheckerArea, GridAxis, GridInk, GridLines, GridLook, GridStroke, MAX_LINES, Tick, TickEdge, TickRank, dashed, drop_mark, ellipse,
+1
View File
@@ -35,6 +35,7 @@ pub use state::StateSet;
pub use surface::{BandFill, SurfaceEdge, SurfaceStyle};
pub use surround::SurroundLook;
pub use tokens::UiTokens;
pub(crate) use tokens::log_once;
#[doc(hidden)]
pub use cache::resolve_style;
+21 -2
View File
@@ -1,13 +1,32 @@
//! `UiTokens`: the runtime's egui-ready view of one resolved token set.
use crate::fonts::{SEMIBOLD, StackFacts};
use crate::primitives::{IconSet, theme_icons};
use craft_theme::{AppSizes, Appearance, Contrast, GroupValues, Size, ThemeDef, Tokens, TypeRole, resolve_sized};
use crate::primitives::IconSet;
use craft_theme::{AppSizes, Appearance, Contrast, GroupValues, IconPackId, Size, ThemeDef, Tokens, TypeRole, resolve_sized};
use egui::{CornerRadius, FontFamily, FontId};
use std::hash::{Hash, Hasher};
use std::ops::Deref;
use std::sync::Arc;
/// Runs `log` the first time `key` is seen: lookups repeat on every repaint and every resolve.
pub(crate) fn log_once(key: String, log: impl FnOnce()) {
static REPORTED: std::sync::Mutex<Option<std::collections::HashSet<String>>> = std::sync::Mutex::new(None);
let mut reported = REPORTED.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
if reported.get_or_insert_with(Default::default).insert(key) {
log();
}
}
/// The set SVG icons draw from under a theme that names `pack`: the default set when it names none, and, with a log
/// line the first time, when it names one that is not installed.
fn theme_icons(pack: Option<&IconPackId>) -> IconSet {
let Some(pack) = pack else { return IconSet::default() };
IconSet::of_pack(pack).unwrap_or_else(|| {
log_once(format!("pack:{pack}"), || log::warn!("icon pack {pack:?} is not installed; the default icons are drawn"));
IconSet::default()
})
}
/// One resolved token set with the theme's token-group values and a key of their content. Each theme scope
/// (mode, contrast, theme, density, text size) resolves its own; equal sets share a key, so the caches keyed by
/// it hold one entry per distinct set however often a set is rebuilt. The set remembers the contrast and density it