diff --git a/crates/ui-contract/src/primitives/icon.rs b/crates/ui-contract/src/primitives/icon.rs index 758cd0744..36d9a1b18 100644 --- a/crates/ui-contract/src/primitives/icon.rs +++ b/crates/ui-contract/src/primitives/icon.rs @@ -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>> = 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 { diff --git a/crates/ui-contract/src/primitives/mod.rs b/crates/ui-contract/src/primitives/mod.rs index f04bca2fc..d302024b4 100644 --- a/crates/ui-contract/src/primitives/mod.rs +++ b/crates/ui-contract/src/primitives/mod.rs @@ -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, diff --git a/crates/ui-contract/src/style/mod.rs b/crates/ui-contract/src/style/mod.rs index d13c35b33..dc5783d61 100644 --- a/crates/ui-contract/src/style/mod.rs +++ b/crates/ui-contract/src/style/mod.rs @@ -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; diff --git a/crates/ui-contract/src/style/tokens.rs b/crates/ui-contract/src/style/tokens.rs index d4616867f..504731b04 100644 --- a/crates/ui-contract/src/style/tokens.rs +++ b/crates/ui-contract/src/style/tokens.rs @@ -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>> = 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